mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 11:02:11 +03:00
25b26f41e7
... and add a parallel raytracing demo! This commit adds enough support to `wasm-bindgen` to produce a workable wasm binary *today* with the experimental WebAssembly threads support implemented in Firefox Nightly. I've tried to comment what's going on in the commits and such, but at a high level the changes made here are: * A new transformation, living in a new `wasm-bindgen-threads-xform` crate, prepares a wasm module for parallel execution. This performs a number of mundane tasks which I hope to detail in a blog post later on. * The `--no-modules` output is enhanced with more support for when shared memory is enabled, allowing passing in the module/memory to initialize the wasm instance on multiple threads (sharing both module and memory). * The `wasm-bindgen` crate now offers the ability, in `--no-modules` mode, to get a handle on the `WebAssembly.Module` instance. * The example itself requires Xargo to recompile the standard library with atomics and an experimental feature enabled. Afterwards it experimentally also enables threading support in wasm-bindgen. I've also added hopefully enough CI support to compile this example in a builder so we can upload it and poke around live online. I hope to detail more about the technical details here in a blog post soon as well!
26 lines
1005 B
Bash
Executable File
26 lines
1005 B
Bash
Executable File
#!/bin/sh
|
|
|
|
set -ex
|
|
|
|
# Two critical steps are required here to get this working:
|
|
#
|
|
# * First, the Rust standard library needs to be compiled. The default version
|
|
# is not compatible with atomics so we need to compile a version, with xargo,
|
|
# that is compatible.
|
|
#
|
|
# * Next we need to compile everything with the `atomics` feature enabled,
|
|
# ensuring that LLVM will generate atomic instructions and such.
|
|
RUSTFLAGS='-C target-feature=+atomics' \
|
|
rustup run nightly xargo build --target wasm32-unknown-unknown --release
|
|
|
|
# Threading support is disabled by default in wasm-bindgen, so use an env var
|
|
# here to turn it on for our bindings generation. Also note that webpack isn't
|
|
# currently compatible with atomics, so we go with the --no-modules output.
|
|
WASM_BINDGEN_THREADS=1 \
|
|
cargo +nightly run --manifest-path ../../crates/cli/Cargo.toml \
|
|
--bin wasm-bindgen -- \
|
|
../../target/wasm32-unknown-unknown/release/raytrace_parallel.wasm --out-dir . \
|
|
--no-modules
|
|
|
|
python3 -m http.server
|