Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,22 @@ pub struct Std {

impl Std {
pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self {
Std {
build_compiler: builder.compiler(builder.top_stage, builder.config.host_target),
target,
}
// This is an important optimization mainly for CI.
// Normally, to build stage N libstd, we need stage N rustc.
// However, if we know that we will uplift libstd from stage 1 anyway, building the stage N
// rustc can be wasteful.
// In particular, if we do a cross-compiling dist stage 2 build from T1 to T2, we need:
Copy link
Member

@hkBst hkBst Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does 'T' stand for target? I suggest spelling it out whatever it is. Alternatives: machine, arch(itecture)

// - stage 2 libstd for T2 (uplifted from stage 1, where it was built by T1 rustc)
// - stage 2 rustc for T2
// However, without this optimization, we would also build stage 2 rustc for **T1**, which
// is completely wasteful.
let build_compiler =
if compile::Std::should_be_uplifted_from_stage_1(builder, builder.top_stage, target) {
builder.compiler(1, builder.host_target)
} else {
builder.compiler(builder.top_stage, builder.host_target)
};
Std { build_compiler, target }
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
}

/// Metadata that describes an executed step, mostly for testing and tracing.
#[allow(unused)]
#[derive(Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StepMetadata {
name: String,
kind: Kind,
Expand Down
120 changes: 95 additions & 25 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,8 +1133,7 @@ mod snapshot {
[dist] mingw <host>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <host>
[build] rustc 2 <host> -> std 2 <host>
[dist] rustc 2 <host> -> std 2 <host>
[dist] rustc 1 <host> -> std 1 <host>
[dist] rustc 1 <host> -> rustc-dev 2 <host>
[dist] src <>
[dist] reproducible-artifacts <host>
Expand Down Expand Up @@ -1198,8 +1197,7 @@ mod snapshot {
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <host>
[build] rustc 2 <host> -> std 2 <host>
[dist] rustc 2 <host> -> std 2 <host>
[dist] rustc 1 <host> -> std 1 <host>
[dist] rustc 1 <host> -> rustc-dev 2 <host>
[dist] rustc 1 <host> -> analysis 2 <host>
[dist] src <>
Expand All @@ -1216,7 +1214,6 @@ mod snapshot {
[build] rustc 1 <host> -> miri 2 <host>
[build] rustc 1 <host> -> cargo-miri 2 <host>
[dist] rustc 1 <host> -> miri 2 <host>
[dist] rustc 1 <host> -> std 1 <host>
[dist] rustc 1 <host> -> extended 2 <host>
[dist] reproducible-artifacts <host>
");
Expand Down Expand Up @@ -1287,8 +1284,7 @@ mod snapshot {
[dist] mingw <target1>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <host>
[build] rustc 2 <host> -> std 2 <host>
[dist] rustc 2 <host> -> std 2 <host>
[dist] rustc 1 <host> -> std 1 <host>
[build] rustc 2 <host> -> std 2 <target1>
[dist] rustc 2 <host> -> std 2 <target1>
[dist] rustc 1 <host> -> rustc-dev 2 <host>
Expand Down Expand Up @@ -1350,8 +1346,7 @@ mod snapshot {
[dist] rustc <host>
[build] rustdoc 2 <target1>
[dist] rustc <target1>
[build] rustc 2 <host> -> std 2 <host>
[dist] rustc 2 <host> -> std 2 <host>
[dist] rustc 1 <host> -> std 1 <host>
[dist] rustc 1 <host> -> rustc-dev 2 <host>
[dist] rustc 1 <host> -> rustc-dev 2 <target1>
[dist] src <>
Expand Down Expand Up @@ -1433,10 +1428,8 @@ mod snapshot {
[dist] rustc <host>
[build] rustdoc 2 <target1>
[dist] rustc <target1>
[build] rustc 2 <host> -> std 2 <host>
[dist] rustc 2 <host> -> std 2 <host>
[build] rustc 2 <host> -> std 2 <target1>
[dist] rustc 2 <host> -> std 2 <target1>
[dist] rustc 1 <host> -> std 1 <host>
[dist] rustc 1 <host> -> std 1 <target1>
[dist] rustc 1 <host> -> rustc-dev 2 <host>
[dist] rustc 1 <host> -> rustc-dev 2 <target1>
[dist] src <>
Expand Down Expand Up @@ -1490,10 +1483,8 @@ mod snapshot {
");
}

/// This also serves as an important regression test for <https://github.com/rust-lang/rust/issues/138123>
/// and <https://github.com/rust-lang/rust/issues/138004>.
#[test]
fn dist_all_cross() {
fn dist_all_cross_extended() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx
Expand Down Expand Up @@ -1545,8 +1536,7 @@ mod snapshot {
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <target1>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <target1>
[build] rustc 2 <host> -> std 2 <target1>
[dist] rustc 2 <host> -> std 2 <target1>
[dist] rustc 1 <host> -> std 1 <target1>
[dist] rustc 1 <host> -> rustc-dev 2 <target1>
[dist] rustc 1 <host> -> analysis 2 <target1>
[dist] src <>
Expand All @@ -1564,15 +1554,82 @@ mod snapshot {
[build] rustc 1 <host> -> cargo-miri 2 <target1>
[dist] rustc 1 <host> -> miri 2 <target1>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <target1>
[dist] rustc 1 <host> -> std 1 <target1>
[doc] rustc 2 <target1> -> std 2 <target1> crates=[]
[dist] rustc 1 <host> -> extended 2 <target1>
[dist] reproducible-artifacts <target1>
");
}

// Enable dist cranelift tarball by default with `x dist` if cranelift is enabled in
// `rust.codegen-backends`.
/// Simulates e.g. the powerpc64 builder, which is fully cross-compiled from x64, but it does
/// not build docs. Crutically, it shouldn't build host stage 2 rustc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crucially or Critically?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha :D Thanks, I'll fix it in a followup PR.

///
/// This is a regression test for <https://github.com/rust-lang/rust/issues/138123>
/// and <https://github.com/rust-lang/rust/issues/138004>.
#[test]
fn dist_all_cross_extended_no_docs() {
let ctx = TestCtx::new();
let steps = ctx
.config("dist")
.hosts(&[TEST_TRIPLE_1])
.targets(&[TEST_TRIPLE_1])
.args(&[
"--set",
"rust.channel=nightly",
"--set",
"build.extended=true",
"--set",
"build.docs=false",
])
.get_steps();

// Make sure that we don't build stage2 host rustc
steps.assert_no_match(|m| {
m.name == "rustc"
&& m.built_by.map(|b| b.stage) == Some(1)
&& *m.target.triple == host_target()
});

insta::assert_snapshot!(
steps.render(), @r"
[dist] mingw <target1>
[build] llvm <host>
[build] llvm <target1>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> WasmComponentLd 1 <host>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <target1>
[build] rustc 1 <host> -> WasmComponentLd 2 <target1>
[build] rustdoc 2 <target1>
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <target1>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
[dist] rustc <target1>
[dist] rustc 1 <host> -> std 1 <target1>
[dist] rustc 1 <host> -> rustc-dev 2 <target1>
[dist] rustc 1 <host> -> analysis 2 <target1>
[dist] src <>
[build] rustc 1 <host> -> cargo 2 <target1>
[dist] rustc 1 <host> -> cargo 2 <target1>
[build] rustc 1 <host> -> rust-analyzer 2 <target1>
[dist] rustc 1 <host> -> rust-analyzer 2 <target1>
[build] rustc 1 <host> -> rustfmt 2 <target1>
[build] rustc 1 <host> -> cargo-fmt 2 <target1>
[dist] rustc 1 <host> -> rustfmt 2 <target1>
[build] rustc 1 <host> -> clippy-driver 2 <target1>
[build] rustc 1 <host> -> cargo-clippy 2 <target1>
[dist] rustc 1 <host> -> clippy 2 <target1>
[build] rustc 1 <host> -> miri 2 <target1>
[build] rustc 1 <host> -> cargo-miri 2 <target1>
[dist] rustc 1 <host> -> miri 2 <target1>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <target1>
[dist] rustc 1 <host> -> extended 2 <target1>
[dist] reproducible-artifacts <target1>
");
}

/// Enable dist cranelift tarball by default with `x dist` if cranelift is enabled in
/// `rust.codegen-backends`.
#[test]
fn dist_cranelift_by_default() {
let ctx = TestCtx::new();
Expand Down Expand Up @@ -1619,8 +1676,7 @@ mod snapshot {
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <host>
[dist] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
[build] rustc 2 <host> -> std 2 <host>
[dist] rustc 2 <host> -> std 2 <host>
[dist] rustc 1 <host> -> std 1 <host>
[dist] rustc 1 <host> -> rustc-dev 2 <host>
[dist] src <>
[dist] reproducible-artifacts <host>
Expand Down Expand Up @@ -2351,8 +2407,7 @@ mod snapshot {
[doc] rustc 1 <host> -> releases 2 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
[dist] docs <host>
[build] rustc 2 <host> -> std 2 <host>
[dist] rustc 2 <host> -> std 2 <host>
[dist] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <host>
Expand Down Expand Up @@ -2426,6 +2481,21 @@ impl ExecutedSteps {
}
}

/// Make sure that no metadata matches the given `func`.
#[track_caller]
fn assert_no_match<F>(&self, func: F)
where
F: Fn(StepMetadata) -> bool,
{
for metadata in self.steps.iter().filter_map(|s| s.metadata.clone()) {
if func(metadata.clone()) {
panic!(
"Metadata {metadata:?} was found, even though it should have not been present"
);
}
}
}

fn contains(&self, metadata: &StepMetadata) -> bool {
self.steps
.iter()
Expand Down
Loading