Skip to content

Disambiguate between rustc vs std having debug assertions in run-make-support and run-make tests #143782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/tools/compiletest/src/runtest/run_make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ impl TestCx<'_> {
cmd.env("RUNNER", runner);
}

// Guard against externally-set env vars.
cmd.env_remove("__RUSTC_DEBUG_ASSERTIONS_ENABLED");
if self.config.with_rustc_debug_assertions {
// Used for `run_make_support::env::rustc_debug_assertions_enabled`.
cmd.env("__RUSTC_DEBUG_ASSERTIONS_ENABLED", "1");
}

cmd.env_remove("__STD_DEBUG_ASSERTIONS_ENABLED");
if self.config.with_std_debug_assertions {
// Used for `run_make_support::env::std_debug_assertions_enabled`.
cmd.env("__STD_DEBUG_ASSERTIONS_ENABLED", "1");
}

// We don't want RUSTFLAGS set from the outside to interfere with
// compiler flags set in the test cases:
cmd.env_remove("RUSTFLAGS");
Expand Down
15 changes: 12 additions & 3 deletions src/tools/run-make-support/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ pub fn env_var_os(name: &str) -> OsString {
}
}

/// Check if `NO_DEBUG_ASSERTIONS` is set (usually this may be set in CI jobs).
/// Check if staged `rustc`-under-test was built with debug assertions.
#[track_caller]
#[must_use]
pub fn no_debug_assertions() -> bool {
std::env::var_os("NO_DEBUG_ASSERTIONS").is_some()
pub fn rustc_debug_assertions_enabled() -> bool {
// Note: we assume this env var is set when the test recipe is being executed.
std::env::var_os("__RUSTC_DEBUG_ASSERTIONS_ENABLED").is_some()
}

/// Check if staged `std`-under-test was built with debug assertions.
#[track_caller]
#[must_use]
pub fn std_debug_assertions_enabled() -> bool {
// Note: we assume this env var is set when the test recipe is being executed.
std::env::var_os("__STD_DEBUG_ASSERTIONS_ENABLED").is_some()
}

/// A wrapper around [`std::env::set_current_dir`] which includes the directory
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/fmt-write-bloat/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
//@ ignore-cross-compile

use run_make_support::artifact_names::bin_name;
use run_make_support::env::no_debug_assertions;
use run_make_support::env::std_debug_assertions_enabled;
use run_make_support::rustc;
use run_make_support::symbols::any_symbol_contains;

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