Project Setup

Rust

First, you’ll need Rust. To install Rust and the cargo build tool, follow the official instructions.

Wasm Build Tools

Extra tooling is needed to facilitate the interop between WebAssembly and JavaScript. Additionally, depending on the tool you choose, they can help make deployment and packaging much less of a headache by generating all of the wrapper JavaScript code necessary to run the .wasm file from your app in the browser.

wasm-pack

A CLI tool developed by the Rust / Wasm Working Group for packaging up WebAssembly. Best used together with the wasm-pack-plugin for Webpack.

Get started with wasm-pack

wasm-bindgen

Both a library and CLI tool and is also developed by the Rust / Wasm Working Group. It is a low level tool (used internally by wasm-pack) which facilitates JS / WebAssembly interoperability. We don’t recommend using wasm-bindgendirectly because it requires hand-writing some JavaScript to bootstrap your WebAssembly binary. However, it is possible and more info can be found on the wasm-bindgen guide.

Get started with wasm-bindgen

cargo-web

The preferred web workflow tool before the introduction of wasm-pack and wasm-bindgen. It is still the quickest way to get up and running and worth installing to run examples that haven’t been migrated to support wasm-pack yet.

Getting started with cargo web

Comparison

wasm-packwasm-bindgencargo-web
Project StatusActively maintained by the Rust / Wasm Working GroupActively maintained by the Rust / Wasm Working GroupNo Github activity for over 6 months
Dev ExperienceAlmost there! Requires webpack for best experience.Barebones. You’ll need to write some scripts to streamline your dev experience.Just works! Batteries included, no external dependencies needed.
Local ServerSupported with webpack pluginNot supportedSupported
Auto rebuild on local changesSupported with webpack pluginNot SupportedSupported
Headless Browser TestingSupportedSupportedSupported
Supported Targets
  • wasm32-unknown-unknown
  • wasm32-unknown-unknown
  • wasm32-unknown-unknown
  • wasm32-unknown-emscripten
  • asmjs-unknown-emscripten
web-sysCompatibleCompatibleIncompatible
stdwebCompatibleCompatibleCompatible
Example UsageStarter templateBuild script for Yew examplesBuild script for Yew examples