Skip to content

Commit e138a07

Browse files
authored
Rollup merge of rust-lang#143782 - jieyouxu:debug-assertions, r=ChrisDenton
Disambiguate between rustc vs std having debug assertions in `run-make-support` and `run-make` tests `NO_DEBUG_ASSERTIONS` is set by CI that threads through to the `./configure.py` script, which is somewhat fragile and "spooky action at a distance". For `fmt-write-bloat`, this is actually wrong because the test wants to gate on *std* being built with debug assertions or not, whereas `NO_DEBUG_ASSERTIONS` determines *rustc* being built with debug assertions or not. Instead, use env vars controlled by compiletest, whose debug assertion info comes from bootstrap. https://github.com/rust-lang/rust/blob/855e0fe46e68d94e9f6147531b75ac2d488c548e/src/ci/run.sh#L137-L146 `NO_DEBUG_ASSERTIONS` controls `--enable-debug-assertions` https://github.com/rust-lang/rust/blob/855e0fe46e68d94e9f6147531b75ac2d488c548e/src/bootstrap/configure.py#L124 which sets `--rust.debug-assertions`, which controls *rustc* debug assertions. https://github.com/rust-lang/rust/blob/855e0fe46e68d94e9f6147531b75ac2d488c548e/src/bootstrap/configure.py#L125-L129 `--rust.debug-assertions-std` controls *std* debug assertions. Noticed while investigating `fmt-write-bloat` in rust-lang#143669 (comment). Best reviewed commit-by-commit. r? `@ChrisDenton` (or compiler/bootstrap)
2 parents 47f1ddc + 33e6962 commit e138a07

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
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

tests/run-make/fmt-write-bloat/rmake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
//@ ignore-cross-compile
1919

2020
use run_make_support::artifact_names::bin_name;
21-
use run_make_support::env::no_debug_assertions;
21+
use run_make_support::env::std_debug_assertions_enabled;
2222
use run_make_support::rustc;
2323
use run_make_support::symbols::any_symbol_contains;
2424

2525
fn main() {
2626
rustc().input("main.rs").opt().run();
2727
// panic machinery identifiers, these should not appear in the final binary
2828
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
29-
if no_debug_assertions() {
29+
if std_debug_assertions_enabled() {
3030
// if debug assertions are allowed, we need to allow these,
3131
// otherwise, add them to the list of symbols to deny.
3232
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);

0 commit comments

Comments
 (0)