【问题标题】:Does Cargo support custom profiles?Cargo 是否支持自定义配置文件?
【发布时间】:2017-06-14 16:23:07
【问题描述】:

我经常想用debug = true 在发布模式下编译,这样我可以更轻松地阅读生成的程序集。我目前正在这样做:

[profile.release]
debug = true

但我不希望在我的最终发布版本中有任何调试符号。我想做类似的事情:

[profile.custom]
debug = true
opt-level = 3
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'unwind'

然后运行

cargo build --custom

我已阅读the documentation 无济于事。

【问题讨论】:

  • 您可以创建一个自定义 Cargo.toml 并像这样使用它:cargo build --manifest-path ./Cargo-custom.toml。但它要求您在两个文件中指定依赖项。

标签: rust rust-cargo


【解决方案1】:

Cargo 是否支持自定义配置文件?

不,Cargo 的稳定版本不支持此功能。它可以通过unstable nightly feature 获得。

如果您使用夜间版本的 Cargo,您可以在 Cargo.toml 中创建自定义配置文件:

cargo-features = ["named-profiles"]

[profile.release-lto]
inherits = "release"
lto = true

然后使用它们:

cargo +nightly build --profile release-lto -Z unstable-options

【讨论】:

    【解决方案2】:

    截至Rust v1.57.0,自定义配置文件现已稳定。

    添加配置文件部分,指定要继承的基本配置文件,并根据需要选择柚木:

    [profile.production]
    inherits = "release"
    lto = true
    

    通过 --profile <name> 标志指定要使用的配置文件到货物。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多