Skip to content

Commit f2abbe8

Browse files
committed
Auto merge of #5448 - ehuss:debug_env, r=alexcrichton
Fix "DEBUG" env var in build.rs for debug=0 Fixes #5370
2 parents 0d377b6 + 83b8c23 commit f2abbe8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
123123
// carried over.
124124
let to_exec = to_exec.into_os_string();
125125
let mut cmd = cx.compilation.host_process(to_exec, unit.pkg)?;
126+
let debug = unit.profile.debuginfo.unwrap_or(0) != 0;
126127
cmd.env("OUT_DIR", &build_output)
127128
.env("CARGO_MANIFEST_DIR", unit.pkg.root())
128129
.env("NUM_JOBS", &cx.jobs().to_string())
@@ -133,7 +134,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
133134
Kind::Target => cx.build_config.target_triple(),
134135
},
135136
)
136-
.env("DEBUG", &unit.profile.debuginfo.is_some().to_string())
137+
.env("DEBUG", debug.to_string())
137138
.env("OPT_LEVEL", &unit.profile.opt_level.to_string())
138139
.env(
139140
"PROFILE",

tests/testsuite/build_script.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,37 @@ fn profile_and_opt_level_set_correctly() {
17021702
assert_that(build.cargo("bench"), execs().with_status(0));
17031703
}
17041704

1705+
#[test]
1706+
fn profile_debug_0() {
1707+
let p = project("foo")
1708+
.file(
1709+
"Cargo.toml",
1710+
r#"
1711+
[package]
1712+
name = "foo"
1713+
version = "0.0.1"
1714+
1715+
[profile.dev]
1716+
debug = 0
1717+
"#,
1718+
)
1719+
.file("src/lib.rs", "")
1720+
.file(
1721+
"build.rs",
1722+
r#"
1723+
use std::env;
1724+
1725+
fn main() {
1726+
assert_eq!(env::var("OPT_LEVEL").unwrap(), "0");
1727+
assert_eq!(env::var("PROFILE").unwrap(), "debug");
1728+
assert_eq!(env::var("DEBUG").unwrap(), "false");
1729+
}
1730+
"#,
1731+
)
1732+
.build();
1733+
assert_that(p.cargo("build"), execs().with_status(0));
1734+
}
1735+
17051736
#[test]
17061737
fn build_script_with_lto() {
17071738
let build = project("builder")

0 commit comments

Comments
 (0)