Rust Wasix Usage
Currenly, Wasix is only supported by the Wasmer runtime. So, you need to install the Wasmer (opens in a new tab) runtime.
cargo wasix
cargo wasix can be used to run, test, and build Rust programs for the Wasix
Running a binary
$ cargo wasix runTesting a binary
$ cargo wasix testBuilding a binary
$ cargo wasix buildBenchmarking a binary
$ cargo wasix benchPassing runtime flags with -W,
run, test, and bench execute the built .wasm with the Wasmer
runtime. To pass flags through to the runtime, use -W, followed by
comma-separated arguments — the same idea as clang's -Wl,:
$ cargo wasix run -W,--net
$ cargo wasix run -W,--net,--volume,./tls:/tlsThe first passes --net to wasmer (enabling networking); the second
additionally mounts the local ./tls directory at /tls inside the
sandbox. Anything after a standalone -- is forwarded to your program (or
the test harness) instead of the runtime:
$ cargo wasix run -W,--net -- --port 8080See Wasmer's runtime flags (opens in a new tab)
for what can be passed. For test and bench, cargo-wasix also applies
some defaults automatically (the package directory is mounted at
/project, and the host temp directory at /tmp); set
CARGO_WASIX_NO_RUN_DEFAULTS=1 to disable them.
Setting up a project
$ cargo wasix initWrites the WASIX registry config
into the workspace's .cargo/config.toml without building anything. The
other commands apply the same config automatically, so running init is
optional — it exists to set up (or verify) a project explicitly, e.g. before
committing the config.
wasmer
wasmer-cli can also be used to run wasix binaries directly, as well as
provide additional flags such as --net and --volume.
Additional flags
Some wasm files need extra flags that can be provided while running the file
with the runtime. For example, wasmer run --net ./target/wasm32-wasmer-wasi/debug/hello.wasm. Learn more about Wasmer's
runtime flags (opens in a new tab)
The WASIX Registry
Crates that need WASIX-specific patches resolve automatically through the
WASIX registry — no
[patch.crates-io] entries required.