Skip to content

Commit 7ecf229

Browse files
authored
Unrolled build for #146929
Rollup merge of #146929 - Zalathar:capture, r=Kobzol,jieyouxu compiletest: Remove old-output-capture and become a stage0 bootstrap tool The new compiletest output-capture system became the default in #146574, and no problems have been reported since. This PR therefore removes the old output-capture implementation from compiletest, and adjusts bootstrap to always build and test compiletest as a stage0 bootstrap tool. In other words, compiletest no longer relies on any unstable features (such as `libtest` or `internal_output_capture`), and is now written entirely in stable Rust! The compiletest self-tests still need access to an in-tree rustc, in order to obtain information via `rustc --print`, so we interpret `--stage` as indicating the stage of that secondary compiler, but always use the stage0 compiler to build compiletest itself. r? Kobzol
2 parents 772f380 + 8b18798 commit 7ecf229

File tree

12 files changed

+78
-154
lines changed

12 files changed

+78
-154
lines changed

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

Lines changed: 20 additions & 33 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,
@@ -654,7 +654,7 @@ macro_rules! tool_check_step {
654654
// The part of this path after the final '/' is also used as a display name.
655655
path: $path:literal
656656
$(, alt_path: $alt_path:literal )*
657-
// Closure that returns `Mode` based on the passed `&Builder<'_>`
657+
// `Mode` to use when checking this tool
658658
, mode: $mode:expr
659659
// Subset of nightly features that are allowed to be used when checking
660660
$(, allow_features: $allow_features:expr )?
@@ -682,8 +682,7 @@ macro_rules! tool_check_step {
682682

683683
fn make_run(run: RunConfig<'_>) {
684684
let target = run.target;
685-
let builder = run.builder;
686-
let mode = $mode(builder);
685+
let mode: Mode = $mode;
687686

688687
let compiler = prepare_compiler_for_check(run.builder, target, mode);
689688

@@ -704,7 +703,7 @@ macro_rules! tool_check_step {
704703
_value
705704
};
706705
let extra_features: &[&str] = &[$($($enable_features),*)?];
707-
let mode = $mode(builder);
706+
let mode: Mode = $mode;
708707
run_tool_check_step(builder, compiler, target, $path, mode, allow_features, extra_features);
709708
}
710709

@@ -767,81 +766,69 @@ fn run_tool_check_step(
767766
tool_check_step!(Rustdoc {
768767
path: "src/tools/rustdoc",
769768
alt_path: "src/librustdoc",
770-
mode: |_builder| Mode::ToolRustcPrivate
769+
mode: Mode::ToolRustcPrivate
771770
});
772771
// Clippy, miri and Rustfmt are hybrids. They are external tools, but use a git subtree instead
773772
// of a submodule. Since the SourceType only drives the deny-warnings
774773
// behavior, treat it as in-tree so that any new warnings in clippy will be
775774
// rejected.
776-
tool_check_step!(Clippy { path: "src/tools/clippy", mode: |_builder| Mode::ToolRustcPrivate });
777-
tool_check_step!(Miri { path: "src/tools/miri", mode: |_builder| Mode::ToolRustcPrivate });
778-
tool_check_step!(CargoMiri {
779-
path: "src/tools/miri/cargo-miri",
780-
mode: |_builder| Mode::ToolRustcPrivate
781-
});
782-
tool_check_step!(Rustfmt { path: "src/tools/rustfmt", mode: |_builder| Mode::ToolRustcPrivate });
775+
tool_check_step!(Clippy { path: "src/tools/clippy", mode: Mode::ToolRustcPrivate });
776+
tool_check_step!(Miri { path: "src/tools/miri", mode: Mode::ToolRustcPrivate });
777+
tool_check_step!(CargoMiri { path: "src/tools/miri/cargo-miri", mode: Mode::ToolRustcPrivate });
778+
tool_check_step!(Rustfmt { path: "src/tools/rustfmt", mode: Mode::ToolRustcPrivate });
783779
tool_check_step!(RustAnalyzer {
784780
path: "src/tools/rust-analyzer",
785-
mode: |_builder| Mode::ToolRustcPrivate,
781+
mode: Mode::ToolRustcPrivate,
786782
allow_features: tool::RustAnalyzer::ALLOW_FEATURES,
787783
enable_features: ["in-rust-tree"],
788784
});
789785
tool_check_step!(MiroptTestTools {
790786
path: "src/tools/miropt-test-tools",
791-
mode: |_builder| Mode::ToolBootstrap
787+
mode: Mode::ToolBootstrap
792788
});
793789
// We want to test the local std
794790
tool_check_step!(TestFloatParse {
795791
path: "src/tools/test-float-parse",
796-
mode: |_builder| Mode::ToolStd,
792+
mode: Mode::ToolStd,
797793
allow_features: TEST_FLOAT_PARSE_ALLOW_FEATURES
798794
});
799795
tool_check_step!(FeaturesStatusDump {
800796
path: "src/tools/features-status-dump",
801-
mode: |_builder| Mode::ToolBootstrap
797+
mode: Mode::ToolBootstrap
802798
});
803799

804-
tool_check_step!(Bootstrap {
805-
path: "src/bootstrap",
806-
mode: |_builder| Mode::ToolBootstrap,
807-
default: false
808-
});
800+
tool_check_step!(Bootstrap { path: "src/bootstrap", mode: Mode::ToolBootstrap, default: false });
809801

810802
// `run-make-support` will be built as part of suitable run-make compiletest test steps, but support
811803
// check to make it easier to work on.
812804
tool_check_step!(RunMakeSupport {
813805
path: "src/tools/run-make-support",
814-
mode: |_builder| Mode::ToolBootstrap,
806+
mode: Mode::ToolBootstrap,
815807
default: false
816808
});
817809

818810
tool_check_step!(CoverageDump {
819811
path: "src/tools/coverage-dump",
820-
mode: |_builder| Mode::ToolBootstrap,
812+
mode: Mode::ToolBootstrap,
821813
default: false
822814
});
823815

824816
// Compiletest is implicitly "checked" when it gets built in order to run tests,
825817
// so this is mainly for people working on compiletest to run locally.
826818
tool_check_step!(Compiletest {
827819
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,
820+
mode: Mode::ToolBootstrap,
834821
default: false,
835822
});
836823

837824
tool_check_step!(Linkchecker {
838825
path: "src/tools/linkchecker",
839-
mode: |_builder| Mode::ToolBootstrap,
826+
mode: Mode::ToolBootstrap,
840827
default: false
841828
});
842829

843830
tool_check_step!(BumpStage0 {
844831
path: "src/tools/bump-stage0",
845-
mode: |_builder| Mode::ToolBootstrap,
832+
mode: Mode::ToolBootstrap,
846833
default: false
847834
});

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: 11 additions & 15 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();
@@ -2145,6 +2130,17 @@ mod snapshot {
21452130
");
21462131
}
21472132

2133+
#[test]
2134+
fn test_compiletest_self_test() {
2135+
let ctx = TestCtx::new();
2136+
let steps = ctx.config("test").arg("compiletest").render_steps();
2137+
insta::assert_snapshot!(steps, @r"
2138+
[build] llvm <host>
2139+
[build] rustc 0 <host> -> rustc 1 <host>
2140+
[build] rustdoc 0 <host>
2141+
");
2142+
}
2143+
21482144
#[test]
21492145
fn test_compiletest_suites_stage1() {
21502146
let ctx = TestCtx::new();

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,13 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
557557
summary: "New option `build.windows-rc` that will override which resource compiler on Windows will be used to compile Rust.",
558558
},
559559
ChangeInfo {
560-
change_id: 99999,
560+
change_id: 147046,
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)