Skip to content

Commit

Permalink
Auto merge of #5448 - ehuss:debug_env, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix "DEBUG" env var in build.rs for debug=0

Fixes #5370
  • Loading branch information
bors committed May 1, 2018
2 parents 0d377b6 + 83b8c23 commit f2abbe8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
// carried over.
let to_exec = to_exec.into_os_string();
let mut cmd = cx.compilation.host_process(to_exec, unit.pkg)?;
let debug = unit.profile.debuginfo.unwrap_or(0) != 0;
cmd.env("OUT_DIR", &build_output)
.env("CARGO_MANIFEST_DIR", unit.pkg.root())
.env("NUM_JOBS", &cx.jobs().to_string())
Expand All @@ -133,7 +134,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
Kind::Target => cx.build_config.target_triple(),
},
)
.env("DEBUG", &unit.profile.debuginfo.is_some().to_string())
.env("DEBUG", debug.to_string())
.env("OPT_LEVEL", &unit.profile.opt_level.to_string())
.env(
"PROFILE",
Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,37 @@ fn profile_and_opt_level_set_correctly() {
assert_that(build.cargo("bench"), execs().with_status(0));
}

#[test]
fn profile_debug_0() {
let p = project("foo")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[profile.dev]
debug = 0
"#,
)
.file("src/lib.rs", "")
.file(
"build.rs",
r#"
use std::env;
fn main() {
assert_eq!(env::var("OPT_LEVEL").unwrap(), "0");
assert_eq!(env::var("PROFILE").unwrap(), "debug");
assert_eq!(env::var("DEBUG").unwrap(), "false");
}
"#,
)
.build();
assert_that(p.cargo("build"), execs().with_status(0));
}

#[test]
fn build_script_with_lto() {
let build = project("builder")
Expand Down

0 comments on commit f2abbe8

Please sign in to comment.