cargo build --target wasm32-wasip1 (WASI)
cargo build --target wasm32-wasip1 compiles a Rust crate to a WASI module that runs under wasmtime, wasmer, or WasmEdge.
WASI gives wasm a POSIX-like interface for files, args, and env, so ordinary Rust command-line programs run in a runtime. The target was renamed from wasm32-wasi to wasm32-wasip1 in recent toolchains.
What it does
The target links against a WASI libc so std APIs for files, stdio, args, and env work when run in a WASI runtime. The output is a command module with a _start entry point.
Common usage
rustup target add wasm32-wasip1
cargo build --target wasm32-wasip1 --release
wasmtime run --dir=. \
target/wasm32-wasip1/release/app.wasmOptions
| Flag | What it does |
|---|---|
| --target wasm32-wasip1 | Target WASI preview1 (older alias: wasm32-wasi) |
| --target wasm32-wasip2 | Target WASI preview2 / the component model |
| --release | Optimized build |
| --bin <name> | Select a binary in a multi-target crate |
In CI
Add the target with rustup target add wasm32-wasip1 (or wasm32-wasi on older toolchains). Recent Rust renamed the target: scripts pinned to wasm32-wasi break after an upgrade, so match the target name to your toolchain version. Run the result with a WASI runtime, granting dirs via --dir.
Common errors in CI
"error: can't find crate for std" means the target is not installed; run rustup target add wasm32-wasip1. "error: target wasm32-wasi not found" after an upgrade means the target was renamed to wasm32-wasip1. Running the module without a WASI runtime, or without --dir, yields import or preopen errors.