我可以只为没有包的代码包含调试信息吗?

Can I include debug information only for my code without packages?

包含调试信息后,我的二进制文件变成了 400 MB 左右。发生这种情况是因为 Rust 包含所有依赖项的调试信息。有什么方法可以只为我的代码包含调试信息吗?

[package]
name = "app"
version = "0.7.1"
edition = "2018"

[dependencies]
actix = "*"
actix-web = {version = "1.0", features = ["ssl"]}
...
tokio-core = "*"
tokio = "*"

[profile.release]
debug = true

编辑:此功能现已稳定,无需 cargo-features 清单密钥即可在稳定的工具链上使用。此功能记录在案 in the Cargo reference


如果您愿意通过夜间工具链使用不稳定的货物功能,这可以通过 cargo profile dependencies 功能实现,如下所示:

cargo-features = ["profile-overrides"]

[package]
name = "app"
version = "0.7.1"
edition = "2018"

[dependencies]
actix = "*"
actix-web = {version = "1.0", features = ["ssl"]}
...
tokio-core = "*"
tokio = "*"

[profile.release]
debug = true

// disable debug symbols for all packages except this one
[profile.release.package."*"]
debug = false