Skip to content

Commit

Permalink
Build pyodide wheels in CI (#2433)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Mar 6, 2023
1 parent 16979e8 commit fecfc97
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 15 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,38 @@ jobs:
with:
path: './wheelhouse/sourmash*.whl'

build_wasm:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.10.2
- run: |
pip install 'pyodide-build>=0.22.0'
pyodide config get emscripten_version # trigger setup
echo EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version) >> $GITHUB_ENV
- uses: mymindstorm/setup-emsdk@v11
with:
version: ${{ env.EMSCRIPTEN_VERSION }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-emscripten
- run: |
export RUSTC_BOOTSTRAP=1
pyodide build
- uses: actions/upload-artifact@v3
with:
path: './dist/sourmash*.whl'


release:
name: Publish wheels
runs-on: ubuntu-20.04
if: startsWith(github.ref, 'refs/tags/v')
needs: build_wheels
needs: [build_wheels, build_wasm]

steps:
- name: Fetch wheels from artifacts
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/dev_envs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ jobs:
with:
fetch-depth: 0

- uses: cachix/install-nix-action@v19
- uses: cachix/install-nix-action@v20
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v12
with:
name: sourmash-bio
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- run: nix run .# -- --version

- run: nix-shell --command "tox -e py39"
- run: nix-shell --command "tox -e py310"

mamba:
runs-on: ubuntu-latest
Expand Down
130 changes: 125 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,23 @@ harness = false

## Wasm section. Crates only used for WASM, as well as specific configurations

[target.'cfg(all(target_arch = "wasm32", target_vendor="unknown"))'.dependencies.wasm-bindgen]
[target.'cfg(all(target_arch = "wasm32", target_os="unknown"))'.dependencies.wasm-bindgen]
version = "0.2.84"
features = ["serde-serialize"]

[target.'cfg(all(target_arch = "wasm32", target_vendor="unknown"))'.dependencies.web-sys]
[target.'cfg(all(target_arch = "wasm32", target_os="unknown"))'.dependencies.web-sys]
version = "0.3.61"
features = ["console", "File"]

[target.'cfg(all(target_arch = "wasm32", target_vendor="unknown"))'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32"))'.dependencies.chrono]
version = "0.4.23"
features = ["wasmbind"]

[target.'cfg(all(target_arch = "wasm32", target_os="unknown"))'.dev-dependencies]
wasm-bindgen-test = "0.3.34"

### These crates don't compile on wasm
[target.'cfg(not(all(target_arch = "wasm32", target_vendor="unknown")))'.dependencies]
[target.'cfg(not(all(target_arch = "wasm32", target_os="unknown")))'.dependencies]

[package.metadata.maturin]
name = "sourmash._lowlevel"
4 changes: 2 additions & 2 deletions src/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum SourmashError {
#[error(transparent)]
IOError(#[from] std::io::Error),

#[cfg(not(all(target_arch = "wasm32", target_vendor = "unknown")))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
#[error(transparent)]
Panic(#[from] crate::ffi::utils::Panic),
}
Expand Down Expand Up @@ -110,7 +110,7 @@ pub enum SourmashErrorCode {
NifflerError = 100_005,
}

#[cfg(not(all(target_arch = "wasm32", target_vendor = "unknown")))]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
impl SourmashErrorCode {
pub fn from_error(error: &SourmashError) -> SourmashErrorCode {
match error {
Expand Down
3 changes: 2 additions & 1 deletion src/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ use cfg_if::cfg_if;
use murmurhash3::murmurhash3_x64_128;

cfg_if! {
if #[cfg(all(target_arch = "wasm32", target_vendor = "unknown"))] {
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
// Explicitly keeping emscripten and wasi out of this
pub mod wasm;
} else {
pub mod ffi;
Expand Down

0 comments on commit fecfc97

Please sign in to comment.