Skip to content

Commit 265260b

Browse files
author
Robert Deaton
committed
feat: Enable plumbing through keep_names to wasm build for better stack traces
1 parent 9b0d380 commit 265260b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

packages/cli/src/build/request.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ pub(crate) struct BuildRequest {
393393
pub(crate) skip_assets: bool,
394394
pub(crate) wasm_split: bool,
395395
pub(crate) debug_symbols: bool,
396+
pub(crate) keep_names: bool,
396397
pub(crate) inject_loading_scripts: bool,
397398
pub(crate) custom_linker: Option<PathBuf>,
398399
pub(crate) base_path: Option<String>,
@@ -1006,6 +1007,7 @@ impl BuildRequest {
10061007
base_path: args.base_path.clone(),
10071008
wasm_split: args.wasm_split,
10081009
debug_symbols: args.debug_symbols,
1010+
keep_names: args.keep_names,
10091011
inject_loading_scripts: args.inject_loading_scripts,
10101012
apple_entitlements: args.apple_entitlements.clone(),
10111013
apple_team_id: args.apple_team_id.clone(),
@@ -4061,7 +4063,10 @@ impl BuildRequest {
40614063
|| self.wasm_split
40624064
|| !self.release
40634065
|| ctx.mode == BuildMode::Fat;
4064-
let keep_names = self.wasm_split || ctx.mode == BuildMode::Fat;
4066+
let keep_names = self.config.web.wasm_opt.keep_names
4067+
|| self.keep_names
4068+
|| self.wasm_split
4069+
|| ctx.mode == BuildMode::Fat;
40654070
let demangle = false;
40664071
let wasm_opt_options = WasmOptConfig {
40674072
memory_packing: self.wasm_split,

packages/cli/src/cli/target.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ pub(crate) struct TargetArgs {
104104
#[clap(long, default_value_t = true, help_heading = HELP_HEADING, num_args = 0..=1)]
105105
pub(crate) debug_symbols: bool,
106106

107+
/// Keep the name section in the wasm binary, useful for profiling and debugging [default: false]
108+
///
109+
/// Unlike --debug-symbols which preserves DWARF debug info (requiring a browser extension to
110+
/// read), the name section allows tools like console_error_panic_hook to print backtraces with
111+
/// human-readable function names without any browser extension.
112+
#[clap(long, default_value_t = false, help_heading = HELP_HEADING)]
113+
pub(crate) keep_names: bool,
114+
107115
/// The name of the device we are hoping to upload to. By default, dx tries to upload to the active
108116
/// simulator. If the device name is passed, we will upload to that device instead.
109117
///
@@ -190,6 +198,7 @@ impl Anonymized for TargetArgs {
190198
"inject_loading_scripts": self.inject_loading_scripts,
191199
"wasm_split": self.wasm_split,
192200
"debug_symbols": self.debug_symbols,
201+
"keep_names": self.keep_names,
193202
"device": self.device,
194203
"base_path": self.base_path.is_some(),
195204
"cargo_args": self.cargo_args.is_some(),

packages/cli/src/config/web.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ pub(crate) struct WasmOptConfig {
5959
#[serde(default = "false_bool")]
6060
pub(crate) debug: bool,
6161

62+
/// Keep the wasm name section, useful for profiling and debugging
63+
///
64+
/// Unlike `debug` which preserves DWARF debug symbols (requiring a browser extension to read),
65+
/// the name section allows tools like `console_error_panic_hook` to print backtraces with
66+
/// human-readable function names without any browser extension.
67+
#[serde(default = "false_bool")]
68+
pub(crate) keep_names: bool,
69+
6270
/// Enable memory packing
6371
#[serde(default = "false_bool")]
6472
pub(crate) memory_packing: bool,

0 commit comments

Comments
 (0)