如何从构建脚本(build.rs)访问当前货物档案(调试/发布等) [英] How to access current cargo profile (debug/release, …) from the build script (build.rs)

查看:156
本文介绍了如何从构建脚本(build.rs)访问当前货物档案(调试/发布等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在嵌入式项目中,我通常使用qemu运行调试模式,但需要为具体的微控制器构建发行版。



build.rs需要知道什么是实际模式(调试或释放)以生成正确的内存布局。



build.rs如何做出此决定?



相关:如何访问当前货物配置文件(构建,测试,工作台,文档,....)从构建脚本(build.rs)

解决方案

它是用文档


配置文件-发布 用于发布版本,调试 用于其他版本。




<前置类= lang-rust prettyprint-override> fn main(){
let profile = std :: env :: var( PROFILE)。unwrap();
match profile.as_str(){
debug => (),
发行 => (),
_ => (),
}
}


In an embedded project, I usually run the debug mode with qemu, but need to build the release for a concrete microcontroller.

The build.rs would need to know what the actual mode is (debug or release) to generate the correct memory layout.

How can the build.rs make this decision?

Related: How to access current cargo profile (build, test, bench, doc, ....) from the build script (build.rs)

解决方案

It's written in the doc:

PROFILE - "release" for release builds, "debug" for other builds.

fn main() {
    let profile = std::env::var("PROFILE").unwrap();
    match profile.as_str() {
        "debug" => (),
        "release" => (),
        _ => (),
    }
}

这篇关于如何从构建脚本(build.rs)访问当前货物档案(调试/发布等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆