diff --git a/packages/cli/src/build/request.rs b/packages/cli/src/build/request.rs index e50990ddc..96c1cb272 100644 --- a/packages/cli/src/build/request.rs +++ b/packages/cli/src/build/request.rs @@ -393,6 +393,7 @@ pub(crate) struct BuildRequest { pub(crate) skip_assets: bool, pub(crate) wasm_split: bool, pub(crate) debug_symbols: bool, + pub(crate) keep_names: bool, pub(crate) inject_loading_scripts: bool, pub(crate) custom_linker: Option, pub(crate) base_path: Option, @@ -1025,6 +1026,7 @@ impl BuildRequest { base_path: args.base_path.clone(), wasm_split: args.wasm_split, debug_symbols: args.debug_symbols, + keep_names: args.keep_names, inject_loading_scripts: args.inject_loading_scripts, apple_entitlements: args.apple_entitlements.clone(), apple_team_id: args.apple_team_id.clone(), @@ -4309,7 +4311,10 @@ impl BuildRequest { || self.wasm_split || !self.release || ctx.mode == BuildMode::Fat; - let keep_names = self.wasm_split || ctx.mode == BuildMode::Fat; + let keep_names = self.config.web.wasm_opt.keep_names + || self.keep_names + || self.wasm_split + || ctx.mode == BuildMode::Fat; let demangle = false; let wasm_opt_options = WasmOptConfig { memory_packing: self.wasm_split, diff --git a/packages/cli/src/cli/target.rs b/packages/cli/src/cli/target.rs index 5f8bcb485..ea77d895c 100644 --- a/packages/cli/src/cli/target.rs +++ b/packages/cli/src/cli/target.rs @@ -104,6 +104,14 @@ pub(crate) struct TargetArgs { #[clap(long, default_value_t = true, help_heading = HELP_HEADING, num_args = 0..=1)] pub(crate) debug_symbols: bool, + /// Keep the name section in the wasm binary, useful for profiling and debugging [default: false] + /// + /// Unlike --debug-symbols which preserves DWARF debug info (requiring a browser extension to + /// read), the name section allows tools like console_error_panic_hook to print backtraces with + /// human-readable function names without any browser extension. + #[clap(long, default_value_t = false, help_heading = HELP_HEADING)] + pub(crate) keep_names: bool, + /// The name of the device we are hoping to upload to. By default, dx tries to upload to the active /// simulator. If the device name is passed, we will upload to that device instead. /// @@ -190,6 +198,7 @@ impl Anonymized for TargetArgs { "inject_loading_scripts": self.inject_loading_scripts, "wasm_split": self.wasm_split, "debug_symbols": self.debug_symbols, + "keep_names": self.keep_names, "device": self.device, "base_path": self.base_path.is_some(), "cargo_args": self.cargo_args.is_some(), diff --git a/packages/cli/src/config/web.rs b/packages/cli/src/config/web.rs index 8e1343f9f..de9781313 100644 --- a/packages/cli/src/config/web.rs +++ b/packages/cli/src/config/web.rs @@ -59,6 +59,14 @@ pub(crate) struct WasmOptConfig { #[serde(default = "false_bool")] pub(crate) debug: bool, + /// Keep the wasm name section, useful for profiling and debugging + /// + /// Unlike `debug` which preserves DWARF debug symbols (requiring a browser extension to read), + /// the name section allows tools like `console_error_panic_hook` to print backtraces with + /// human-readable function names without any browser extension. + #[serde(default = "false_bool")] + pub(crate) keep_names: bool, + /// Enable memory packing #[serde(default = "false_bool")] pub(crate) memory_packing: bool,