Skip to content

Commit 7a6b50a

Browse files
committed
Remove usage of compiler_for from the compile::Rustc step
1 parent b13717b commit 7a6b50a

File tree

1 file changed

+38
-64
lines changed

1 file changed

+38
-64
lines changed

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

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,14 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car
661661
cargo.rustdocflag("-Zcrate-attr=warn(rust_2018_idioms)");
662662
}
663663

664+
/// Link all libstd rlibs/dylibs into a sysroot of `target_compiler`.
665+
///
666+
/// Links those artifacts generated by `compiler` to the `stage` compiler's
667+
/// sysroot for the specified `host` and `target`.
668+
///
669+
/// Note that this assumes that `compiler` has already generated the libstd
670+
/// libraries for `target`, and this method will find them in the relevant
671+
/// output directory.
664672
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
665673
pub struct StdLink {
666674
pub compiler: Compiler,
@@ -691,14 +699,6 @@ impl Step for StdLink {
691699
run.never()
692700
}
693701

694-
/// Link all libstd rlibs/dylibs into the sysroot location.
695-
///
696-
/// Links those artifacts generated by `compiler` to the `stage` compiler's
697-
/// sysroot for the specified `host` and `target`.
698-
///
699-
/// Note that this assumes that `compiler` has already generated the libstd
700-
/// libraries for `target`, and this method will find them in the relevant
701-
/// output directory.
702702
#[cfg_attr(
703703
feature = "tracing",
704704
instrument(
@@ -969,14 +969,8 @@ impl Rustc {
969969
}
970970

971971
impl Step for Rustc {
972-
/// We return the stage of the "actual" compiler (not the uplifted one).
973-
///
974-
/// By "actual" we refer to the uplifting logic where we may not compile the requested stage;
975-
/// instead, we uplift it from the previous stages. Which can lead to bootstrap failures in
976-
/// specific situations where we request stage X from other steps. However we may end up
977-
/// uplifting it from stage Y, causing the other stage to fail when attempting to link with
978-
/// stage X which was never actually built.
979-
type Output = u32;
972+
type Output = ();
973+
980974
const ONLY_HOSTS: bool = true;
981975
const DEFAULT: bool = false;
982976

@@ -1024,7 +1018,7 @@ impl Step for Rustc {
10241018
fields(previous_compiler = ?self.build_compiler, target = ?self.target),
10251019
),
10261020
)]
1027-
fn run(self, builder: &Builder<'_>) -> u32 {
1021+
fn run(self, builder: &Builder<'_>) {
10281022
let build_compiler = self.build_compiler;
10291023
let target = self.target;
10301024

@@ -1040,7 +1034,7 @@ impl Step for Rustc {
10401034
&sysroot,
10411035
builder.config.ci_rustc_dev_contents(),
10421036
);
1043-
return build_compiler.stage;
1037+
return;
10441038
}
10451039

10461040
// Build a standard library for `target` using the `build_compiler`.
@@ -1054,31 +1048,23 @@ impl Step for Rustc {
10541048
builder.info("WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes");
10551049
builder.ensure(RustcLink::from_rustc(self, build_compiler));
10561050

1057-
return build_compiler.stage;
1051+
return;
10581052
}
10591053

1060-
let compiler_to_use =
1061-
builder.compiler_for(build_compiler.stage, build_compiler.host, target);
1062-
if compiler_to_use != build_compiler {
1063-
builder.ensure(Rustc::new(compiler_to_use, target));
1064-
let msg = if compiler_to_use.host == target {
1065-
format!(
1066-
"Uplifting rustc (stage{} -> stage{})",
1067-
compiler_to_use.stage,
1068-
build_compiler.stage + 1
1069-
)
1070-
} else {
1071-
format!(
1072-
"Uplifting rustc (stage{}:{} -> stage{}:{})",
1073-
compiler_to_use.stage,
1074-
compiler_to_use.host,
1075-
build_compiler.stage + 1,
1076-
target
1077-
)
1078-
};
1079-
builder.info(&msg);
1080-
builder.ensure(RustcLink::from_rustc(self, compiler_to_use));
1081-
return compiler_to_use.stage;
1054+
// The stage of the compiler that we're building
1055+
let stage = build_compiler.stage + 1;
1056+
1057+
// If we are building a stage3+ compiler, and full bootstrap is disabled, and we're not
1058+
// cross-compiling, we will uplift a compiler from stage1.
1059+
if build_compiler.stage >= 2
1060+
&& !builder.config.full_bootstrap
1061+
&& target == builder.host_target
1062+
{
1063+
let rustc_to_uplift = builder.compiler(1, target);
1064+
builder
1065+
.info(&format!("Uplifting rustc (stage{} -> stage{stage})", rustc_to_uplift.stage));
1066+
builder.ensure(RustcLink::from_rustc(self, rustc_to_uplift));
1067+
return;
10821068
}
10831069

10841070
// Build a standard library for the current host target using the `build_compiler`.
@@ -1155,8 +1141,6 @@ impl Step for Rustc {
11551141
self,
11561142
builder.compiler(build_compiler.stage, builder.config.host_target),
11571143
));
1158-
1159-
build_compiler.stage
11601144
}
11611145

11621146
fn metadata(&self) -> Option<StepMetadata> {
@@ -1970,12 +1954,18 @@ impl Step for Sysroot {
19701954
}
19711955
}
19721956

1957+
/// Prepare a compiler sysroot.
1958+
///
1959+
/// The sysroot may contain various things useful for running the compiler, like linkers and
1960+
/// linker wrappers (LLD, LLVM bitcode linker, etc.).
1961+
///
1962+
/// This will assemble a compiler in `build/$target/stage$stage`.
19731963
#[derive(Debug, PartialOrd, Ord, Clone, PartialEq, Eq, Hash)]
19741964
pub struct Assemble {
19751965
/// The compiler which we will produce in this step. Assemble itself will
19761966
/// take care of ensuring that the necessary prerequisites to do so exist,
1977-
/// that is, this target can be a stage2 compiler and Assemble will build
1978-
/// previous stages for you.
1967+
/// that is, this can be e.g. a stage2 compiler and Assemble will build
1968+
/// the previous stages for you.
19791969
pub target_compiler: Compiler,
19801970
}
19811971

@@ -1993,11 +1983,6 @@ impl Step for Assemble {
19931983
});
19941984
}
19951985

1996-
/// Prepare a new compiler from the artifacts in `stage`
1997-
///
1998-
/// This will assemble a compiler in `build/$host/stage$stage`. The compiler
1999-
/// must have been previously produced by the `stage - 1` builder.build
2000-
/// compiler.
20011986
#[cfg_attr(
20021987
feature = "tracing",
20031988
instrument(
@@ -2135,7 +2120,7 @@ impl Step for Assemble {
21352120
target_compiler.stage - 1,
21362121
builder.config.host_target,
21372122
);
2138-
let mut build_compiler =
2123+
let build_compiler =
21392124
builder.compiler(target_compiler.stage - 1, builder.config.host_target);
21402125

21412126
// Build enzyme
@@ -2159,24 +2144,13 @@ impl Step for Assemble {
21592144
}
21602145

21612146
// Build the libraries for this compiler to link to (i.e., the libraries
2162-
// it uses at runtime). NOTE: Crates the target compiler compiles don't
2163-
// link to these. (FIXME: Is that correct? It seems to be correct most
2164-
// of the time but I think we do link to these for stage2/bin compilers
2165-
// when not performing a full bootstrap).
2147+
// it uses at runtime).
21662148
debug!(
21672149
?build_compiler,
21682150
"target_compiler.host" = ?target_compiler.host,
21692151
"building compiler libraries to link to"
21702152
);
2171-
let actual_stage = builder.ensure(Rustc::new(build_compiler, target_compiler.host));
2172-
// Current build_compiler.stage might be uplifted instead of being built; so update it
2173-
// to not fail while linking the artifacts.
2174-
debug!(
2175-
"(old) build_compiler.stage" = build_compiler.stage,
2176-
"(adjusted) build_compiler.stage" = actual_stage,
2177-
"temporarily adjusting `build_compiler.stage` to account for uplifted libraries"
2178-
);
2179-
build_compiler.stage = actual_stage;
2153+
builder.ensure(Rustc::new(build_compiler, target_compiler.host));
21802154

21812155
let mut codegen_backend_stamps = vec![];
21822156
{

0 commit comments

Comments
 (0)