From 47bac77e522eaebaf01a70059ea1d7f69612846e Mon Sep 17 00:00:00 2001 From: Shahar Papini <43779613+spapinistarkware@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:09:42 +0300 Subject: [PATCH] Test wasm32-unknown-unknown target (#791) --- .github/workflows/ci.yaml | 16 ++++ Cargo.lock | 90 +++++++++++++++++++--- crates/prover/Cargo.toml | 3 + crates/prover/src/examples/poseidon/mod.rs | 13 ++++ 4 files changed, 110 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 91b62c1a7..4a5ad0e7b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -67,6 +67,22 @@ jobs: CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --" RUSTFLAGS: -C target-feature=+simd128 + run-wasm32-unknown-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly-2024-01-04 + targets: wasm32-unknown-unknown + - uses: Swatinem/rust-cache@v2 + - uses: jetli/wasm-pack-action@v0.4.0 + with: + version: 'latest' + - run: cd crates/prover && wasm-pack test --node + env: + RUSTFLAGS: -C target-feature=+simd128 + run-neon-tests: runs-on: macos-latest-xlarge steps: diff --git a/Cargo.lock b/Cargo.lock index 92ae452f9..c14183025 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -262,6 +262,16 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "constant_time_eq" version = "0.3.0" @@ -541,9 +551,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -581,6 +591,16 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "minicov" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c71e683cd655513b99affab7d317deb690528255a0d5f717f1024093c12b169" +dependencies = [ + "cc", + "walkdir", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -825,6 +845,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "semver" version = "1.0.23" @@ -972,6 +998,7 @@ dependencies = [ "thiserror", "tracing", "tracing-subscriber", + "wasm-bindgen-test", ] [[package]] @@ -1167,19 +1194,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -1190,11 +1218,23 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1202,9 +1242,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -1215,9 +1255,35 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "wasm-bindgen-test" +version = "0.3.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68497a05fb21143a08a7d24fc81763384a3072ee43c44e86aad1744d6adef9d9" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "minicov", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] [[package]] name = "web-sys" diff --git a/crates/prover/Cargo.toml b/crates/prover/Cargo.toml index 0be92c9a0..4a02c5c7e 100644 --- a/crates/prover/Cargo.toml +++ b/crates/prover/Cargo.toml @@ -30,6 +30,8 @@ serde = { version = "1.0", features = ["derive"] } aligned = "0.4.2" test-log = { version = "0.2.15", features = ["trace"] } tracing-subscriber = "0.3.18" +[target.'cfg(all(target_family = "wasm", not(target_os = "wasi")))'.dev-dependencies] +wasm-bindgen-test = "0.3.43" [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.criterion] features = ["html_reports"] @@ -44,6 +46,7 @@ version = "0.5.1" [lib] bench = false +crate-type = ["cdylib", "lib"] [lints.rust] warnings = "deny" diff --git a/crates/prover/src/examples/poseidon/mod.rs b/crates/prover/src/examples/poseidon/mod.rs index 052c6a9e7..63af1d03f 100644 --- a/crates/prover/src/examples/poseidon/mod.rs +++ b/crates/prover/src/examples/poseidon/mod.rs @@ -404,6 +404,19 @@ mod tests { }; use crate::math::matrix::{RowMajorMatrix, SquareMatrix}; + #[cfg(all(target_family = "wasm", not(target_os = "wasi")))] + #[wasm_bindgen_test::wasm_bindgen_test] + fn test_poseidon_prove_wasm() { + const LOG_N_INSTANCES: u32 = 10; + let config = PcsConfig { + pow_bits: 10, + fri_config: FriConfig::new(5, 1, 64), + }; + + // Prove. + prove_poseidon(LOG_N_INSTANCES, config); + } + #[test] fn test_apply_m4() { let m4 = RowMajorMatrix::::new(