Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,37 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
targets: wasm32-unknown-unknown
Copy link
Collaborator

@ajakubowicz-canva ajakubowicz-canva Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, thank you for the awesome PR! This comment can be treated as non-blocking – but I am just curious and honestly lacking knowledge of other wasm32 targets.

We (Canva) currently use the vello_hybrid / vello_cpu renderers via wasm32-unknown-unknown using wasm-bindgen directly. From that perspective I'd be concerned that we lose that test coverage.

Is there a solution for migrating from wasm32-unknown-unknown to wasm32-wasip1 for Rust on the browser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so at the moment; there's wasm-bindgen/wasm-bindgen#3421 but it's kinda dead (as is wasm-bindgen in general, unfortunately).

The Vello tests will still run on wasm32-unknown-unknown, so test coverage should be maintained through those. I'm also not removing wasm32-unknown-unknown support from this library; this is just a matter of making the tests easier to run and extend.

It might be worth adding a CI check that wasm32-unknown-unknown still builds, but I seriously doubt there'll be any functional differences between wasm32-wasip1 and wasm32-unknown-unknown. For example, there are a lot of JavaScript packages on NPM that run all their unit tests on Node, but that doesn't mean those packages don't work in the browser.

Copy link
Collaborator

@ajakubowicz-canva ajakubowicz-canva Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me! Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an additional step to the "cargo test (wasm32)" workflow that runs cargo build --target wasm32-unknown-unknown. This should ensure that target still builds.

targets: wasm32-unknown-unknown,wasm32-wasip1

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

- name: install wasm-pack
- name: install cargo-nextest and wasmtime
uses: taiki-e/install-action@v2
with:
tool: wasm-pack
tool: cargo-nextest,wasmtime-cli

# We test using wasm32-wasip1, but want to make sure that wasm32-unknown-unknown still builds
- name: cargo build (wasm32-unknown-unknown)
run: |
cargo build --target wasm32-unknown-unknown \
--config 'target.wasm32-unknown-unknown.rustflags = "-Ctarget-feature=+simd128"'

- name: cargo nextest
run: |
cargo nextest run --workspace --locked --all-features --no-fail-fast --target wasm32-wasip1 \
--config 'target.wasm32-wasip1.rustflags = "-Ctarget-feature=+simd128"' \
--config 'target.wasm32-wasip1.runner = "wasmtime"'

- name: cargo test --doc
run: |
cargo test --doc --workspace --locked --all-features --no-fail-fast --target wasm32-wasip1 \
--config 'target.wasm32-wasip1.rustflags = "-Ctarget-feature=+simd128"' \
--config 'target.wasm32-wasip1.rustdocflags = "-Ctarget-feature=+simd128"' \
--config 'target.wasm32-wasip1.runner = "wasmtime"'

- name: Run fearless_simd_tests on Chrome
run: RUSTFLAGS=-Ctarget-feature=+simd128 wasm-pack test --headless --chrome
working-directory: fearless_simd_tests


check-msrv:
name: cargo check (msrv)
Expand Down
200 changes: 0 additions & 200 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion fearless_simd/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
///
/// # Example
///
/// ```
/// ```rust
/// use fearless_simd::{Level, Simd, dispatch};
///
/// #[inline(always)]
Expand Down
5 changes: 2 additions & 3 deletions fearless_simd_dev_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
let include_avx2 = false;
// Note that we cannot feature-gate this with `target_arch`. If we run
// `wasm-pack test --headless --chrome`, then the `target_arch` will still be set to
// `cargo test --target wasm32-wasip1`, then the `target_arch` will still be set to
// the operating system you are running on. Because of this, we instead add the `target_arch`
// feature gate to the actual test.
let include_wasm = !exclude_wasm(&input_fn_name.to_string());
Comment on lines 43 to 47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth checking whether we can use CARGO_CFG_TARGET_ARCH (ideally for all of these tests, because in theory we could be cross-compiling to run through miri or qemu).

This should be a follow-up/an issue though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't; it's not exposed at the time proc macros are run.


let fallback_snippet = if include_fallback {
quote! {
#[test]
#[cfg_attr(all(target_arch = "wasm32", target_feature = "simd128"), wasm_bindgen_test::wasm_bindgen_test)]
fn #fallback_name() {
let fallback = fearless_simd::Fallback::new();
#input_fn_name(fallback);
Expand Down Expand Up @@ -101,7 +100,7 @@ pub fn simd_test(_: TokenStream, item: TokenStream) -> TokenStream {
let wasm_snippet = if include_wasm {
quote! {
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
#[wasm_bindgen_test::wasm_bindgen_test]
#[test]
fn #wasm_name() {
let wasm = unsafe { fearless_simd::wasm32::WasmSimd128::new_unchecked() };
#input_fn_name(wasm);
Expand Down
4 changes: 0 additions & 4 deletions fearless_simd_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ workspace = true
[dependencies]
fearless_simd = { workspace = true, features = ["std"] }
fearless_simd_dev_macros = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.50"
wasm-bindgen = "0.2.100"
20 changes: 16 additions & 4 deletions fearless_simd_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ This is a development-only crate for testing `fearless_simd`.

### Testing WebAssembly +simd128

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

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

Currently these tests only enforce that WASM SIMD and the fallback scalar implementations match when
run in the browser.
Or [wasmi](https://github.com/wasmi-labs/wasmi):

```sh
cargo install --locked --features simd wasmi_cli
```

Run WebAssembly tests with:

```sh
cargo test --target wasm32-wasip1 \
--config 'target.wasm32-wasip1.rustflags = "-Ctarget-feature=+simd128"' \
--config 'target.wasm32-wasip1.rustdocflags = "-Ctarget-feature=+simd128"' \
--config 'target.wasm32-wasip1.runner = "wasmtime"' # or "wasmi_cli" if you installed that
```
3 changes: 0 additions & 3 deletions fearless_simd_tests/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use fearless_simd::*;
use fearless_simd_dev_macros::simd_test;

#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

mod harness;

#[simd_test]
Expand Down