Skip to content

Commit 76ddd59

Browse files
authored
Build WebAssembly tests for the wasm32-wasip1 target and run them using wasmtime (#122)
[WASI](https://wasi.dev/) is now mature enough that we can build binaries that target WebAssembly, and they will "just work" if run in a WebAssembly runtime. This means we can get rid of the [increasingly-unmaintained](https://blog.rust-lang.org/inside-rust/2025/07/21/sunsetting-the-rustwasm-github-org/) `wasm-pack` and `wasm-bindgen` machinery, and run tests the same way we do for any other target, including doctests. We *could* add a `.cargo/config.toml` to this repository that specifies the rustflags and runner, but that would affect every package and cargo command. Not sure if that's desirable. Note that some of the doctests for `wasm32-wasip1` fail to compile, probably due to #105: <details> <summary>Error messages</summary> ``` ---- fearless_simd/src/macros.rs - macros::dispatch (line 34) stdout ---- error[E0599]: no variant or associated item named `Fallback` found for enum `Level` in the current scope --> fearless_simd/src/macros.rs:43:1 | 12 | dispatch!(level, simd => sigmoid(simd, &[/*...*/], &mut [/*...*/])); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variant or associated item not found in `Level` | = note: this error originates in the macro `$crate::dispatch` which comes from the expansion of the macro `dispatch` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0599`. Couldn't compile the test. ---- fearless_simd/src/lib.rs - (line 23) stdout ---- error[E0599]: no variant or associated item named `Fallback` found for enum `Level` in the current scope --> fearless_simd/src/lib.rs:33:1 | 13 | dispatch!(level, simd => sigmoid(simd, &[/*...*/], &mut [/*...*/])); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variant or associated item not found in `Level` | = note: this error originates in the macro `$crate::dispatch` which comes from the expansion of the macro `dispatch` (in Nightly builds, run with -Z macro-backtrace for more info) ``` </details> I've `ignore`d those doctests for now.
1 parent 9039b44 commit 76ddd59

File tree

7 files changed

+41
-222
lines changed

7 files changed

+41
-222
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,37 @@ jobs:
241241
uses: dtolnay/rust-toolchain@master
242242
with:
243243
toolchain: ${{ env.RUST_STABLE_VER }}
244-
targets: wasm32-unknown-unknown
244+
targets: wasm32-unknown-unknown,wasm32-wasip1
245245

246246
- name: restore cache
247247
uses: Swatinem/rust-cache@v2
248248
with:
249249
save-if: ${{ github.event_name != 'merge_group' }}
250250

251-
- name: install wasm-pack
251+
- name: install cargo-nextest and wasmtime
252252
uses: taiki-e/install-action@v2
253253
with:
254-
tool: wasm-pack
254+
tool: cargo-nextest,wasmtime-cli
255+
256+
# We test using wasm32-wasip1, but want to make sure that wasm32-unknown-unknown still builds
257+
- name: cargo build (wasm32-unknown-unknown)
258+
run: |
259+
cargo build --target wasm32-unknown-unknown \
260+
--config 'target.wasm32-unknown-unknown.rustflags = "-Ctarget-feature=+simd128"'
261+
262+
- name: cargo nextest
263+
run: |
264+
cargo nextest run --workspace --locked --all-features --no-fail-fast --target wasm32-wasip1 \
265+
--config 'target.wasm32-wasip1.rustflags = "-Ctarget-feature=+simd128"' \
266+
--config 'target.wasm32-wasip1.runner = "wasmtime"'
267+
268+
- name: cargo test --doc
269+
run: |
270+
cargo test --doc --workspace --locked --all-features --no-fail-fast --target wasm32-wasip1 \
271+
--config 'target.wasm32-wasip1.rustflags = "-Ctarget-feature=+simd128"' \
272+
--config 'target.wasm32-wasip1.rustdocflags = "-Ctarget-feature=+simd128"' \
273+
--config 'target.wasm32-wasip1.runner = "wasmtime"'
255274
256-
- name: Run fearless_simd_tests on Chrome
257-
run: RUSTFLAGS=-Ctarget-feature=+simd128 wasm-pack test --headless --chrome
258-
working-directory: fearless_simd_tests
259-
260275
261276
check-msrv:
262277
name: cargo check (msrv)

Cargo.lock

Lines changed: 0 additions & 200 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fearless_simd/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
///
3232
/// # Example
3333
///
34-
/// ```
34+
/// ```rust
3535
/// use fearless_simd::{Level, Simd, dispatch};
3636
///
3737
/// #[inline(always)]

fearless_simd_dev_macros/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
4141
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
4242
let include_avx2 = false;
4343
// Note that we cannot feature-gate this with `target_arch`. If we run
44-
// `wasm-pack test --headless --chrome`, then the `target_arch` will still be set to
44+
// `cargo test --target wasm32-wasip1`, then the `target_arch` will still be set to
4545
// the operating system you are running on. Because of this, we instead add the `target_arch`
4646
// feature gate to the actual test.
4747
let include_wasm = !exclude_wasm(&input_fn_name.to_string());
4848

4949
let fallback_snippet = if include_fallback {
5050
quote! {
5151
#[test]
52-
#[cfg_attr(all(target_arch = "wasm32", target_feature = "simd128"), wasm_bindgen_test::wasm_bindgen_test)]
5352
fn #fallback_name() {
5453
let fallback = fearless_simd::Fallback::new();
5554
#input_fn_name(fallback);
@@ -101,7 +100,7 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
101100
let wasm_snippet = if include_wasm {
102101
quote! {
103102
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
104-
#[wasm_bindgen_test::wasm_bindgen_test]
103+
#[test]
105104
fn #wasm_name() {
106105
let wasm = unsafe { fearless_simd::wasm32::WasmSimd128::new_unchecked() };
107106
#input_fn_name(wasm);

fearless_simd_tests/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,3 @@ workspace = true
2020
[dependencies]
2121
fearless_simd = { workspace = true, features = ["std"] }
2222
fearless_simd_dev_macros = { workspace = true }
23-
24-
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
25-
wasm-bindgen-test = "0.3.50"
26-
wasm-bindgen = "0.2.100"

fearless_simd_tests/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@ This is a development-only crate for testing `fearless_simd`.
99

1010
### Testing WebAssembly +simd128
1111

12-
Run browser tests with:
12+
To run the WebAssembly tests, first install a WebAssembly runtime such as [wasmtime](https://docs.wasmtime.dev/introduction.html):
1313

1414
```sh
15-
RUSTFLAGS=-Ctarget-feature=+simd128 wasm-pack test --headless --chrome
15+
cargo install --locked wasmtime-cli
1616
```
1717

18-
Currently these tests only enforce that WASM SIMD and the fallback scalar implementations match when
19-
run in the browser.
18+
Or [wasmi](https://github.com/wasmi-labs/wasmi):
19+
20+
```sh
21+
cargo install --locked --features simd wasmi_cli
22+
```
23+
24+
Run WebAssembly tests with:
25+
26+
```sh
27+
cargo test --target wasm32-wasip1 \
28+
--config 'target.wasm32-wasip1.rustflags = "-Ctarget-feature=+simd128"' \
29+
--config 'target.wasm32-wasip1.rustdocflags = "-Ctarget-feature=+simd128"' \
30+
--config 'target.wasm32-wasip1.runner = "wasmtime"' # or "wasmi_cli" if you installed that
31+
```

fearless_simd_tests/tests/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
use fearless_simd::*;
1111
use fearless_simd_dev_macros::simd_test;
1212

13-
#[cfg(target_arch = "wasm32")]
14-
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
15-
1613
mod harness;
1714

1815
#[simd_test]

0 commit comments

Comments
 (0)