Skip to content

wasi3

Latest
Compare
Choose a tag to compare
@alexcrichton alexcrichton released this 25 Mar 16:31

Steps for usage

  1. 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!
  2. Extract it, it'll make a directory called wasi-rustc
  3. Execute rustup toolchain link wasi $PWD/wasi-rustc
  4. Execute rustc +wasi -vV and make sure it works
  5. Create hello.rs which is the standard rust hello world
  6. rustc +wasi hello.rs --target wasm32-unknown-wasi
  7. Clone https://github.com/CraneStation/wasmtime
  8. 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:

  1. Download Clang 8.0 for your platform
  2. Clone https://github.com/CraneStation/wasi-sysroot
  3. Run make WASM_CC=/path/to/clang
  4. Create an executable script called wasm32-wasi-clang which looks like this:
#!/bin/sh
exec /path/to/clang --sysroot /path/to/wasi-sysroot/sysroot "$@"
  1. 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!