Tools You Should Know
seeks to be a one-stop shop for building and working with Rust-generated WebAssembly that you would like to interoperate with JavaScript, onthe Web or with Node.js. wasm-pack
helps you build and publish Rust-generatedWebAssembly to the npm registry to be used alongside any other JavaScriptpackage in workflows that you already use.
wasm-opt | repository
The wasm-opt
tool reads WebAssembly as input, runs transformation,optimization, and/or instrumentation passes on it, and then emits thetransformed WebAssembly as output. Running it on the .wasm
binaries producedby LLVM by way of rustc
will usually create .wasm
binaries that are bothsmaller and execute faster. This tool is a part of the binaryen
project.
The wasm2js
tool compiles WebAssembly into "almost asm.js". This is great forsupporting browsers that don't have a WebAssembly implementation, such asInternet Explorer 11. This tool is a part of the project.
wasm-gc | repository
You don't usually need to use this tool yourself because of two reasons:
rustc
now has a new enough version oflld
that it supports the—gc-sections
flag for WebAssembly. This is automatically enabled for LTObuilds.- The
wasm-bindgen
CLI tool runswasm-gc
for you automatically.
wasm-snip
replaces a WebAssembly function's body with an instruction.
Maybe you know that some function will never be called at runtime, but thecompiler can't prove that at compile time? Snip it! Then run wasm-gc
again andall the functions it transitively called (which could also never be called atruntime) will get removed too.
twiggy | repository
twiggy
is a code size profiler for .wasm
binaries. It analyzes a binary'scall graph to answer questions like:
- Why was this function included in the binary in the first place? I.e. whichexported functions are transitively calling it?
Use twiggy
to make your binaries slim!
Print low-level details about a .wasm
binary and each of its sections. Alsosupports disassembling into the WAT text format. It's like objdump
but forWebAssembly. This is a part of the WABT project.