Issues with panic_unwind and panic_immediate_abort using Cargo 1.85.0-nightly

Hi everyone!

I'm working on a WebAssembly project with Rust 1.85.0-nightly (769f622e1 2024-12-14) and running into some issues with panic settings. I'm trying to reduce binary size by using panic_immediate_abort with panic_abort.

Problem: When I try to set it up, I get this error:

error: package ID specification `panic_unwind` did not match any packages

Build Command:

This completes without an error:

cargo +nightly build --target wasm32-wasip1 --release -Z build-std=std,panic_abort

This doesn't:

cargo +nightly build --target wasm32-wasip1 --release -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort

The only difference is -Z build-std-features=panic_immediate_abort. I thought the panic_immediate_abort would stop any unwinding, so I'm not sure why it's looking for panic_unwind.

Here’s What I’m Using:

  • Rust Version: 1.85.0-nightly (769f622e1 2024-12-14)
  • RUSTFLAGS: -Zlocation-detail=none -C strip=none

I am able to build this on 1.84.0-nightly, so the issue likely lies with this release.

Questions:

  1. How do I set up panic_immediate_abort and panic_abort to stop unwinding for WASM?
  2. Are there known issues with these flags for WebAssembly in Rust Nightly?
  3. Could my settings in RUSTFLAGS be causing this error? What should I change?

Thanks for any help you can provide!

panic_abort should be sufficient on its own to stop unwinding. All it leaves behind is the error printing.

For wasm panic=abort is already the default. And printing the panic message bloats the binary significantly less than for native targets as wasm doesn't allow getting backtraces, and thus we don't need all the code to print and symbolize backtraces on wasm. panic_immediate_abort would save maybe 10-20kb (just a wild guess) when using wasm, while for native targets it is closer to 400-500kb saving.