如何将 panic=abort 与外部依赖项一起使用?
How to use panic=abort with external dependencies?
对于单个 crate 项目,将这些行添加到 Cargo.toml
会按预期工作。
[profile.release]
panic = "abort"
然后构建项目:
cargo build --release
但是,在间接使用依赖项的项目上,我遇到了错误。
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`.
c_vec
crate 是间接使用的依赖项。
如何在没有冲突的多 crate 项目上使用 panic=abort
?
重要的细节:
- Rustc 1.12.0
- 有问题的库:lodepng-rust
- Linux, 64 位
看起来是因为 c_vec
将 dylib
指定为其库类型之一。
我在 Github 上发现这是一个问题: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.
当然,您必须创建自己的 lodepng
和 c_vec
来解决这个问题。
对于单个 crate 项目,将这些行添加到 Cargo.toml
会按预期工作。
[profile.release]
panic = "abort"
然后构建项目:
cargo build --release
但是,在间接使用依赖项的项目上,我遇到了错误。
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`.
c_vec
crate 是间接使用的依赖项。
如何在没有冲突的多 crate 项目上使用 panic=abort
?
重要的细节:
- Rustc 1.12.0
- 有问题的库:lodepng-rust
- Linux, 64 位
看起来是因为 c_vec
将 dylib
指定为其库类型之一。
我在 Github 上发现这是一个问题: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.
当然,您必须创建自己的 lodepng
和 c_vec
来解决这个问题。