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
16 changes: 16 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

test-wasm:
runs-on: ubuntu-latest
strategy:
matrix:
simd128: ["-simd128", "+simd128"]
env:
RUSTFLAGS: -C target-feature=${{ matrix.simd128 }}
CARGO_TARGET_WASM32_WASIP1_RUNNER: node --no-warnings scripts/wasi-node.mjs
steps:
- uses: actions/checkout@v4
- run: rustup target add wasm32-wasip1 wasm32-unknown-unknown
- name: Check wasm32-unknown-unknown
run: cargo check --verbose --release --lib --no-default-features --features scalar --target wasm32-unknown-unknown
- name: Run release tests
run: cargo test --verbose --release --no-default-features --features rand,scalar --target wasm32-wasip1
25 changes: 25 additions & 0 deletions scripts/wasi-node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Run a wasm32-wasip1 binary under Node's V8 engine, for use as a cargo runner:
//
// CARGO_TARGET_WASM32_WASIP1_RUNNER="node --no-warnings scripts/wasi-node.mjs" \
// RUSTFLAGS="-C target-feature=+simd128" \
// cargo test --release --features scalar --target wasm32-wasip1
import { readFile } from 'node:fs/promises';
import process from 'node:process';
import { WASI } from 'node:wasi';

const [wasmPath, ...args] = process.argv.slice(2);
if (!wasmPath) {
console.error('usage: node wasi-node.mjs <file.wasm> [args...]');
process.exit(2);
}

const wasi = new WASI({
version: 'preview1',
args: [wasmPath, ...args],
env: process.env,
returnOnExit: true,
});

const module = await WebAssembly.compile(await readFile(wasmPath));
const instance = await WebAssembly.instantiate(module, wasi.getImportObject());
process.exitCode = wasi.start(instance);