Rust & WebAssembly · Getting Started
Compiling Rust to WASM
Using wasm-pack to produce a browser-ready module.
1 min readPublished Updated
- wasm
- wasm-pack
wasm-pack compiles a Rust crate into a WebAssembly module with JavaScript bindings.
bash
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
wasm-pack build rust-core --target web --releaseThe output is a .wasm binary plus a small JS glue file that loads and instantiates it.
Install the toolchain
Add thewasm32-unknown-unknowntarget and installwasm-pack.Build the crate
Runwasm-pack buildwith--target webso the glue loads in the browser.Copy the artifacts
Place the.wasmand glue files inpublic/wasm/.