#cargo #run #serve #wasm-bindgen


Trivially run wasm applications and examples in the browser

6 releases

0.3.2 Mar 27, 2023
0.3.1 Mar 25, 2023
0.3.0 Dec 20, 2022
0.2.0 Oct 9, 2022
0.1.0 Jan 5, 2022

#86 in WebAssembly

Download history 1141/week @ 2023-08-11 988/week @ 2023-08-18 1382/week @ 2023-08-25 1101/week @ 2023-09-01 675/week @ 2023-09-08 822/week @ 2023-09-15 1048/week @ 2023-09-22 1207/week @ 2023-09-29 1202/week @ 2023-10-06 1421/week @ 2023-10-13 1112/week @ 2023-10-20 1187/week @ 2023-10-27 582/week @ 2023-11-03 603/week @ 2023-11-10 774/week @ 2023-11-17 1023/week @ 2023-11-24

3,189 downloads per month


290 lines

cargo run-wasm

Crates.io Docs dependency status

Allows running wasm applications and examples as simply as:

cargo run-wasm --example example_name


cargo run-wasm --package crate_name


cargo run-wasm --bin bin_name

In the background it:

  1. Compiles the rust project to wasm
  2. Runs wasm-bindgen
  3. Generates an index.html that runs the wasm.
  4. Launches a tiny webserver to serve index.html + your wasm


  1. Setup your wasm runnable project as a crate within a cargo workspace
  2. Create a crate in the workspace named run-wasm with:


name = "run-wasm"
version = "0.1.0"
edition = "2021"

cargo-run-wasm = "0.3.0"


fn main() {
    cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
  1. Create a .cargo/config file containing:
run-wasm = "run --release --package run-wasm --"
  1. Thats it, you can now run the commands described earlier. You can also run cargo run-wasm --help to view all the possible flags.

Note: If you want to avoid restructuring your project into a proper workspace you can do so by combining your workspace and crate Cargo.toml into a single file like winit does.

Advantages over an equivalent bash/powershell/bat script

  • cross platform
  • 0 external dependencies
  • better UX + more robust than anything hacked together with bash/powershell/bat
  • wasm-bindgen-cli version is always in sync with wasm-bindgen version because cargo update updates both of them at the same time thanks to being in the same workspace

cargo custom command

cargo-run-wasm is not available as a cargo custom command as that would cause:

  • issues with mismatches between wasm-bindgen versions
  • issues with keeping a stable interface with the wasm app
  • gives the idea that the command is compatible with every project that uses wasm which is not the case.


If you wish to set custom css, do so in the string argument to run_wasm_with_css.

However it is not possible to set custom html from cargo-run-wasm, instead any DOM elements you require should be created from within your crate or example using web-sys or another crate. The reasoning is that in the case an example requires custom HTML it will probably:

  • require HTML that is unique to that example while cargo-run-wasm is only capable of global settings
  • require web-sys or similar to interact with the DOM at runtime anyway


Since this tool has a trivial implementation the MSRV is at 1.59 and will only be increased if dependencies require it. If it is ever increased it must be below the MSRV of maintained branches of important users such as wgpu and winit.

The MSRV is enforced in CI and locally via the rust-toolchain.toml file.


  • wasm-server-runner
    • Advantages
      • Integrates better with cargo
      • Doesnt require any setup to live within the project
    • Disadvantages
      • Requires the user to run cargo install wasm-server-runner
      • wasm-bindgen versions can go out of sync causing issues like this


Licensed under either of

at your option.


~241K SLoC