从调试版本链接到优化的包

时间:2015-07-07 05:28:46

标签: rust rust-cargo

我想将一些性能密集型代码分成一个.so(我正在运行Kubuntu Linux),而我的代码的主要数量是在调试模式下编译的。我希望在我的代码中获得更快的编译和运行时支持,但是运行少量密集代码并且包含所有调试检查是不可接受的。

使用Cargo可以做到这一点吗?似乎Cargo将顶级配置文件传播到依赖项,因此它们都被编译为发布或调试,具体取决于主仓的请求。

1 个答案:

答案 0 :(得分:2)

不使用稳定的货物。

有一个名为profile overrides的夜间货物功能可以实现此目的:

cargo-features = ["profile-overrides"]

[package]
name = "speedy"
version = "0.1.0"
authors = ["An Devloper <an.devloper@example.com>"]
edition = "2018"

[dependencies]
image = "0.21.1"

# All dependencies (but not this crate itself or any workspace member)
# will be compiled with -Copt-level=2 . This includes build dependencies.
[profile.dev.overrides."*"]
opt-level = 2

输出中包含一些细节:

$ cargo +nightly build --verbose

   Compiling image v0.21.1
     Running `rustc --crate-name image [...] -C opt-level=2 -C debuginfo=2 -C debug-assertions=on [...]
   Compiling speedy v0.1.0 (/private/tmp/speedy)
     Running `rustc --edition=2018 --crate-name speedy [...] -C debuginfo=2 [...]`
相关问题