Skip to content

Commit 2839f99

Browse files
committed
Use std uplifting more often
1 parent 6058f7f commit 2839f99

File tree

5 files changed

+21
-40
lines changed

5 files changed

+21
-40
lines changed

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,12 @@ impl Std {
9999
deps
100100
}
101101

102-
/// Returns true if the standard library will be uplifted from stage 1 for the given
103-
/// `build_compiler` (which determines the stdlib stage) and `target`.
102+
/// Returns true if the standard library should be uplifted from stage 1.
104103
///
105-
/// Uplifting is enabled if we're building a stage2+ libstd, full bootstrap is
106-
/// disabled and we have a stage1 libstd already compiled for the given target.
107-
pub fn should_be_uplifted_from_stage_1(
108-
builder: &Builder<'_>,
109-
stage: u32,
110-
target: TargetSelection,
111-
) -> bool {
112-
stage > 1
113-
&& !builder.config.full_bootstrap
114-
// This estimates if a stage1 libstd exists for the given target. If we're not
115-
// cross-compiling, it should definitely exist by the time we're building a stage2
116-
// libstd.
117-
// Or if we are cross-compiling, and we are building a cross-compiled rustc, then that
118-
// rustc needs to link to a cross-compiled libstd, so again we should have a stage1
119-
// libstd for the given target prepared.
120-
// Even if we guess wrong in the cross-compiled case, the worst that should happen is
121-
// that we build a fresh stage1 libstd below, and then we immediately uplift it, so we
122-
// don't pay the libstd build cost twice.
123-
&& (target == builder.host_target || builder.config.hosts.contains(&target))
104+
/// Uplifting is enabled if we're building a stage2+ libstd and full bootstrap is
105+
/// disabled.
106+
pub fn should_be_uplifted_from_stage_1(builder: &Builder<'_>, stage: u32) -> bool {
107+
stage > 1 && !builder.config.full_bootstrap
124108
}
125109
}
126110

@@ -223,7 +207,7 @@ impl Step for Std {
223207
// Stage of the stdlib that we're building
224208
let stage = build_compiler.stage;
225209

226-
if Self::should_be_uplifted_from_stage_1(builder, build_compiler.stage, target) {
210+
if Self::should_be_uplifted_from_stage_1(builder, build_compiler.stage) {
227211
let build_compiler_for_std_to_uplift = builder.compiler(1, builder.host_target);
228212
let stage_1_stamp = builder.std(build_compiler_for_std_to_uplift, target);
229213

@@ -2007,6 +1991,8 @@ impl Step for Assemble {
20071991
fn run(self, builder: &Builder<'_>) -> Compiler {
20081992
let target_compiler = self.target_compiler;
20091993

1994+
eprintln!("{}", std::backtrace::Backtrace::force_capture());
1995+
20101996
if target_compiler.stage == 0 {
20111997
trace!("stage 0 build compiler is always available, simply returning");
20121998
assert_eq!(

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl Step for JsonDocs {
115115

116116
fn make_run(run: RunConfig<'_>) {
117117
run.builder.ensure(JsonDocs {
118-
build_compiler: run.builder.compiler_for_std(run.builder.top_stage, run.target),
118+
build_compiler: run.builder.compiler_for_std(run.builder.top_stage),
119119
target: run.target,
120120
});
121121
}
@@ -769,7 +769,7 @@ pub struct Std {
769769

770770
impl Std {
771771
pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self {
772-
Std { build_compiler: builder.compiler_for_std(builder.top_stage, target), target }
772+
Std { build_compiler: builder.compiler_for_std(builder.top_stage), target }
773773
}
774774
}
775775

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,7 @@ impl Step for Std {
616616
return;
617617
}
618618
run.builder.ensure(Std {
619-
build_compiler: run
620-
.builder
621-
.compiler_for_std(run.builder.top_stage, run.builder.host_target),
619+
build_compiler: run.builder.compiler_for_std(run.builder.top_stage),
622620
target: run.target,
623621
format: if run.builder.config.cmd.json() {
624622
DocumentationFormat::Json

src/bootstrap/src/core/builder/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,8 @@ impl<'a> Builder<'a> {
13751375
/// - stage 2 rustc for target2
13761376
/// However, without this optimization, we would also build stage 2 rustc for **target1**,
13771377
/// which is completely wasteful.
1378-
pub fn compiler_for_std(&self, stage: u32, target: TargetSelection) -> Compiler {
1379-
if compile::Std::should_be_uplifted_from_stage_1(self, stage, target) {
1378+
pub fn compiler_for_std(&self, stage: u32) -> Compiler {
1379+
if compile::Std::should_be_uplifted_from_stage_1(self, stage) {
13801380
self.compiler(1, self.host_target)
13811381
} else {
13821382
self.compiler(stage, self.host_target)

src/bootstrap/src/core/builder/tests.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ mod snapshot {
10541054
[build] rustc 1 <host> -> rustc 2 <target1>
10551055
[build] rustc 2 <host> -> std 2 <host>
10561056
[build] rustc 2 <host> -> std 2 <target1>
1057+
[build] rustc 1 <host> -> std 1 <target2>
10571058
[build] rustc 2 <host> -> std 2 <target2>
10581059
");
10591060
}
@@ -1283,16 +1284,15 @@ mod snapshot {
12831284
[dist] docs <target1>
12841285
[doc] rustc 1 <host> -> std 1 <host> crates=[]
12851286
[dist] rustc 1 <host> -> json-docs 2 <host>
1286-
[build] rustdoc 2 <host>
1287-
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
1288-
[dist] rustc 2 <host> -> json-docs 3 <target1>
1287+
[doc] rustc 1 <host> -> std 1 <target1> crates=[]
1288+
[dist] rustc 1 <host> -> json-docs 2 <target1>
12891289
[dist] mingw <host>
12901290
[dist] mingw <target1>
1291+
[build] rustdoc 2 <host>
12911292
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
12921293
[dist] rustc <host>
12931294
[dist] rustc 1 <host> -> std 1 <host>
1294-
[build] rustc 2 <host> -> std 2 <target1>
1295-
[dist] rustc 2 <host> -> std 2 <target1>
1295+
[dist] rustc 1 <host> -> std 1 <target1>
12961296
[dist] rustc 1 <host> -> rustc-dev 2 <host>
12971297
[dist] src <>
12981298
[dist] reproducible-artifacts <host>
@@ -1483,13 +1483,10 @@ mod snapshot {
14831483
[doc] rustc 1 <host> -> releases 2 <target1>
14841484
[build] rustc 0 <host> -> RustInstaller 1 <host>
14851485
[dist] docs <target1>
1486-
[build] rustc 1 <host> -> rustc 2 <host>
1487-
[build] rustdoc 2 <host>
1488-
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
1489-
[dist] rustc 2 <host> -> json-docs 3 <target1>
1486+
[doc] rustc 1 <host> -> std 1 <target1> crates=[]
1487+
[dist] rustc 1 <host> -> json-docs 2 <target1>
14901488
[dist] mingw <target1>
1491-
[build] rustc 2 <host> -> std 2 <target1>
1492-
[dist] rustc 2 <host> -> std 2 <target1>
1489+
[dist] rustc 1 <host> -> std 1 <target1>
14931490
");
14941491
}
14951492

0 commit comments

Comments
 (0)