Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use panic=abort with external dependencies?

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:

  • Rustc 1.12.0
  • Library with issue: lodepng-rust
  • Linux, 64bit
like image 836
ideasman42 Avatar asked Oct 04 '16 04:10

ideasman42


1 Answers

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.

like image 89
Linear Avatar answered Nov 12 '22 15:11

Linear