Debian Codegraph @

wasm32-development.md

raw symbols SCIP
1 # Developing/Testing the `wasm32` Target
2
3 Since there is no native host platform for WebAssembly, developing/targeting requires a bit more setup than a vanilla
4 Rust toolchain environment. To build/target this library outside a `wasm-pack` context, you can do the following:
5
6 * Install toolchain with `wasm32-wasi` or `wasm32-unknown-unknown` (e.g. `rustup target add wasm32-wasi`).
7 * `wasm32-wasi` is a nice target because it gives us the capability to run the tests as-is with a WASM runtime.
8 * Install a WASM runtime (e.g. [Wasmer]/[Wasmtime]/[WAVM]).
9 * Install `wasm-runner` a simple runner wrapper to run WASM targeted code with a WASM runtime:
10
11 ```
12 $ cargo install wasm-runner
13 ```
14
15 * Add a Cargo configuration file to target `wasm` and allow the unit tests to be run with a WASM VM *by default*:
16
17 ```
18 [build]
19 target = "wasm32-wasi"
20 rustflags = "-C target-feature=+simd128"
21
22 [target.'cfg(target_arch="wasm32")']
23 runner = ["wasm-runner", "wasmer"]
24 ```
25
26 * Run the build/tests:
27
28 ```
29 $ cargo test
30 $ cargo test --all-features
31 ```
32
33 You can do this without configuration as well:
34
35 ```
36 $ RUSTFLAGS="-C target-feature=+simd128" \
37 CARGO_TARGET_WASM32_WASI_RUNNER="wasm-runner wasmer" \
38 cargo test --target wasm32-wasi
39 $ RUSTFLAGS="-C target-feature=+simd128" \
40 CARGO_TARGET_WASM32_WASI_RUNNER="wasm-runner wasmer" \
41 cargo test --target wasm32-wasi --all-features
42 ```
43
44 [wasmer]: https://wasmer.io/
45 [wasmtime]: https://wasmtime.dev/
46 [wavm]: https://wavm.github.io/