Skip to content

Commit cdd8af2

Browse files
committed
Auto merge of #138205 - onur-ozkan:fix-build-cycle, r=jieyouxu
handle precompiled compiler more properly Fixes the build cycle problem reported on [#t-infra/bootstrap > Cycle on `aarch64-apple`](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Cycle.20on.20.60aarch64-apple.60/with/504231609).
2 parents 20f0108 + dd8d1b4 commit cdd8af2

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1991,12 +1991,12 @@ impl Step for Assemble {
19911991
}
19921992
}
19931993

1994-
let maybe_install_llvm_bitcode_linker = || {
1994+
let maybe_install_llvm_bitcode_linker = |compiler| {
19951995
if builder.config.llvm_bitcode_linker_enabled {
19961996
trace!("llvm-bitcode-linker enabled, installing");
19971997
let llvm_bitcode_linker =
19981998
builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
1999-
compiler: target_compiler,
1999+
compiler,
20002000
target: target_compiler.host,
20012001
extra_features: vec![],
20022002
});
@@ -2020,7 +2020,9 @@ impl Step for Assemble {
20202020
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage=target_compiler.stage));
20212021
}
20222022

2023-
maybe_install_llvm_bitcode_linker();
2023+
let mut precompiled_compiler = target_compiler;
2024+
precompiled_compiler.forced_compiler(true);
2025+
maybe_install_llvm_bitcode_linker(precompiled_compiler);
20242026

20252027
return target_compiler;
20262028
}
@@ -2203,7 +2205,7 @@ impl Step for Assemble {
22032205
);
22042206
}
22052207

2206-
maybe_install_llvm_bitcode_linker();
2208+
maybe_install_llvm_bitcode_linker(target_compiler);
22072209

22082210
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
22092211
// so that it can be found when the newly built `rustc` is run.

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

+13-11
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,20 @@ pub(crate) fn get_tool_rustc_compiler(
319319
builder: &Builder<'_>,
320320
target_compiler: Compiler,
321321
) -> Compiler {
322-
if builder.download_rustc() && target_compiler.stage == 1 {
323-
// We already have the stage 1 compiler, we don't need to cut the stage.
324-
builder.compiler(target_compiler.stage, builder.config.build)
325-
} else if target_compiler.is_forced_compiler() {
326-
target_compiler
327-
} else {
328-
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
329-
// we'd have stageN/bin/rustc and stageN/bin/$rustc_tool be effectively different stage
330-
// compilers, which isn't what we want. Rustc tools should be linked in the same way as the
331-
// compiler it's paired with, so it must be built with the previous stage compiler.
332-
builder.compiler(target_compiler.stage.saturating_sub(1), builder.config.build)
322+
if target_compiler.is_forced_compiler() {
323+
return target_compiler;
324+
}
325+
326+
if builder.download_rustc() && target_compiler.stage > 0 {
327+
// We already have the stage N compiler, we don't need to cut the stage.
328+
return builder.compiler(target_compiler.stage, builder.config.build);
333329
}
330+
331+
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
332+
// we'd have stageN/bin/rustc and stageN/bin/$rustc_tool be effectively different stage
333+
// compilers, which isn't what we want. Rustc tools should be linked in the same way as the
334+
// compiler it's paired with, so it must be built with the previous stage compiler.
335+
builder.compiler(target_compiler.stage.saturating_sub(1), builder.config.build)
334336
}
335337

336338
/// Links a built tool binary with the given `name` from the build directory to the

src/bootstrap/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
9696
pub struct Compiler {
9797
stage: u32,
9898
host: TargetSelection,
99-
/// Indicates whether `compiler_for` was used to force a specific compiler stage.
99+
/// Indicates whether the compiler was forced to use a specific stage.
100100
/// This field is ignored in `Hash` and `PartialEq` implementations as only the `stage`
101101
/// and `host` fields are relevant for those.
102102
forced_compiler: bool,
@@ -1998,7 +1998,7 @@ impl Compiler {
19981998
self.stage == 0 && self.host == build.build
19991999
}
20002000

2001-
/// Indicates whether `compiler_for` was used to force a specific compiler stage.
2001+
/// Indicates whether the compiler was forced to use a specific stage.
20022002
pub fn is_forced_compiler(&self) -> bool {
20032003
self.forced_compiler
20042004
}

0 commit comments

Comments
 (0)