-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable WASM-compat and monitor it in the CI (#142)
* fix: Use `target_pointer_size` conditional compilation There are some parts of the code where is needed to de/serialze `usize`s. These, have sizes that vary depending on the target achitecture the code is compiled for. Hence, this adapts the de/serialization to the specific pointer size for which the crate is being compiled to. * change: Support WASM-compatibility and polish Cargo.toml In order to support Wasm-compat and to simplify and improve `Cargo.toml` readability, the follwing changes have been made: - All the deps that can use `parallel` feature, do so. As `rayon` supports non-threaded targets with a fallback option. See: https://docs.rs/rayon-core/1.12.1/rayon_core/index.html#global-fallback-when-threading-is-unsupported - `ark-grumpking` has been brought to `0.5.0-alpha.0` as `0.4.0` appears to not be in `crates.io` anymore. See: https://crates.io/crates/ark-grumpkin/versions - By default, the crate uses `"ark-circom/default"` which selects the `wasmer/sys` feature such that it knows where wasmer is suposed to be run`. - Added a `wasm` feature which forces `ark-circom/wasm` to be used instead. Which internally selects the `wasmer/js` backend to be used such that in-browser execution is possible. - Added `getrandom` with `js` feature as dependency when `wasm32-unknown-unknown` target is selected such that compilation of the crate for testing or simply building is possible. Notice that with `wasi` and other wasm targets, this is not the case as they're automatically supported. For more info, please check: https://docs.rs/getrandom/latest/getrandom/#webassembly-support * feat: Support WASM-compatibility tests in CI Add support for both testing the build of `sonobe/folding-schemes` for WASM-targets and also, it's build as a dependency for a WASM-crate. This includes a build job for the three main supported rust-WASM targets and the same but for a thrid crate creted on-the-fly which uses `sonobe/folding-schemes` as a dependency. * chore: Add README docs about WASM-compat & feats * ci: don't run WASM-compat job if PR is draft * chore: depend on `arnaucube/circom-compat` fork. Since arnaucube/circom-compat#2 was merged, we can already switch to it as we were depending before. * chore: minimal build/test instructions * fix: CI typos * fix: Update CI to use correct feature sets * fix: `ark-grumpkin` versioning issues As mentioned in #146 there's a big issue that involves some dependencies of the crate. As a temporary fix, this forces the workspace to rely on a "non-existing" version of `ark-grumpkin` which is immediately patched at workspace-level for a custom version that @arnaucube owns with some cherry-picked commits. While this allows the CI to pass and crate to build, a better solution is needed. * fix: Clippy CI avoiding --all-targets * fix: use `wasm` feat only with folding-schemes
- Loading branch information
Showing
7 changed files
with
181 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
|
||
GIT_ROOT=$(pwd) | ||
|
||
cd /tmp | ||
|
||
# create test project | ||
cargo new foobar | ||
cd foobar | ||
|
||
# set rust-toolchain same as "sonobe" | ||
cp "${GIT_ROOT}/rust-toolchain" . | ||
|
||
# add wasm32-* targets | ||
rustup target add wasm32-unknown-unknown wasm32-wasi | ||
|
||
# add dependencies | ||
cargo add --path "${GIT_ROOT}/folding-schemes" --features wasm, parallel | ||
cargo add getrandom --features js --target wasm32-unknown-unknown | ||
|
||
# test build for wasm32-* targets | ||
cargo build --release --target wasm32-unknown-unknown | ||
cargo build --release --target wasm32-wasi | ||
# Emscripten would require to fetch the `emcc` tooling. Hence we don't build the lib as a dep for it. | ||
# cargo build --release --target wasm32-unknown-emscripten | ||
|
||
# delete test project | ||
cd ../ | ||
rm -rf foobar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ env: | |
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
|
||
jobs: | ||
test: | ||
|
@@ -41,17 +40,16 @@ jobs: | |
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
feature_set: [basic] | ||
include: | ||
- feature: default | ||
- feature_set: basic | ||
features: --features default,light-test | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
- uses: noir-lang/[email protected] | ||
with: | ||
toolchain: nightly | ||
- uses: actions-rs/toolchain@v1 | ||
# use the more efficient nextest | ||
- uses: taiki-e/install-action@nextest | ||
- uses: Swatinem/rust-cache@v2 | ||
toolchain: nightly | ||
- name: Download Circom | ||
run: | | ||
mkdir -p $HOME/bin | ||
|
@@ -66,16 +64,47 @@ jobs: | |
run: ./folding-schemes/src/frontend/circom/test_folder/compile.sh | ||
- name: Execute compile.sh to generate .json from noir | ||
run: ./folding-schemes/src/frontend/noir/test_folder/compile.sh | ||
- name: Build | ||
# This build will be reused by nextest, | ||
# and also checks (--all-targets) that benches don't bit-rot | ||
run: cargo build --release --all-targets --no-default-features --features "light-test,${{ matrix.feature }}" | ||
- name: Test | ||
run: | | ||
cargo nextest run --profile ci --release --workspace --no-default-features --features "light-test,${{ matrix.feature }}" | ||
- name: Doctests # nextest does not support doc tests | ||
- name: Run tests | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --release --workspace --no-default-features ${{ matrix.features }} | ||
- name: Run Doc-tests | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --doc | ||
|
||
build: | ||
if: github.event.pull_request.draft == false | ||
name: Build target ${{ matrix.target }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
target: | ||
- wasm32-unknown-unknown | ||
- wasm32-wasi | ||
# Ignoring until clear usage is required | ||
# - wasm32-unknown-emscripten | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
override: false | ||
default: true | ||
- name: Add target | ||
run: rustup target add ${{ matrix.target }} | ||
- name: Wasm-compat build | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: build | ||
args: -p folding-schemes --no-default-features --target ${{ matrix.target }} --features "wasm, parallel" | ||
- name: Run wasm-compat script | ||
run: | | ||
cargo test --doc | ||
chmod +x .github/scripts/wasm-target-test-build.sh | ||
.github/scripts/wasm-target-test-build.sh | ||
shell: bash | ||
|
||
examples: | ||
if: github.event.pull_request.draft == false | ||
|
@@ -86,7 +115,7 @@ jobs: | |
- uses: actions-rs/toolchain@v1 | ||
- uses: noir-lang/[email protected] | ||
with: | ||
toolchain: nightly | ||
toolchain: nightly | ||
- name: Download Circom | ||
run: | | ||
mkdir -p $HOME/bin | ||
|
@@ -98,9 +127,9 @@ jobs: | |
curl -sSfL https://github.com/ethereum/solidity/releases/download/v0.8.4/solc-static-linux -o /usr/local/bin/solc | ||
chmod +x /usr/local/bin/solc | ||
- name: Execute compile.sh to generate .r1cs and .wasm from .circom | ||
run: ./folding-schemes/src/frontend/circom/test_folder/compile.sh | ||
run: ./folding-schemes/src/frontend/circom/test_folder/compile.sh | ||
- name: Execute compile.sh to generate .json from noir | ||
run: ./folding-schemes/src/frontend/noir/test_folder/compile.sh | ||
run: ./folding-schemes/src/frontend/noir/test_folder/compile.sh | ||
- name: Run examples tests | ||
run: cargo test --examples | ||
- name: Run examples | ||
|
@@ -119,31 +148,42 @@ jobs: | |
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: --all -- --check | ||
args: --all --check | ||
|
||
clippy: | ||
if: github.event.pull_request.draft == false | ||
name: Clippy lint checks | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
feature_set: [basic, wasm] | ||
include: | ||
- feature_set: basic | ||
features: --features default,light-test | ||
# We only want to test `folding-schemes` package with `wasm` feature. | ||
- feature_set: wasm | ||
features: -p folding-schemes --features wasm,parallel --target wasm32-unknown-unknown | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
components: clippy | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Add target | ||
run: rustup target add wasm32-unknown-unknown | ||
- name: Run clippy | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: clippy | ||
args: --all-targets --all-features -- -D warnings | ||
args: --no-default-features ${{ matrix.features }} -- -D warnings | ||
|
||
typos: | ||
if: github.event.pull_request.draft == false | ||
name: Spell Check with Typos | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use typos with config file | ||
uses: crate-ci/typos@master | ||
with: | ||
config: .github/workflows/typos.toml | ||
- uses: actions/checkout@v4 | ||
- name: Use typos with config file | ||
uses: crate-ci/typos@master | ||
with: | ||
config: .github/workflows/typos.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters