Cargo 是否支持自定义配置文件?
Does Cargo support custom profiles?
我经常想用 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 没用。
Does Cargo support custom profiles?
不,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
自 Rust v1.57.0 起,自定义配置文件现已稳定。
添加配置文件部分,指定要继承的基本配置文件,并根据需要进行调整:
[profile.production]
inherits = "release"
lto = true
通过 --profile <name>
标志指定要使用的配置文件。
我经常想用 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 没用。
Does Cargo support custom profiles?
不,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
自 Rust v1.57.0 起,自定义配置文件现已稳定。
添加配置文件部分,指定要继承的基本配置文件,并根据需要进行调整:
[profile.production]
inherits = "release"
lto = true
通过 --profile <name>
标志指定要使用的配置文件。