]> git.proxmox.com Git - cargo.git/commitdiff
Fix "DEBUG" env var in build.rs for debug=0.
authorEric Huss <eric@huss.org>
Mon, 30 Apr 2018 17:17:43 +0000 (10:17 -0700)
committerEric Huss <eric@huss.org>
Mon, 30 Apr 2018 17:17:43 +0000 (10:17 -0700)
Fixes #5370

src/cargo/core/compiler/custom_build.rs
tests/testsuite/build_script.rs

index ff28c0e065a9201a335723ad99496c48138c6246..59cb9b81aee46fb26563e1d91db2a8e6f8c29ea6 100644 (file)
@@ -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())
@@ -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",
index eb444f25450416f75f46572512aa4a967b166ea7..ec68f6cd6179e088c02425ab28e48592eb6d674c 100644 (file)
@@ -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")