Skip to content

Commit 120c9fc

Browse files
committed
Disambiguate between rustc vs std having debug assertions
Additionally, `NO_DEBUG_ASSERTIONS` is set by CI that threads through to the `./configure` script, which is somewhat fragile and "spooky action at a distance". Instead, use env vars controlled by compiletest, whose debug assertion info comes from bootstrap.
1 parent 855e0fe commit 120c9fc

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/tools/compiletest/src/runtest/run_make.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ impl TestCx<'_> {
225225
cmd.env("RUNNER", runner);
226226
}
227227

228+
// Guard against externally-set env vars.
229+
cmd.env_remove("__RUSTC_DEBUG_ASSERTIONS_ENABLED");
230+
if self.config.with_rustc_debug_assertions {
231+
// Used for `run_make_support::env::rustc_debug_assertions_enabled`.
232+
cmd.env("__RUSTC_DEBUG_ASSERTIONS_ENABLED", "1");
233+
}
234+
235+
cmd.env_remove("__STD_DEBUG_ASSERTIONS_ENABLED");
236+
if self.config.with_std_debug_assertions {
237+
// Used for `run_make_support::env::std_debug_assertions_enabled`.
238+
cmd.env("__STD_DEBUG_ASSERTIONS_ENABLED", "1");
239+
}
240+
228241
// We don't want RUSTFLAGS set from the outside to interfere with
229242
// compiler flags set in the test cases:
230243
cmd.env_remove("RUSTFLAGS");

src/tools/run-make-support/src/env.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ pub fn env_var_os(name: &str) -> OsString {
1818
}
1919
}
2020

21-
/// Check if `NO_DEBUG_ASSERTIONS` is set (usually this may be set in CI jobs).
21+
/// Check if staged `rustc`-under-test was built with debug assertions.
2222
#[track_caller]
2323
#[must_use]
24-
pub fn no_debug_assertions() -> bool {
25-
std::env::var_os("NO_DEBUG_ASSERTIONS").is_some()
24+
pub fn rustc_debug_assertions_enabled() -> bool {
25+
// Note: we assume this env var is set when the test recipe is being executed.
26+
std::env::var_os("__RUSTC_DEBUG_ASSERTIONS_ENABLED").is_some()
27+
}
28+
29+
/// Check if staged `std`-under-test was built with debug assertions.
30+
#[track_caller]
31+
#[must_use]
32+
pub fn std_debug_assertions_enabled() -> bool {
33+
// Note: we assume this env var is set when the test recipe is being executed.
34+
std::env::var_os("__STD_DEBUG_ASSERTIONS_ENABLED").is_some()
2635
}
2736

2837
/// A wrapper around [`std::env::set_current_dir`] which includes the directory

0 commit comments

Comments
 (0)