Skip to content

Commit 0e6a966

Browse files
committed
Fix uplifting in Assemble step
1 parent 425a9c0 commit 0e6a966

File tree

1 file changed

+55
-36
lines changed

1 file changed

+55
-36
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,15 @@ fn cp_rustc_component_to_ci_sysroot(builder: &Builder<'_>, sysroot: &Path, conte
933933
}
934934
}
935935

936+
/// Represents information about a built rustc.
937+
#[derive(Clone, Debug)]
938+
pub struct BuiltRustc {
939+
/// The compiler that actually built this *rustc*.
940+
/// This can be different from the *build_compiler* passed to the `Rustc` step because of
941+
/// uplifting.
942+
pub build_compiler: Compiler,
943+
}
944+
936945
/// Build rustc using the passed `build_compiler`.
937946
///
938947
/// - Makes sure that `build_compiler` has a standard library prepared for its host target,
@@ -960,7 +969,7 @@ impl Rustc {
960969
}
961970

962971
impl Step for Rustc {
963-
type Output = ();
972+
type Output = BuiltRustc;
964973

965974
const IS_HOST: bool = true;
966975
const DEFAULT: bool = false;
@@ -1000,7 +1009,7 @@ impl Step for Rustc {
10001009
/// This will build the compiler for a particular stage of the build using
10011010
/// the `build_compiler` targeting the `target` architecture. The artifacts
10021011
/// created will also be linked into the sysroot directory.
1003-
fn run(self, builder: &Builder<'_>) {
1012+
fn run(self, builder: &Builder<'_>) -> Self::Output {
10041013
let build_compiler = self.build_compiler;
10051014
let target = self.target;
10061015

@@ -1016,7 +1025,7 @@ impl Step for Rustc {
10161025
&sysroot,
10171026
builder.config.ci_rustc_dev_contents(),
10181027
);
1019-
return;
1028+
return BuiltRustc { build_compiler };
10201029
}
10211030

10221031
// Build a standard library for `target` using the `build_compiler`.
@@ -1028,9 +1037,9 @@ impl Step for Rustc {
10281037

10291038
builder.info("WARNING: Using a potentially old librustc. This may not behave well.");
10301039
builder.info("WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes");
1031-
builder.ensure(RustcLink::from_rustc(self, build_compiler));
1040+
builder.ensure(RustcLink::from_rustc(self));
10321041

1033-
return;
1042+
return BuiltRustc { build_compiler };
10341043
}
10351044

10361045
// The stage of the compiler that we're building
@@ -1042,21 +1051,31 @@ impl Step for Rustc {
10421051
&& !builder.config.full_bootstrap
10431052
&& (target == builder.host_target || builder.hosts.contains(&target))
10441053
{
1045-
// If we're cross-compiling, the earliest rustc that we could have is stage 2.
1046-
// If we're not cross-compiling, then we should have rustc stage 1.
1054+
// Here we need to determine the **build compiler** that built the stage that we will
1055+
// be uplifting.
1056+
// - If we're cross-compiling, the earliest rustc that we could have is stage 2, so its
1057+
// build compiler is stage 1.
1058+
// - If we're not cross-compiling, then we should have rustc stage 1, so its build
1059+
// compiler is stage 0.
10471060
let stage_to_uplift = if target == builder.host_target { 1 } else { 2 };
1048-
let rustc_to_uplift = builder.compiler(stage_to_uplift, target);
1049-
let msg = if rustc_to_uplift.host == target {
1050-
format!("Uplifting rustc (stage{} -> stage{stage})", rustc_to_uplift.stage,)
1061+
let build_compiler = builder.compiler(stage_to_uplift - 1, build_compiler.host);
1062+
let msg = if build_compiler.host == target {
1063+
format!("Uplifting rustc (stage{stage_to_uplift} -> stage{stage})")
10511064
} else {
10521065
format!(
1053-
"Uplifting rustc (stage{}:{} -> stage{stage}:{target})",
1054-
rustc_to_uplift.stage, rustc_to_uplift.host,
1066+
"Uplifting rustc (stage{stage_to_uplift}:{} -> stage{stage}:{target})",
1067+
build_compiler.host
10551068
)
10561069
};
10571070
builder.info(&msg);
1058-
builder.ensure(RustcLink::from_rustc(self, rustc_to_uplift));
1059-
return;
1071+
1072+
// Note that we do not invoke `RustcLink` here. Because the uplifted compiled was
1073+
// already built before using `build_compiler`, and its rlibs thus also had to be copied
1074+
// into the build compiler's sysroot.
1075+
1076+
// Here we have performed an uplift, so we return the actual built compiler that "built"
1077+
// this rustc.
1078+
return BuiltRustc { build_compiler };
10601079
}
10611080

10621081
// Build a standard library for the current host target using the `build_compiler`.
@@ -1129,10 +1148,8 @@ impl Step for Rustc {
11291148
strip_debug(builder, target, &target_root_dir.join("rustc-main"));
11301149
}
11311150

1132-
builder.ensure(RustcLink::from_rustc(
1133-
self,
1134-
builder.compiler(build_compiler.stage, builder.config.host_target),
1135-
));
1151+
builder.ensure(RustcLink::from_rustc(self));
1152+
BuiltRustc { build_compiler }
11361153
}
11371154

11381155
fn metadata(&self) -> Option<StepMetadata> {
@@ -1441,30 +1458,30 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
14411458
}
14421459
}
14431460

1444-
/// `RustcLink` copies all of the rlibs from the rustc build into the previous stage's sysroot.
1461+
/// `RustcLink` copies compiler rlibs from a rustc build into the sysroot of the compiler that built
1462+
/// them.
14451463
/// This is necessary for tools using `rustc_private`, where the previous compiler will build
14461464
/// a tool against the next compiler.
14471465
/// To build a tool against a compiler, the rlibs of that compiler that it links against
14481466
/// must be in the sysroot of the compiler that's doing the compiling.
14491467
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
14501468
struct RustcLink {
1451-
/// The compiler whose rlibs we are copying around.
1452-
pub compiler: Compiler,
14531469
/// This is the compiler into whose sysroot we want to copy the rlibs into.
1454-
pub previous_stage_compiler: Compiler,
1455-
pub target: TargetSelection,
1470+
/// This compiler **built** some rustc, whose rlibs we will copy into the sysroot.
1471+
/// Note that we do not explicitly work with the built compiler in this stage at all.
1472+
/// We just access the build stamp of *some* rustc built by `build_compiler` for the given
1473+
/// `target`, and copy all the rlibs into the build compiler's sysroot.
1474+
build_compiler: Compiler,
1475+
target: TargetSelection,
14561476
/// Not actually used; only present to make sure the cache invalidation is correct.
14571477
crates: Vec<String>,
14581478
}
14591479

14601480
impl RustcLink {
1461-
fn from_rustc(rustc: Rustc, host_compiler: Compiler) -> Self {
1462-
Self {
1463-
compiler: host_compiler,
1464-
previous_stage_compiler: rustc.build_compiler,
1465-
target: rustc.target,
1466-
crates: rustc.crates,
1467-
}
1481+
/// Copy rlibs from the build compiler that build this `rustc` into the sysroot of that
1482+
/// build compiler.
1483+
fn from_rustc(rustc: Rustc) -> Self {
1484+
Self { build_compiler: rustc.build_compiler, target: rustc.target, crates: rustc.crates }
14681485
}
14691486
}
14701487

@@ -1477,14 +1494,13 @@ impl Step for RustcLink {
14771494

14781495
/// Same as `std_link`, only for librustc
14791496
fn run(self, builder: &Builder<'_>) {
1480-
let compiler = self.compiler;
1481-
let previous_stage_compiler = self.previous_stage_compiler;
1497+
let build_compiler = self.build_compiler;
14821498
let target = self.target;
14831499
add_to_sysroot(
14841500
builder,
1485-
&builder.sysroot_target_libdir(previous_stage_compiler, target),
1486-
&builder.sysroot_target_libdir(previous_stage_compiler, compiler.host),
1487-
&build_stamp::librustc_stamp(builder, compiler, target),
1501+
&builder.sysroot_target_libdir(build_compiler, target),
1502+
&builder.sysroot_target_libdir(build_compiler, build_compiler.host),
1503+
&build_stamp::librustc_stamp(builder, build_compiler, target),
14881504
);
14891505
}
14901506
}
@@ -2099,7 +2115,10 @@ impl Step for Assemble {
20992115
"target_compiler.host" = ?target_compiler.host,
21002116
"building compiler libraries to link to"
21012117
);
2102-
builder.ensure(Rustc::new(build_compiler, target_compiler.host));
2118+
2119+
// It is possible that an uplift has happened, so we override build_compiler here.
2120+
let BuiltRustc { build_compiler } =
2121+
builder.ensure(Rustc::new(build_compiler, target_compiler.host));
21032122

21042123
let stage = target_compiler.stage;
21052124
let host = target_compiler.host;

0 commit comments

Comments
 (0)