问题
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