Introduce proper build.compiletest-allow-stage0 config option

In favor of the adhoc `COMPILETEST_FORCE_STAGE0` env var.
This commit is contained in:
Jieyou Xu 2025-07-30 19:54:16 +08:00
parent 919c409243
commit 0cf6eb5f75
No known key found for this signature in database
GPG key ID: 045B995028EA6AFC
4 changed files with 24 additions and 6 deletions

View file

@ -465,6 +465,11 @@
# What custom diff tool to use for displaying compiletest tests.
#build.compiletest-diff-tool = <none>
# Whether to allow `compiletest` self-tests and `compiletest`-managed test
# suites to be run against the stage 0 rustc. This is only intended to be used
# when the stage 0 compiler is actually built from in-tree sources.
#build.compiletest-allow-stage0 = false
# Whether to use the precompiled stage0 libtest with compiletest.
#build.compiletest-use-stage0-libtest = true

View file

@ -723,8 +723,8 @@ impl Step for CompiletestTest {
let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
// compiletest uses libtest internals; make it use the in-tree std to make sure it never breaks
// when std sources change.
// compiletest uses libtest internals; make it use the in-tree std to make sure it never
// breaks when std sources change.
Mode::ToolStd,
host,
Kind::Test,
@ -1612,12 +1612,11 @@ impl Step for Compiletest {
return;
}
if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
if builder.top_stage == 0 && !builder.config.compiletest_allow_stage0 {
eprintln!("\
ERROR: `--stage 0` runs compiletest on the stage0 (precompiled) compiler, not your local changes, and will almost always cause tests to fail
HELP: to test the compiler, use `--stage 1` instead
HELP: to test the standard library, use `--stage 0 library/std` instead
NOTE: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `COMPILETEST_FORCE_STAGE0=1`."
HELP: to test the compiler or standard library, omit the stage or explicitly use `--stage 1` instead
NOTE: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `--set build.compiletest-allow-stage0=true`."
);
crate::exit!(1);
}

View file

@ -298,8 +298,16 @@ pub struct Config {
/// Command for visual diff display, e.g. `diff-tool --color=always`.
pub compiletest_diff_tool: Option<String>,
/// Whether to allow running both `compiletest` self-tests and `compiletest`-managed test suites
/// against the stage 0 (rustc, std).
///
/// This is only intended to be used when the stage 0 compiler is actually built from in-tree
/// sources.
pub compiletest_allow_stage0: bool,
/// Whether to use the precompiled stage0 libtest with compiletest.
pub compiletest_use_stage0_libtest: bool,
/// Default value for `--extra-checks`
pub tidy_extra_checks: Option<String>,
pub is_running_on_ci: bool,
@ -749,6 +757,7 @@ impl Config {
optimized_compiler_builtins,
jobs,
compiletest_diff_tool,
compiletest_allow_stage0,
compiletest_use_stage0_libtest,
tidy_extra_checks,
ccache,
@ -1020,8 +1029,12 @@ impl Config {
config.optimized_compiler_builtins =
optimized_compiler_builtins.unwrap_or(config.channel != "dev");
config.compiletest_diff_tool = compiletest_diff_tool;
config.compiletest_allow_stage0 = compiletest_allow_stage0.unwrap_or(false);
config.compiletest_use_stage0_libtest = compiletest_use_stage0_libtest.unwrap_or(true);
config.tidy_extra_checks = tidy_extra_checks;
let download_rustc = config.download_rustc_commit.is_some();

View file

@ -68,6 +68,7 @@ define_config! {
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
jobs: Option<u32> = "jobs",
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
compiletest_allow_stage0: Option<bool> = "compiletest-allow-stage0",
compiletest_use_stage0_libtest: Option<bool> = "compiletest-use-stage0-libtest",
tidy_extra_checks: Option<String> = "tidy-extra-checks",
ccache: Option<StringOrBool> = "ccache",