Skip to content

Commit a9cdb78

Browse files
committed
Introduce proper bootstrap build.compiletest-allow-stage0 config
Instead of the ad-hoc `COMPILETEST_FORCE_STAGE0` env var. This config is intended to allow `compiletest` self-tests and `compiletest`-managed test suites to run against a stage 0 rustc, which is *usually* not a supported use case. It's intended only for the case where the stage 0 rustc is actually built from in-tree sources.
1 parent 919c409 commit a9cdb78

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

bootstrap.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,11 @@
465465
# What custom diff tool to use for displaying compiletest tests.
466466
#build.compiletest-diff-tool = <none>
467467

468+
# Whether to allow `compiletest` self-tests and `compiletest`-managed test
469+
# suites to be run against the stage 0 rustc. This is only intended to be used
470+
# when the stage 0 compiler is actually built from in-tree sources.
471+
#build.compiletest-allow-stage0 = false
472+
468473
# Whether to use the precompiled stage0 libtest with compiletest.
469474
#build.compiletest-use-stage0-libtest = true
470475

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,15 @@ impl Step for CompiletestTest {
715715
/// Runs `cargo test` for compiletest.
716716
fn run(self, builder: &Builder<'_>) {
717717
let host = self.host;
718+
719+
if builder.top_stage == 0 && !builder.config.compiletest_allow_stage0 {
720+
eprintln!("\
721+
ERROR: `--stage 0` runs compiletest self-tests against the stage0 (precompiled) compiler, not the in-tree compiler, and will almost always cause tests to fail
722+
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`."
723+
);
724+
crate::exit!(1);
725+
}
726+
718727
let compiler = builder.compiler(builder.top_stage, host);
719728

720729
// We need `ToolStd` for the locally-built sysroot because
@@ -723,8 +732,8 @@ impl Step for CompiletestTest {
723732
let mut cargo = tool::prepare_tool_cargo(
724733
builder,
725734
compiler,
726-
// compiletest uses libtest internals; make it use the in-tree std to make sure it never breaks
727-
// when std sources change.
735+
// compiletest uses libtest internals; make it use the in-tree std to make sure it never
736+
// breaks when std sources change.
728737
Mode::ToolStd,
729738
host,
730739
Kind::Test,
@@ -1612,12 +1621,11 @@ impl Step for Compiletest {
16121621
return;
16131622
}
16141623

1615-
if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1624+
if builder.top_stage == 0 && !builder.config.compiletest_allow_stage0 {
16161625
eprintln!("\
16171626
ERROR: `--stage 0` runs compiletest on the stage0 (precompiled) compiler, not your local changes, and will almost always cause tests to fail
1618-
HELP: to test the compiler, use `--stage 1` instead
1619-
HELP: to test the standard library, use `--stage 0 library/std` instead
1620-
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`."
1627+
HELP: to test the compiler or standard library, omit the stage or explicitly use `--stage 1` instead
1628+
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-force-stage0=true`."
16211629
);
16221630
crate::exit!(1);
16231631
}

src/bootstrap/src/core/config/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,16 @@ pub struct Config {
298298
/// Command for visual diff display, e.g. `diff-tool --color=always`.
299299
pub compiletest_diff_tool: Option<String>,
300300

301+
/// Whether to force bootstrap to run both `compiletest` self-tests and `compiletest`-managed
302+
/// test suites against the stage 0 (rustc, std).
303+
///
304+
/// This is only intended to be used when the stage 0 compiler is actually built from in-tree
305+
/// sources.
306+
pub compiletest_allow_stage0: bool,
307+
301308
/// Whether to use the precompiled stage0 libtest with compiletest.
302309
pub compiletest_use_stage0_libtest: bool,
310+
303311
/// Default value for `--extra-checks`
304312
pub tidy_extra_checks: Option<String>,
305313
pub is_running_on_ci: bool,
@@ -749,6 +757,7 @@ impl Config {
749757
optimized_compiler_builtins,
750758
jobs,
751759
compiletest_diff_tool,
760+
compiletest_allow_stage0,
752761
compiletest_use_stage0_libtest,
753762
tidy_extra_checks,
754763
ccache,
@@ -1020,8 +1029,12 @@ impl Config {
10201029

10211030
config.optimized_compiler_builtins =
10221031
optimized_compiler_builtins.unwrap_or(config.channel != "dev");
1032+
10231033
config.compiletest_diff_tool = compiletest_diff_tool;
1034+
1035+
config.compiletest_allow_stage0 = compiletest_allow_stage0.unwrap_or(false);
10241036
config.compiletest_use_stage0_libtest = compiletest_use_stage0_libtest.unwrap_or(true);
1037+
10251038
config.tidy_extra_checks = tidy_extra_checks;
10261039

10271040
let download_rustc = config.download_rustc_commit.is_some();

src/bootstrap/src/core/config/toml/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ define_config! {
6868
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
6969
jobs: Option<u32> = "jobs",
7070
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
71+
compiletest_allow_stage0: Option<bool> = "compiletest-allow-stage0",
7172
compiletest_use_stage0_libtest: Option<bool> = "compiletest-use-stage0-libtest",
7273
tidy_extra_checks: Option<String> = "tidy-extra-checks",
7374
ccache: Option<StringOrBool> = "ccache",

0 commit comments

Comments
 (0)