Steps for usage
- First, download the appropriate tarball below. Only Linux/macOS tarballs are available right now, but that's just because I don't have a Windows machine handy. When this is landed in upstream rust-lang/rust we'll have standard releases for everyone!
- Extract it, it'll make a directory called
wasi-rustc
- Execute
rustup toolchain link wasi $PWD/wasi-rustc
- Execute
rustc +wasi -vV
and make sure it works - Create
hello.rs
which is the standard rust hello world rustc +wasi hello.rs --target wasm32-unknown-wasi
- Clone https://github.com/CraneStation/wasmtime
cargo run --bin wasmtime /path/to/hello.wasm
And that's it!
If you want to interoperate with C code, then finish step 4 above and follow afterwards with:
- Download Clang 8.0 for your platform
- Clone https://github.com/CraneStation/wasi-sysroot
- Run
make WASM_CC=/path/to/clang
- Create an executable script called
wasm32-wasi-clang
which looks like this:
#!/bin/sh
exec /path/to/clang --sysroot /path/to/wasi-sysroot/sysroot "$@"
- Execute
rustc +wasi hello.rs --target wasm32-unknown-wasi -C target-feature=-crt-static -C linker=/path/to/wasm32-wasi-clang
That final step will link against the sysroot rather than the internal one provided by rustc. You can also produce a staticlib and avoid -C linker
and then link manually. You can also use crates like cc
to build C code as part of your Rust application. Up to you!