cargo build --target wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown compiles a Rust crate to bare browser wasm with no host OS APIs.
This is the target behind wasm-pack and wasm-bindgen: pure wasm with no WASI. Because there is no OS, crates that touch the filesystem or threads fail unless they gate wasm support.
What it does
The target produces a wasm module with no WASI imports, intended to run in a browser through JS glue. std is available but many of its OS-backed APIs panic or are unavailable, so crates must be wasm-aware.
Common usage
rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown --release
cargo build --target wasm32-unknown-unknown --no-default-features --features webOptions
| Flag | What it does |
|---|---|
| --target wasm32-unknown-unknown | Compile for browser wasm (no WASI) |
| --release | Optimized build |
| --no-default-features / --features | Toggle crate features for wasm support |
| -Z build-std (nightly) | Rebuild std for the target when needed |
In CI
Add the target once with rustup target add wasm32-unknown-unknown before building; a fresh runner does not have it. Cache ~/.cargo and target/. If a dependency needs OS features, gate it behind cfg(target_arch = "wasm32") or swap it for a wasm-friendly crate.
Common errors in CI
"error[E0463]: can't find crate for std" or "the ... target may not be installed" means run rustup target add wasm32-unknown-unknown. "error: linking with rust-lld failed" often means an incompatible dependency. Crates calling std::fs/net may compile but panic at runtime because there is no OS underneath.