Skip to content

Commit ce872ce

Browse files
maratik123ctron
authored andcommitted
feat: add data-wasm-opt-params
1 parent 097ed88 commit ce872ce

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

guide/src/assets/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This will typically look like: `<link data-trunk rel="{type}" href="{path}" ..ot
2525
- `data-cargo-all-features`: (optional) Enables all Cargo features.
2626
- Neither compatible with `data-cargo-features` nor `data-cargo-no-default-features`.
2727
- `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.
28+
- `data-wasm-opt-params`: (optional) run wasm-opt with the additional params. Only used in `--release` mode.
2829
- `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.
2930
- `data-no-demangle`: (optional) instruct `wasm-bindgen` to not demangle Rust symbol names.
3031
- `data-reference-types`: (optional) instruct `wasm-bindgen` to enable [reference types](https://rustwasm.github.io/docs/wasm-bindgen/reference/reference-types.html).

site/content/assets.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This will typically look like: `<link data-trunk rel="{type}" href="{path}" ..ot
2929
- `data-cargo-all-features`: (optional) Enables all Cargo features.
3030
- Neither compatible with `data-cargo-features` nor `data-cargo-no-default-features`.
3131
- `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.
32+
- `data-wasm-opt-params`: (optional) run wasm-opt with the additional params. Only used in `--release` mode.
3233
- `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.
3334
- `data-no-demangle`: (optional) instruct `wasm-bindgen` to not demangle Rust symbol names.
3435
- `data-reference-types`: (optional) instruct `wasm-bindgen` to enable [reference types](https://rustwasm.github.io/docs/wasm-bindgen/reference/reference-types.html).

src/pipelines/rust/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pub struct RustApp {
7878
/// An optional optimization setting that enables wasm-opt. Can be nothing, `0` (default), `1`,
7979
/// `2`, `3`, `4`, `s or `z`. Using `0` disables wasm-opt completely.
8080
wasm_opt: WasmOptLevel,
81+
/// An optional optimization command line params to wasm-opt if it is enabled.
82+
wasm_opt_params: Vec<String>,
8183
/// The value of the `--target` flag for wasm-bindgen.
8284
wasm_bindgen_target: WasmBindgenTarget,
8385
/// Name for the module. Is binary name if given, otherwise it is the name of the cargo
@@ -169,6 +171,12 @@ impl RustApp {
169171
WasmOptLevel::Off
170172
}
171173
});
174+
let wasm_opt_params = attrs
175+
.get("data-wasm-opt-params")
176+
.iter()
177+
.flat_map(|val| val.split_whitespace())
178+
.map(|val| val.to_string())
179+
.collect();
172180
let wasm_bindgen_target = attrs
173181
.get("data-bindgen-target")
174182
.map(|s| s.parse())
@@ -282,6 +290,7 @@ impl RustApp {
282290
reference_types,
283291
weak_refs,
284292
wasm_opt,
293+
wasm_opt_params,
285294
wasm_bindgen_target,
286295
app_type,
287296
name,
@@ -331,6 +340,7 @@ impl RustApp {
331340
reference_types: false,
332341
weak_refs: false,
333342
wasm_opt: WasmOptLevel::Off,
343+
wasm_opt_params: Default::default(),
334344
app_type: RustAppType::Main,
335345
wasm_bindgen_target: WasmBindgenTarget::Web,
336346
name,
@@ -890,6 +900,7 @@ impl RustApp {
890900
let output = output.join(format!("{}_bg.wasm", self.name));
891901
let arg_output = format!("--output={output}");
892902
let arg_opt_level = format!("-O{}", self.wasm_opt.as_ref());
903+
let arg_opt_params = self.wasm_opt_params.as_slice();
893904
let target_wasm = self
894905
.cfg
895906
.staging_dist
@@ -902,6 +913,8 @@ impl RustApp {
902913
args.push("--enable-reference-types");
903914
}
904915

916+
args.extend(arg_opt_params.iter().map(|s| s.as_str()));
917+
905918
// Invoke wasm-opt.
906919
tracing::debug!("calling wasm-opt");
907920
common::run_command(wasm_opt_name, &wasm_opt, &args, &self.cfg.working_directory)

0 commit comments

Comments
 (0)