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

8

我经常想以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

我已经阅读了文档,但仍然没有找到答案。


3
您可以创建一个自定义的 Cargo.toml 文件,并像这样使用它:cargo build --manifest-path ./Cargo-custom.toml。但是,这需要您在两个文件中都指定依赖项。 - wimh
2个回答

9

截至Rust v1.57.0自定义配置项特性已经稳定了。

添加一个配置项部分,指定一个基本配置项继承,并根据需要进行调整:

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

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


2

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

不支持。稳定版本的Cargo不支持自定义配置文件,此功能只在不稳定的夜间版本中开放。

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

cargo-features = ["named-profiles"]

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

然后使用它们:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接