7

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

是否可以使用 Cargo 执行此操作?Cargo 似乎将顶级配置文件传播到依赖项,因此它们都被编译为发布或调试,具体取决于主 crate 的请求。

4

1 回答 1

3

从 Rust 1.41 开始,这可以通过overrides实现:

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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[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.package."*"]
opt-level = 2

省略了一些细节的输出:

$ cargo build --verbose

   Compiling image v0.23.0
     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 [...] --crate-name speedy [...] -C debuginfo=2 [...]`
于 2015-07-07T14:38:01.643 回答