Skip to content

Commit 193f717

Browse files
committed
Build and test compiletest as a stage0 bootstrap tool
1 parent 7b8ae74 commit 193f717

File tree

9 files changed

+40
-64
lines changed

9 files changed

+40
-64
lines changed

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::core::build_steps::compile::{
88
};
99
use crate::core::build_steps::tool;
1010
use crate::core::build_steps::tool::{
11-
COMPILETEST_ALLOW_FEATURES, SourceType, TEST_FLOAT_PARSE_ALLOW_FEATURES, ToolTargetBuildMode,
12-
get_tool_target_compiler, prepare_tool_cargo,
11+
SourceType, TEST_FLOAT_PARSE_ALLOW_FEATURES, ToolTargetBuildMode, get_tool_target_compiler,
12+
prepare_tool_cargo,
1313
};
1414
use crate::core::builder::{
1515
self, Alias, Builder, Cargo, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
@@ -825,12 +825,7 @@ tool_check_step!(CoverageDump {
825825
// so this is mainly for people working on compiletest to run locally.
826826
tool_check_step!(Compiletest {
827827
path: "src/tools/compiletest",
828-
mode: |builder: &Builder<'_>| if builder.config.compiletest_use_stage0_libtest {
829-
Mode::ToolBootstrap
830-
} else {
831-
Mode::ToolStd
832-
},
833-
allow_features: COMPILETEST_ALLOW_FEATURES,
828+
mode: |_builder| Mode::ToolBootstrap,
834829
default: false,
835830
});
836831

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
1818
use crate::core::build_steps::run::get_completion_paths;
1919
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
2020
use crate::core::build_steps::tool::{
21-
self, COMPILETEST_ALLOW_FEATURES, RustcPrivateCompilers, SourceType,
22-
TEST_FLOAT_PARSE_ALLOW_FEATURES, Tool, ToolTargetBuildMode, get_tool_target_compiler,
21+
self, RustcPrivateCompilers, SourceType, TEST_FLOAT_PARSE_ALLOW_FEATURES, Tool,
22+
ToolTargetBuildMode, get_tool_target_compiler,
2323
};
2424
use crate::core::build_steps::toolstate::ToolState;
2525
use crate::core::build_steps::{compile, dist, llvm};
@@ -36,7 +36,7 @@ use crate::utils::helpers::{
3636
linker_args, linker_flags, t, target_supports_cranelift_backend, up_to_date,
3737
};
3838
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
39-
use crate::{CLang, CodegenBackendKind, DocTests, GitRepo, Mode, PathSet, debug, envify};
39+
use crate::{CLang, CodegenBackendKind, DocTests, GitRepo, Mode, PathSet, envify};
4040

4141
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
4242

@@ -786,26 +786,26 @@ impl Step for CompiletestTest {
786786
fn run(self, builder: &Builder<'_>) {
787787
let host = self.host;
788788

789+
// Now that compiletest uses only stable Rust, building it always uses
790+
// the stage 0 compiler. However, some of its unit tests need to be able
791+
// to query information from an in-tree compiler, so we treat `--stage`
792+
// as selecting the stage of that secondary compiler.
793+
789794
if builder.top_stage == 0 && !builder.config.compiletest_allow_stage0 {
790795
eprintln!("\
791-
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
796+
ERROR: `--stage 0` causes compiletest to query information from the stage0 (precompiled) compiler, instead of the in-tree compiler, which can cause some tests to fail inappropriately
792797
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`."
793798
);
794799
crate::exit!(1);
795800
}
796801

797-
let compiler = builder.compiler(builder.top_stage, host);
798-
debug!(?compiler);
802+
let bootstrap_compiler = builder.compiler(0, host);
803+
let staged_compiler = builder.compiler(builder.top_stage, host);
799804

800-
// We need `ToolStd` for the locally-built sysroot because
801-
// compiletest uses unstable features of the `test` crate.
802-
builder.std(compiler, host);
803805
let mut cargo = tool::prepare_tool_cargo(
804806
builder,
805-
compiler,
806-
// compiletest uses libtest internals; make it use the in-tree std to make sure it never
807-
// breaks when std sources change.
808-
Mode::ToolStd,
807+
bootstrap_compiler,
808+
Mode::ToolBootstrap,
809809
host,
810810
Kind::Test,
811811
"src/tools/compiletest",
@@ -816,9 +816,8 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
816816
// Used for `compiletest` self-tests to have the path to the *staged* compiler. Getting this
817817
// right is important, as `compiletest` is intended to only support one target spec JSON
818818
// format, namely that of the staged compiler.
819-
cargo.env("TEST_RUSTC", builder.rustc(compiler));
819+
cargo.env("TEST_RUSTC", builder.rustc(staged_compiler));
820820

821-
cargo.allow_features(COMPILETEST_ALLOW_FEATURES);
822821
run_cargo_test(cargo, &[], &[], "compiletest self test", host, builder);
823822
}
824823
}

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ macro_rules! bootstrap_tool {
380380
($(
381381
$name:ident, $path:expr, $tool_name:expr
382382
$(,is_external_tool = $external:expr)*
383-
$(,is_unstable_tool = $unstable:expr)*
384383
$(,allow_features = $allow_features:expr)?
385384
$(,submodules = $submodules:expr)?
386385
$(,artifact_kind = $artifact_kind:expr)?
@@ -438,19 +437,11 @@ macro_rules! bootstrap_tool {
438437
}
439438
)*
440439

441-
let is_unstable = false $(|| $unstable)*;
442-
let compiletest_wants_stage0 = $tool_name == "compiletest" && builder.config.compiletest_use_stage0_libtest;
443-
444440
builder.ensure(ToolBuild {
445441
build_compiler: self.compiler,
446442
target: self.target,
447443
tool: $tool_name,
448-
mode: if is_unstable && !compiletest_wants_stage0 {
449-
// use in-tree libraries for unstable features
450-
Mode::ToolStd
451-
} else {
452-
Mode::ToolBootstrap
453-
},
444+
mode: Mode::ToolBootstrap,
454445
path: $path,
455446
source_type: if false $(|| $external)* {
456447
SourceType::Submodule
@@ -483,8 +474,6 @@ macro_rules! bootstrap_tool {
483474
}
484475
}
485476

486-
pub(crate) const COMPILETEST_ALLOW_FEATURES: &str = "internal_output_capture";
487-
488477
bootstrap_tool!(
489478
// This is marked as an external tool because it includes dependencies
490479
// from submodules. Trying to keep the lints in sync between all the repos
@@ -495,7 +484,7 @@ bootstrap_tool!(
495484
Tidy, "src/tools/tidy", "tidy";
496485
Linkchecker, "src/tools/linkchecker", "linkchecker";
497486
CargoTest, "src/tools/cargotest", "cargotest";
498-
Compiletest, "src/tools/compiletest", "compiletest", is_unstable_tool = true, allow_features = COMPILETEST_ALLOW_FEATURES;
487+
Compiletest, "src/tools/compiletest", "compiletest";
499488
BuildManifest, "src/tools/build-manifest", "build-manifest";
500489
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
501490
RustInstaller, "src/tools/rust-installer", "rust-installer";
@@ -509,8 +498,7 @@ bootstrap_tool!(
509498
CollectLicenseMetadata, "src/tools/collect-license-metadata", "collect-license-metadata";
510499
GenerateCopyright, "src/tools/generate-copyright", "generate-copyright";
511500
GenerateWindowsSys, "src/tools/generate-windows-sys", "generate-windows-sys";
512-
// rustdoc-gui-test has a crate dependency on compiletest, so it needs the same unstable features.
513-
RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test", is_unstable_tool = true, allow_features = COMPILETEST_ALLOW_FEATURES;
501+
RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test";
514502
CoverageDump, "src/tools/coverage-dump", "coverage-dump";
515503
UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
516504
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";

src/bootstrap/src/core/builder/tests.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,21 +2004,6 @@ mod snapshot {
20042004
.render_steps(), @"[check] rustc 0 <host> -> Compiletest 1 <host>");
20052005
}
20062006

2007-
#[test]
2008-
fn check_compiletest_stage1_libtest() {
2009-
let ctx = TestCtx::new();
2010-
insta::assert_snapshot!(
2011-
ctx.config("check")
2012-
.path("compiletest")
2013-
.args(&["--set", "build.compiletest-use-stage0-libtest=false"])
2014-
.render_steps(), @r"
2015-
[build] llvm <host>
2016-
[build] rustc 0 <host> -> rustc 1 <host>
2017-
[build] rustc 1 <host> -> std 1 <host>
2018-
[check] rustc 1 <host> -> Compiletest 2 <host>
2019-
");
2020-
}
2021-
20222007
#[test]
20232008
fn check_codegen() {
20242009
let ctx = TestCtx::new();
@@ -2152,8 +2137,7 @@ mod snapshot {
21522137
insta::assert_snapshot!(steps, @r"
21532138
[build] llvm <host>
21542139
[build] rustc 0 <host> -> rustc 1 <host>
2155-
[build] rustc 1 <host> -> std 1 <host>
2156-
[build] rustdoc 1 <host>
2140+
[build] rustdoc 0 <host>
21572141
");
21582142
}
21592143

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,6 @@ pub struct Config {
310310
/// sources.
311311
pub compiletest_allow_stage0: bool,
312312

313-
/// Whether to use the precompiled stage0 libtest with compiletest.
314-
pub compiletest_use_stage0_libtest: bool,
315-
316313
/// Default value for `--extra-checks`
317314
pub tidy_extra_checks: Option<String>,
318315
pub is_running_on_ci: bool,
@@ -497,7 +494,8 @@ impl Config {
497494
optimized_compiler_builtins: build_optimized_compiler_builtins,
498495
jobs: build_jobs,
499496
compiletest_diff_tool: build_compiletest_diff_tool,
500-
compiletest_use_stage0_libtest: build_compiletest_use_stage0_libtest,
497+
// No longer has any effect; kept (for now) to avoid breaking people's configs.
498+
compiletest_use_stage0_libtest: _,
501499
tidy_extra_checks: build_tidy_extra_checks,
502500
ccache: build_ccache,
503501
exclude: build_exclude,
@@ -1197,7 +1195,6 @@ impl Config {
11971195
compiler_docs: build_compiler_docs.unwrap_or(false),
11981196
compiletest_allow_stage0: build_compiletest_allow_stage0.unwrap_or(false),
11991197
compiletest_diff_tool: build_compiletest_diff_tool,
1200-
compiletest_use_stage0_libtest: build_compiletest_use_stage0_libtest.unwrap_or(true),
12011198
config: toml_path,
12021199
configure_args: build_configure_args.unwrap_or_default(),
12031200
control_flow_guard: rust_control_flow_guard.unwrap_or(false),

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ use crate::str::FromStr;
4747
#[macro_export]
4848
macro_rules! define_config {
4949
($(#[$attr:meta])* struct $name:ident {
50-
$($field:ident: Option<$field_ty:ty> = $field_key:literal,)*
50+
$(
51+
$(#[$field_attr:meta])*
52+
$field:ident: Option<$field_ty:ty> = $field_key:literal,
53+
)*
5154
}) => {
5255
$(#[$attr])*
5356
pub struct $name {
54-
$(pub $field: Option<$field_ty>,)*
57+
$(
58+
$(#[$field_attr])*
59+
pub $field: Option<$field_ty>,
60+
)*
5561
}
5662

5763
impl Merge for $name {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ define_config! {
7070
jobs: Option<u32> = "jobs",
7171
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
7272
compiletest_allow_stage0: Option<bool> = "compiletest-allow-stage0",
73+
/// No longer has any effect; kept (for now) to avoid breaking people's configs.
74+
/// FIXME(#146929): Remove this in 2026.
7375
compiletest_use_stage0_libtest: Option<bool> = "compiletest-use-stage0-libtest",
7476
tidy_extra_checks: Option<String> = "tidy-extra-checks",
7577
ccache: Option<StringOrBool> = "ccache",

src/bootstrap/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ pub enum Mode {
327327
ToolTarget,
328328

329329
/// Build a tool which uses the locally built std, placing output in the
330-
/// "stageN-tools" directory. Its usage is quite rare, mainly used by
331-
/// compiletest which needs libtest.
330+
/// "stageN-tools" directory. Its usage is quite rare; historically it was
331+
/// needed by compiletest, but now it is mainly used by `test-float-parse`.
332332
ToolStd,
333333

334334
/// Build a tool which uses the `rustc_private` mechanism, and thus

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,4 +561,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
561561
severity: ChangeSeverity::Warning,
562562
summary: "The `rust.use-lld` option has been renamed to `rust.bootstrap-override-lld`. Note that it only serves for overriding the linker used when building Rust code in bootstrap to be LLD.",
563563
},
564+
ChangeInfo {
565+
change_id: 146929,
566+
severity: ChangeSeverity::Info,
567+
summary: "`compiletest` is now always built with the stage 0 compiler, so `build.compiletest-use-stage0-libtest` has no effect.",
568+
},
564569
];

0 commit comments

Comments
 (0)