Skip to content

Commit

Permalink
Only use wasm-opt when in release mode
Browse files Browse the repository at this point in the history
This addresses a few pain points where there was no way to reasonably
disable wasm-opt use for debug builds while keeping it enabled for
release builds. There seems to be very few (if any) use cases for using
wasm-opt on a debug build, as such, wasm-opt is now only run on release
builds when enabled.

closes #197
closes #175
  • Loading branch information
thedodd committed Aug 6, 2021
1 parent d24c67e commit eaf8a1e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe
- Fixed [#209](https://github.com/thedodd/trunk/issues/209) where the default Rust App pipeline was causing wasm-opt to be used even for debug builds when the Rust App HTML link was being omitted.
- Closed [#168](https://github.com/thedodd/trunk/issues/158): RSS feed for blog.
- Isolated code used for version checking & formatting of version output for downloadable applications (wasm-bindgen & wasm-opt). Added unit tests to cover this logic.
- Fixed [#197](https://github.com/thedodd/trunk/issues/197) & [#175](https://github.com/thedodd/trunk/pull/175) where disabling wasm-opt for debug builds while keeping it enable for release builds was not possible without some hacking. Now, wasm-opt will only be used for release builds and only when enabled. This semantically matches cargo's behavior with optimizations in release mode.

## 0.12.1
### fixed
Expand Down
2 changes: 1 addition & 1 deletion examples/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<base data-trunk-public-url/>
</head>
<body>
<link data-trunk rel="rust" href="Cargo.toml" data-bin="vanilla-example"/>
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z" data-bin="vanilla-example"/>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/yew/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<base data-trunk-public-url/>
</head>
<body>
<link data-trunk rel="rust" href="Cargo.toml" data-bin="yew-example" data-cargo-features="demo-abc,demo-xyz"/>
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z" data-bin="yew-example" data-cargo-features="demo-abc,demo-xyz"/>
</body>
</html>
4 changes: 2 additions & 2 deletions site/content/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ This will typically look like: `<link data-trunk rel="{type}" href="{path}" ..ot
- `href`: (optional) the path to the `Cargo.toml` of the Rust project. If a directory is specified, then Trunk will look for the `Cargo.toml` in the given directory. If no value is specified, then Trunk will look for a `Cargo.toml` in the parent directory of the source HTML file.
- `data-bin`: (optional) the name of the binary to compile and use as the main WASM application. If the Cargo project has multiple binaries, this value will be required for proper functionality.
- `data-cargo-features`: (optional) Space or comma separated list of cargo features to activate.
- `data-wasm-opt`: (optional) run wasm-opt with the set optimization level. The possible values are `0`, `1`, `2`, `3`, `4`, `s`, `z` or an _empty value_ for wasm-opt's default. Set this option to `0` to disable wasm-opt explicitly. The values `1-4` are increasingly stronger optimization levels for speed. `s` and `z` (z means more optimization) optimize for binary size instead.
- `data-keep-debug`: (optional) instruct `wasm-bindgen` to preserve debug info in the final WASM output, even for `--release` mode.
- `data-wasm-opt`: (optional) run wasm-opt with the set optimization level. The possible values are `0`, `1`, `2`, `3`, `4`, `s`, `z` or an _empty value_ for wasm-opt's default. Set this option to `0` to disable wasm-opt explicitly. The values `1-4` are increasingly stronger optimization levels for speed. `s` and `z` (z means more optimization) optimize for binary size instead. Only used in `--release` mode.
- `data-keep-debug`: (optional) instruct `wasm-bindgen` to preserve debug info in the final WASM output, even for `--release` mode. This may conflict with the use of wasm-opt, so to be sure, it is recommended to set `data-wasm-opt="0"` when using this option.
- `data-no-demangle`: (optional) instruct `wasm-bindgen` to not demangle Rust symbol names.

## sass/scss
Expand Down
5 changes: 5 additions & 0 deletions src/pipelines/rust_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ impl RustApp {

#[tracing::instrument(level = "trace", skip(self, hashed_name))]
async fn wasm_opt_build(&self, hashed_name: &str) -> Result<()> {
// If not in release mode, we skip calling wasm-opt.
if !self.cfg.release {
return Ok(());
}

// If opt level is off, we skip calling wasm-opt as it wouldn't have any effect.
if self.wasm_opt == WasmOptLevel::Off {
return Ok(());
Expand Down

0 comments on commit eaf8a1e

Please sign in to comment.