在嵌入式项目中,我通常使用 qemu 运行调试模式,但需要为具体的微控制器构建版本。
build.rs 需要知道实际模式是什么(调试或发布)才能生成正确的内存布局。
build.rs 如何做出这个决定?
有关的:如何从构建脚本 (build.rs) 访问当前的货物配置文件(构建、测试、工作台、文档......) https://stackoverflow.com/questions/36446642/how-to-access-current-cargo-profile-build-test-bench-doc-from-the-bui
它写在doc https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts:
PROFILE
- "release"
对于发布版本,"debug"
对于其他构建。
这进入 build.rs:
fn main() {
let profile = std::env::var("PROFILE").unwrap();
match profile.as_str() {
"debug" => (),
"release" => (),
_ => (),
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)