How to access current cargo profile (debug/release, …) from the build script (build.rs)

五迷三道 提交于 2020-01-04 05:21:13

问题


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)


回答1:


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" => (),
        _ => (),
    }
}


来源:https://stackoverflow.com/questions/57296104/how-to-access-current-cargo-profile-debug-release-from-the-build-script-bu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!