Skip to content

Commit

Permalink
Merge pull request #11 from YM162/rust_bindings
Browse files Browse the repository at this point in the history
Changed code to Rust and added bindings for Python and JS (via WASM).
  • Loading branch information
YM162 authored Dec 24, 2023
2 parents dd14d6c + 17ee0e1 commit 199a0fc
Show file tree
Hide file tree
Showing 40 changed files with 5,703 additions and 368 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/cargo_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish to crates registry

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
name: Publish to crates registry
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: cargo publish -p gulagcleaner_rs --token ${CARGO_REGISTRY_TOKEN}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
98 changes: 98 additions & 0 deletions .github/workflows/pypi_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Bind from Python/Build wheels and publish to PyPI

on:
release:
types: [published]

jobs:
build:
name: build py3.${{ matrix.python-version }} on ${{ matrix.platform || matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu
- macos
- windows
python-version:
- '7'
- '8'
- '9'
include:
- os: ubuntu
platform: linux
- os: windows
ls: dir

runs-on: ${{ format('{0}-latest', matrix.os) }}
steps:
- uses: actions/checkout@v2

- name: set up python
uses: actions/setup-python@v1
with:
python-version: '3.8'

- name: set up rust
if: matrix.os != 'ubuntu'
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: install python dependencies
run: pip install -U setuptools wheel twine cibuildwheel build

- name: build sdist
working-directory: gulagcleaner_python
if: matrix.os == 'ubuntu' && matrix.python-version == '8'
run: |
pip install -U setuptools-rust
python -m build . --sdist
- name: build ${{ matrix.platform || matrix.os }} binaries
run: cibuildwheel gulagcleaner_python --output-dir dist
env:
CIBW_BUILD: 'cp3${{ matrix.python-version }}-*'
CIBW_SKIP: '*-win32 *-musllinux_i686'
CIBW_PLATFORM: ${{ matrix.platform || matrix.os }}
CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$PATH"'
CIBW_ENVIRONMENT_WINDOWS: 'PATH="$UserProfile\.cargo\bin;$PATH"'
CIBW_MANYLINUX_X86_64_IMAGE: 'manylinux2014'
CIBW_MANYLINUX_I686_IMAGE: 'manylinux2014'
CIBW_BEFORE_BUILD: >
pip install -U setuptools-rust &&
rustup default nightly &&
rustup show
CIBW_BEFORE_BUILD_LINUX: >
pip install -U setuptools-rust &&
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly --profile=minimal -y &&
rustup show
- name: build windows 32bit binaries
if: matrix.os == 'windows'
run: cibuildwheel gulagcleaner_python --output-dir dist
env:
CIBW_BUILD: 'cp3${{ matrix.python-version }}-win32'
CIBW_PLATFORM: windows
CIBW_ENVIRONMENT: 'PATH="$UserProfile\.cargo\bin;$PATH"'
CIBW_BEFORE_BUILD: >
pip install -U setuptools-rust &&
rustup toolchain install nightly-i686-pc-windows-msvc &&
rustup default nightly-i686-pc-windows-msvc &&
rustup override set nightly-i686-pc-windows-msvc &&
rustup show
- name: list dist files
run: ${{ matrix.ls || 'ls -lh' }} dist/

- name: twine check
run: twine check dist/*

- name: upload to pypi
if: startsWith(github.ref, 'refs/tags/')
run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.pypi_token }}
35 changes: 35 additions & 0 deletions .github/workflows/wasm_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build as WASM and publish in npm

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
name: Build and publish to npm
steps:
- name: git-checkout
uses: actions/checkout@v4

- name: install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: build wasm
run: wasm-pack build gulagcleaner_wasm --target web --release -d WASM_build

- name: setup node
uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

- name: run install
working-directory: ./gulagcleaner_wasm/WASM_build
run: npm install

- name: publish to npm
working-directory: ./gulagcleaner_wasm/WASM_build
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ dist
multiplepdf
tests.ipynb
gulagcleaner.egg-info
gulagcleaner/__pycache__
gulagcleaner/__pycache__
target
useful_info+scripts+TODO.md
.env
.venv
python/gulagcleaner/__pycache__
*.pyd
Loading

0 comments on commit 199a0fc

Please sign in to comment.