For single crate projects, adding these lines to Cargo.toml
works as expected.
[profile.release]
panic = "abort"
Then build the project:
cargo build --release
However, on a project which has indirectly used dependencies, I'm getting an error.
Compiling c_vec v1.0.12
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
error: Could not compile `c_vec`.
The c_vec
crate is an indirectly used dependency.
How to use panic=abort
on a multi-crate project without conflicts?
Details incase they matter:
Looks like it's because c_vec
specifies dylib
as one of its library types.
I found this as an issue on Github here: https://github.com/rust-lang/cargo/issues/2738
ah unfortunately that's a bad error message but it's because of crate-type = ["dylib", "rlib"] in the c_vec crate. This causes Cargo to pass -C prefer-dynamic which links to the dylib that we ship which is compiled against panic_unwind, meaning the abort mode is indeed invalid (this error is coming from the compiler).
The fix here would be to remove "dylib" from the c_vec crate.
Of course, you'd have to fork your own lodepng
and c_vec
to take care of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With