This repository demonstrates how to prepare a Rust toolchain for wasi-threads.
Run the following command to compile an example code to WASM:
./compile-rust.sh stable-wasm32-wasi-preview1-threads tests/simple
This will generate a WASM binary in tests/simple/target/wasm32-wasi-preview1-threads/debug/simple.wasm
that can be run in WASM runtime that implements wasi-threads
(e.g. WebAssembly Micro Runtime (WAMR) or Wasmtime):
# running on WAMR
iwasm tests/simple/target/wasm32-wasi-preview1-threads/debug/simple.wasm
# running on Wasmtime
wasmtime run --wasm-features=threads --wasi-modules=experimental-wasi-threads \
tests/simple/target/wasm32-wasi-preview1-threads/debug/simple.wasm
./compile-rust.sh
command builds a toolchain container that compiles a Rust version with some of the patches applied (please note patches won't be needed after this PR is merged and available in the Rust stable branch).
The script takes two parameters:
- BUILD_TYPE - it describes a variant of the Rust toolchain. Currently, there are three variants supported:
stable-wasm32-wasi-with-threads
- a stable branch of the Rust compiler is used; the threading support is by pointing thewasm32-wasi
target to usewasm32-wasi-threads
WASI libc target, and compiling Rust's standard library with the following target features:+atomics,+bulk-memory,+mutable-globals
. The wasi-locks patch is appliedstable-wasm32-wasi-preview1-threads
- a stable branch of the Rust compiler is used; the threading is exposed in thewasm32-wasi-preview1-threads
target by applying the wasm32-wasi-preview1-threads patch.nightly-wasm32-wasi-preview1-threads
- a master branch of the Rust compiler is used; the threading is exposed in thewasm32-wasi-preview1-threads
. No patches are required
- CRATE_PATH - a path to a crate to compile using the toolchain