Skip to content

refactor: use wasm-runner#397

Open
sinui0 wants to merge 1 commit into
devfrom
refactor/wasm-harness
Open

refactor: use wasm-runner#397
sinui0 wants to merge 1 commit into
devfrom
refactor/wasm-harness

Conversation

@sinui0
Copy link
Copy Markdown
Collaborator

@sinui0 sinui0 commented May 13, 2026

Switch wasm test/bench runner to wasm-harness

Summary

Replaces the wasmtime --wasi threads runner with wasm-harness, which executes wasm32-wasip1[-threads] binaries inside a JS shell (V8 / SpiderMonkey) via a bundled WASI polyfill. Enables running cargo test / cargo bench against the same JS engines used in browser-targeted benches, without source changes.

Changes

  • .cargo/config.toml
    • Added a [target.wasm32-wasip1] entry mirroring the threaded target's rustflags (atomics, bulk-memory, simd128, 4 GiB max memory).
    • Both wasm32-wasip1 and wasm32-wasip1-threads now use runner = "scripts/wasm-runner.sh".
  • scripts/wasm-runner.sh (new, executable)
    • Auto-detects host core count (nproc on Linux, sysctl hw.ncpu on macOS, fallback 1) and exports WASM_HARNESS_ENV_RAYON_NUM_THREADS=<cores>.
    • wasm-harness rewrites WASM_HARNESS_ENV_X to X inside the guest, so rayon sees RAYON_NUM_THREADS without polluting the host shell.
    • Pre-existing WASM_HARNESS_ENV_RAYON_NUM_THREADS is respected (user override).
    • execs wasm-harness with cargo-supplied args.

Usage

Prerequisites: cargo install wasm-harness, then npm i -g jsvu && jsvu to install v8 and/or sm shells (defaults to whatever's first on $PATH / ~/.jsvu/bin).

cargo test  --target wasm32-wasip1
cargo bench --target wasm32-wasip1-threads
JS_SHELL=sm cargo bench --target wasm32-wasip1   # pick SpiderMonkey

Notes

  • wasm-harness auto-forwards RAYON_*, CRITERION_*, RUST_*, NO_COLOR from the host into the guest; the WASM_HARNESS_ENV_ prefix is the explicit escape hatch used here.
  • Bench code that builds its own rayon pool with an explicit num_threads() will ignore RAYON_NUM_THREADS — that's a per-bench concern, not a runner one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant