【问题标题】:Linking to optimised crate from a debug build从调试版本链接到优化的 crate
【发布时间】:2020-02-18 10:25:07
【问题描述】:

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

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

【问题讨论】:

  • 当面对不灵活的构建系统时,我已经欺骗并用符号链接替换了 Debug 构建版本...在我们等待完整答案时可能会让您继续前进 :)
  • 你能告诉我你做了什么吗?未优化的 crates 似乎不喜欢与优化的 crates 交谈。
  • 说实话,我从来没有在 Rust 中只在 C++ 中使用过它(部分原因是它只是一个评论);可能是因为 Rust 库中使用的哈希考虑了优化级别,在这种情况下,我很抱歉让你误入歧途。
  • OK 已修复,我设法使用 FFI 链接到 cargo 不需要(不需要)知道的快速动态库来实现这一点。

标签: rust rust-cargo


【解决方案1】:

从 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 [...]`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-25
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    相关资源
    最近更新 更多