Skip to content

Commit 36dfed6

Browse files
committed
Remove usage of compiler_for from the compile::Rustc step
1 parent d8a51f5 commit 36dfed6

File tree

1 file changed

+43
-51
lines changed

1 file changed

+43
-51
lines changed

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

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,14 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
666666
cargo.rustdocflag("-Zcrate-attr=warn(rust_2018_idioms)");
667667
}
668668

669+
/// Link all libstd rlibs/dylibs into a sysroot of `target_compiler`.
670+
///
671+
/// Links those artifacts generated by `compiler` to the `stage` compiler's
672+
/// sysroot for the specified `host` and `target`.
673+
///
674+
/// Note that this assumes that `compiler` has already generated the libstd
675+
/// libraries for `target`, and this method will find them in the relevant
676+
/// output directory.
669677
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
670678
pub struct StdLink {
671679
pub compiler: Compiler,
@@ -952,14 +960,8 @@ impl Rustc {
952960
}
953961

954962
impl Step for Rustc {
955-
/// We return the stage of the "actual" compiler (not the uplifted one).
956-
///
957-
/// By "actual" we refer to the uplifting logic where we may not compile the requested stage;
958-
/// instead, we uplift it from the previous stages. Which can lead to bootstrap failures in
959-
/// specific situations where we request stage X from other steps. However we may end up
960-
/// uplifting it from stage Y, causing the other stage to fail when attempting to link with
961-
/// stage X which was never actually built.
962-
type Output = u32;
963+
type Output = ();
964+
963965
const IS_HOST: bool = true;
964966
const DEFAULT: bool = false;
965967

@@ -998,7 +1000,7 @@ impl Step for Rustc {
9981000
/// This will build the compiler for a particular stage of the build using
9991001
/// the `build_compiler` targeting the `target` architecture. The artifacts
10001002
/// created will also be linked into the sysroot directory.
1001-
fn run(self, builder: &Builder<'_>) -> u32 {
1003+
fn run(self, builder: &Builder<'_>) {
10021004
let build_compiler = self.build_compiler;
10031005
let target = self.target;
10041006

@@ -1014,7 +1016,7 @@ impl Step for Rustc {
10141016
&sysroot,
10151017
builder.config.ci_rustc_dev_contents(),
10161018
);
1017-
return build_compiler.stage;
1019+
return;
10181020
}
10191021

10201022
// Build a standard library for `target` using the `build_compiler`.
@@ -1028,31 +1030,33 @@ impl Step for Rustc {
10281030
builder.info("WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes");
10291031
builder.ensure(RustcLink::from_rustc(self, build_compiler));
10301032

1031-
return build_compiler.stage;
1033+
return;
10321034
}
10331035

1034-
let compiler_to_use =
1035-
builder.compiler_for(build_compiler.stage, build_compiler.host, target);
1036-
if compiler_to_use != build_compiler {
1037-
builder.ensure(Rustc::new(compiler_to_use, target));
1038-
let msg = if compiler_to_use.host == target {
1039-
format!(
1040-
"Uplifting rustc (stage{} -> stage{})",
1041-
compiler_to_use.stage,
1042-
build_compiler.stage + 1
1043-
)
1036+
// The stage of the compiler that we're building
1037+
let stage = build_compiler.stage + 1;
1038+
1039+
// If we are building a stage3+ compiler, and full bootstrap is disabled, and we have a
1040+
// previous rustc available, we will uplift a compiler from a previous stage.
1041+
if build_compiler.stage >= 2
1042+
&& !builder.config.full_bootstrap
1043+
&& (target == builder.host_target || builder.hosts.contains(&target))
1044+
{
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.
1047+
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,)
10441051
} else {
10451052
format!(
1046-
"Uplifting rustc (stage{}:{} -> stage{}:{})",
1047-
compiler_to_use.stage,
1048-
compiler_to_use.host,
1049-
build_compiler.stage + 1,
1050-
target
1053+
"Uplifting rustc (stage{}:{} -> stage{stage}:{target})",
1054+
rustc_to_uplift.stage, rustc_to_uplift.host,
10511055
)
10521056
};
10531057
builder.info(&msg);
1054-
builder.ensure(RustcLink::from_rustc(self, compiler_to_use));
1055-
return compiler_to_use.stage;
1058+
builder.ensure(RustcLink::from_rustc(self, rustc_to_uplift));
1059+
return;
10561060
}
10571061

10581062
// Build a standard library for the current host target using the `build_compiler`.
@@ -1129,8 +1133,6 @@ impl Step for Rustc {
11291133
self,
11301134
builder.compiler(build_compiler.stage, builder.config.host_target),
11311135
));
1132-
1133-
build_compiler.stage
11341136
}
11351137

11361138
fn metadata(&self) -> Option<StepMetadata> {
@@ -1910,12 +1912,18 @@ impl Step for Sysroot {
19101912
}
19111913
}
19121914

1915+
/// Prepare a compiler sysroot.
1916+
///
1917+
/// The sysroot may contain various things useful for running the compiler, like linkers and
1918+
/// linker wrappers (LLD, LLVM bitcode linker, etc.).
1919+
///
1920+
/// This will assemble a compiler in `build/$target/stage$stage`.
19131921
#[derive(Debug, PartialOrd, Ord, Clone, PartialEq, Eq, Hash)]
19141922
pub struct Assemble {
19151923
/// The compiler which we will produce in this step. Assemble itself will
19161924
/// take care of ensuring that the necessary prerequisites to do so exist,
1917-
/// that is, this target can be a stage2 compiler and Assemble will build
1918-
/// previous stages for you.
1925+
/// that is, this can be e.g. a stage2 compiler and Assemble will build
1926+
/// the previous stages for you.
19191927
pub target_compiler: Compiler,
19201928
}
19211929

@@ -1933,11 +1941,6 @@ impl Step for Assemble {
19331941
});
19341942
}
19351943

1936-
/// Prepare a new compiler from the artifacts in `stage`
1937-
///
1938-
/// This will assemble a compiler in `build/$host/stage$stage`. The compiler
1939-
/// must have been previously produced by the `stage - 1` builder.build
1940-
/// compiler.
19411944
fn run(self, builder: &Builder<'_>) -> Compiler {
19421945
let target_compiler = self.target_compiler;
19431946

@@ -2066,7 +2069,7 @@ impl Step for Assemble {
20662069
target_compiler.stage - 1,
20672070
builder.config.host_target,
20682071
);
2069-
let mut build_compiler =
2072+
let build_compiler =
20702073
builder.compiler(target_compiler.stage - 1, builder.config.host_target);
20712074

20722075
// Build enzyme
@@ -2090,24 +2093,13 @@ impl Step for Assemble {
20902093
}
20912094

20922095
// Build the libraries for this compiler to link to (i.e., the libraries
2093-
// it uses at runtime). NOTE: Crates the target compiler compiles don't
2094-
// link to these. (FIXME: Is that correct? It seems to be correct most
2095-
// of the time but I think we do link to these for stage2/bin compilers
2096-
// when not performing a full bootstrap).
2096+
// it uses at runtime).
20972097
debug!(
20982098
?build_compiler,
20992099
"target_compiler.host" = ?target_compiler.host,
21002100
"building compiler libraries to link to"
21012101
);
2102-
let actual_stage = builder.ensure(Rustc::new(build_compiler, target_compiler.host));
2103-
// Current build_compiler.stage might be uplifted instead of being built; so update it
2104-
// to not fail while linking the artifacts.
2105-
debug!(
2106-
"(old) build_compiler.stage" = build_compiler.stage,
2107-
"(adjusted) build_compiler.stage" = actual_stage,
2108-
"temporarily adjusting `build_compiler.stage` to account for uplifted libraries"
2109-
);
2110-
build_compiler.stage = actual_stage;
2102+
builder.ensure(Rustc::new(build_compiler, target_compiler.host));
21112103

21122104
let stage = target_compiler.stage;
21132105
let host = target_compiler.host;

0 commit comments

Comments
 (0)