Skip to content

Intercept cargo's -C strip in the rustc wrapper instead of predicting it - #5737

Open
nicoburns wants to merge 2 commits into
mainfrom
devin/1785890005-rustc-wrapper-strip
Open

Intercept cargo's -C strip in the rustc wrapper instead of predicting it#5737
nicoburns wants to merge 2 commits into
mainfrom
devin/1785890005-rustc-wrapper-strip

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

Fixes #5119 (wasm-opt SIGABRT "compile unit size was incorrect" on dx build --web --release, and more generally ~1.3MB of leftover std DWARF in release wasm).

Since #4966, dx injects --config profile.<x>.strip=false so manganis asset symbols survive the build, then strips manually in post_process_executable() based on get_strip_setting(). That prediction only honored an explicit strip key in Cargo.toml, missing Cargo's implicit default (since Rust 1.77, debuginfo is stripped when the profile's debuginfo is off — as release is by default). The un-stripped DWARF then gets rewritten by wasm-bindgen and crashes binaryen's DWARF re-emitter.

Instead of predicting what Cargo would do, this PR lets Cargo compute the strip setting and intercepts it in the rustc wrapper (RUSTC_WORKSPACE_WRAPPER), which dx already uses for Base/Fat builds:

run_rustc():
  strip = extract_strip_arg(&mut captured_args)   // removes -C strip=X / -Cstrip=X
  RustcArgs { args: filtered, envs, cwd, strip }  // new #[serde(default)] strip field
  // rustc is invoked without the flag, so symbols survive for asset extraction

post_process_executable():
  match recorded_strip_setting(&artifacts.mode) { // reads {tip}.bin.json from the scope dir
    "debuginfo" => rust-objcopy --strip-debug,
    "symbols"   => rust-objcopy --strip-all,
    _           => no-op,
  }
  • profile_args() no longer injects strip=false, and get_strip_setting() is deleted.
  • Since Cargo itself resolves the value, every source it considers is honored with no duplicated logic: profile inherits chains, .cargo/config.toml [profile] tables, CARGO_PROFILE_* env vars, and the implicit 1.77 default.
  • Thin builds replay the captured args, which already have the flag removed, so patches stay un-stripped (post-processing only runs for Base/Fat). wasm_split builds are still never stripped.
  • Bumped the rustc-wrapper scope version to 2 so stale captures (with -C strip still in args and no strip field) aren't replayed.

This is the more robust alternative to #5736, which instead mirrors Cargo's implicit default inside get_strip_setting() (and cannot see .cargo/config.toml / env-var overrides).

Verification

With a fresh cargo new app depending on dioxus (feature web), using dx built from this branch:

  • dx build --web --release: output wasm has no .debug_* custom sections (on main, ~1.1MB of .debug_* remains).
  • dx build --web (dev): debug sections retained.
  • Custom profile with strip = "symbols": binary is fully stripped (--strip-all, no name section), assets still extracted.
  • Custom profile with debug = true and no strip key: not stripped.
  • CARGO_PROFILE_RELEASE_STRIP=none dx build --web --release: env override honored, debuginfo retained (the key case cli: mirror Cargo's implicit strip default when manually stripping binaries (fixes wasm-opt SIGABRT) #5736 can't handle).
  • dx build --web --fat-binary: fat build path still works.

cargo fmt and cargo clippy -p dioxus-cli are clean.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/51b6fb74d9a0452985a2f6840ff2d2bd
Requested by: @nicoburns

The CLI previously injected --config profile.<x>.strip=false and predicted
the profile's strip setting with get_strip_setting(), which missed cargo's
implicit default of stripping debuginfo when debuginfo is disabled (Rust
1.77+), leaving ~1.3MB of DWARF in release wasm and crashing wasm-opt.

Now the rustc wrapper removes the -C strip=... flag cargo computed and
records its value; post_process_executable applies it with rust-objcopy
after asset extraction. Fixes #5119
@nicoburns nicoburns self-assigned this Aug 5, 2026
@staging-devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed to build was app. wasm-opt failed with status code 6

1 participant