Skip to content

Commit e99d11b

Browse files
authored
Unrolled build for #144675
Rollup merge of #144675 - jieyouxu:compiletest-staging, r=Kobzol Reject running `compiletest` self-tests against stage 0 rustc unless explicitly allowed Currently, in `pr-check-1`, we run `python3 ../x.py test --stage 0 src/tools/compiletest`, which is `compiletest` self-tests against stage 0 rustc. This makes it very annoying for PRs wanting to change target spec JSON format, which `compiletest` depends on for target information, as otherwise `compiletest` would have to know how to handle 2 different target spec JSON formats and know when to pick which. Instead of doing that, we change `compiletest` self-tests to reject running against stage 0 `rustc` *unless* explicitly allowed with `build.compiletest-allow-stage0=true`. `build.compiletest-allow-stage0` is a proper bootstrap config option in favor of the ad-hoc `COMPILETEST_FORCE_STAGE0` env var. This means that: - `./x test src/tools/compiletest --stage=0` is not allowed, unless `build.compiletest-allow-stage0=true` is set. In this scenario, `compiletest` self-tests should be expected to fail unless the stage 0 `rustc` as provided is like codegen_cranelift where it's *actually* built from in-tree `rustc` sources. - In CI, we change `./x test src/tools/compiletest --stage=0` to `./x test src/tools/compiletest --stage=1`, and move it to `pr-check-2`. Yes, this involves building the stage 1 compiler, but `pr-check-2` already has to build stage 1 compiler to test stage 1 library crates. - Crucially, this means that **`compiletest` is only intended to support one target spec JSON format**, namely the one corresponding to the in-tree `rustc`. - This should preserve the `compiletest-use-stage0-libtest` UX optimization where changing `compiler/` tree should still not require rebuilding `compiletest` as long as `build.compiletest-use-stage0-libtest=true`, as that should remain orthogonal. This is completely unlike my previous attempt at #144563 that tries to do a way more invasive change which would cause the rebuild problem. Best reviewed commit-by-commit. --- r? `@Kobzol`
2 parents e5e79f8 + e954253 commit e99d11b

File tree

11 files changed

+56
-14
lines changed

11 files changed

+56
-14
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

compiler/rustc_codegen_cranelift/scripts/setup_rust_fork.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ rustc = "$(pwd)/../dist/bin/rustc-clif"
3333
cargo = "$(rustup which cargo)"
3434
full-bootstrap = true
3535
local-rebuild = true
36+
compiletest-allow-stage0 = true
3637
3738
[rust]
3839
download-rustc = false

compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,5 @@ index 073116933bd..c3e4578204d 100644
166166
EOF
167167

168168
echo "[TEST] rustc test suite"
169-
COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 --test-args=--no-capture tests/{codegen-units,run-make,ui,incremental}
169+
./x.py test --stage 0 --test-args=--no-capture tests/{codegen-units,run-make,ui,incremental}
170170
popd

compiler/rustc_codegen_gcc/build_system/src/test.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
561561
// FIXME: create a function "display_if_not_quiet" or something along the line.
562562
println!("[TEST] rustc asm test suite");
563563

564-
env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
565-
566564
let codegen_backend_path = format!(
567565
"{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}",
568566
pwd = std::env::current_dir()
@@ -588,6 +586,8 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
588586
&"always",
589587
&"--stage",
590588
&"0",
589+
&"--set",
590+
&"build.compiletest-allow-stage0=true",
591591
&"tests/assembly-llvm/asm",
592592
&"--compiletest-rustc-args",
593593
&rustc_args,
@@ -1047,7 +1047,6 @@ where
10471047

10481048
// FIXME: create a function "display_if_not_quiet" or something along the line.
10491049
println!("[TEST] rustc {test_type} test suite");
1050-
env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
10511050

10521051
let extra =
10531052
if args.is_using_gcc_master_branch() { "" } else { " -Csymbol-mangling-version=v0" };
@@ -1070,6 +1069,8 @@ where
10701069
&"always",
10711070
&"--stage",
10721071
&"0",
1072+
&"--set",
1073+
&"build.compiletest-allow-stage0=true",
10731074
&format!("tests/{test_type}"),
10741075
&"--compiletest-rustc-args",
10751076
&rustc_args,

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use std::ffi::{OsStr, OsString};
88
use std::path::{Path, PathBuf};
99
use std::{env, fs, iter};
1010

11+
#[cfg(feature = "tracing")]
12+
use tracing::instrument;
13+
1114
use crate::core::build_steps::compile::{Std, run_cargo};
1215
use crate::core::build_steps::doc::DocumentationFormat;
1316
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
@@ -30,7 +33,7 @@ use crate::utils::helpers::{
3033
linker_flags, t, target_supports_cranelift_backend, up_to_date,
3134
};
3235
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
33-
use crate::{CLang, DocTests, GitRepo, Mode, PathSet, envify};
36+
use crate::{CLang, DocTests, GitRepo, Mode, PathSet, debug, envify};
3437

3538
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
3639

@@ -713,18 +716,32 @@ impl Step for CompiletestTest {
713716
}
714717

715718
/// Runs `cargo test` for compiletest.
719+
#[cfg_attr(
720+
feature = "tracing",
721+
instrument(level = "debug", name = "CompiletestTest::run", skip_all)
722+
)]
716723
fn run(self, builder: &Builder<'_>) {
717724
let host = self.host;
725+
726+
if builder.top_stage == 0 && !builder.config.compiletest_allow_stage0 {
727+
eprintln!("\
728+
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
729+
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`."
730+
);
731+
crate::exit!(1);
732+
}
733+
718734
let compiler = builder.compiler(builder.top_stage, host);
735+
debug!(?compiler);
719736

720737
// We need `ToolStd` for the locally-built sysroot because
721738
// compiletest uses unstable features of the `test` crate.
722739
builder.std(compiler, host);
723740
let mut cargo = tool::prepare_tool_cargo(
724741
builder,
725742
compiler,
726-
// compiletest uses libtest internals; make it use the in-tree std to make sure it never breaks
727-
// when std sources change.
743+
// compiletest uses libtest internals; make it use the in-tree std to make sure it never
744+
// breaks when std sources change.
728745
Mode::ToolStd,
729746
host,
730747
Kind::Test,
@@ -1612,12 +1629,11 @@ impl Step for Compiletest {
16121629
return;
16131630
}
16141631

1615-
if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1632+
if builder.top_stage == 0 && !builder.config.compiletest_allow_stage0 {
16161633
eprintln!("\
16171634
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`."
1635+
HELP: to test the compiler or standard library, omit the stage or explicitly use `--stage 1` instead
1636+
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`."
16211637
);
16221638
crate::exit!(1);
16231639
}

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 allow running both `compiletest` self-tests and `compiletest`-managed test suites
302+
/// 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",

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
486486
severity: ChangeSeverity::Warning,
487487
summary: "Removed `rust.description` and `llvm.ccache` as it was deprecated in #137723 and #136941 long time ago.",
488488
},
489+
ChangeInfo {
490+
change_id: 144675,
491+
severity: ChangeSeverity::Warning,
492+
summary: "Added `build.compiletest-allow-stage0` flag instead of `COMPILETEST_FORCE_STAGE0` env var, and reject running `compiletest` self tests against stage 0 rustc unless explicitly allowed.",
493+
},
489494
];

src/ci/docker/host-x86_64/pr-check-1/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ ENV SCRIPT \
4343
python3 ../x.py check bootstrap && \
4444
/scripts/check-default-config-profiles.sh && \
4545
python3 ../x.py build src/tools/build-manifest && \
46-
python3 ../x.py test --stage 0 src/tools/compiletest && \
4746
python3 ../x.py check compiletest --set build.compiletest-use-stage0-libtest=true && \
4847
python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
4948
python3 ../x.py check --set build.optimized-compiler-builtins=false core alloc std --target=aarch64-unknown-linux-gnu,i686-pc-windows-msvc,i686-unknown-linux-gnu,x86_64-apple-darwin,x86_64-pc-windows-gnu,x86_64-pc-windows-msvc && \

src/ci/docker/host-x86_64/pr-check-2/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ ENV SCRIPT \
3030
python3 ../x.py check && \
3131
python3 ../x.py clippy ci && \
3232
python3 ../x.py test --stage 1 core alloc std test proc_macro && \
33+
python3 ../x.py test --stage 1 src/tools/compiletest && \
3334
python3 ../x.py doc --stage 0 bootstrap && \
3435
# Build both public and internal documentation.
3536
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 0 compiler && \
3637
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 1 library && \
3738
mkdir -p /checkout/obj/staging/doc && \
3839
cp -r build/x86_64-unknown-linux-gnu/doc /checkout/obj/staging && \
3940
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 1 library/test && \
40-
# The BOOTSTRAP_TRACING flag is added to verify whether the
41+
# The BOOTSTRAP_TRACING flag is added to verify whether the
4142
# bootstrap process compiles successfully with this flag enabled.
4243
BOOTSTRAP_TRACING=1 python3 ../x.py --help

0 commit comments

Comments
 (0)