cargo wasi will run
wasm-opt over optimized WebAssembly
wasm-opt program is a tool in the binaryen
toolkit which is a wasm-to-wasm
transformation that optimizes the input wasm module. Often
wasm-opt can get
10-20% size reductions over LLVM's raw output.
There are a number of heuristics that are used to configure how
run though and it's important to keep those in mind!
Every release of
cargo wasi is hardcoded to download a precompiled version of
wasm-opt. This binary will be lazily downloaded and then executed. You can
also request that a specific
wasm-opt binary is used via the
Note that we're interested in feedback on this strategy, so please don't hesitate to file an issue if this doesn't work for you!
If DWARF debug information is requested for a build (default on for debug
builds, default off for release builds) then
wasm-opt will be disabled.
At the time of this writing
wasm-opt does not support preserving DWARF debug
information through its transformations, so
wasm-opt is skipped.
In effect this means that
wasm-opt will not run in debug mode, but it will
run in release mode. If you enable debug info in release mode, though, then it
will not run.
You can configure debuginfo through your
debug = 1
wasm-opt tool, like most compilers, supports multiple levels of
optimization. The optimization level is by default selected to match
own optimization level. If
rustc's optimization level is "0", then
will not be run.
This effectively means that in debug mode this is another reason that
wasm-opt is disabled (because debug mode uses optimization level 0). In
release mode we will by default execute
wasm-opt -O3 because
You can configure
wasm-opt's optimization level through your
Cargo.toml. For example to optimize for size instead of speed:
opt-level = 's'
You can also outright disable
wasm-opt via configuration by
wasm-opt = false
Finally, as one last caveat,
wasm-opt is automatically disabled if
wasm-bindgen is used as part of the build. If
wasm-bindgen is used it's
assumed that WebAssembly Interface Types are also used, and currently
wasm-opt (at the time of this writing) does not have support for WebAssembly
Interface Types. If we were to run
wasm-opt it would produce a broken binary!