Skip to content

Commit 41563c7

Browse files
committed
Use compiler_for_std in dist::Std
1 parent edcdb80 commit 41563c7

File tree

4 files changed

+59
-59
lines changed

4 files changed

+59
-59
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ impl Step for Std {
150150
trace!(force_recompile);
151151

152152
run.builder.ensure(Std {
153-
build_compiler: run.builder.compiler_for_std(run.builder.top_stage, run.target),
153+
// Note: we don't use compiler_for_std here, so that `x build library --stage 2`
154+
// builds a stage2 rustc.
155+
build_compiler: run.builder.compiler(run.builder.top_stage, builder.host_target),
154156
target: run.target,
155157
crates,
156158
force_recompile,

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -769,22 +769,7 @@ pub struct Std {
769769

770770
impl Std {
771771
pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self {
772-
// This is an important optimization mainly for CI.
773-
// Normally, to build stage N libstd, we need stage N rustc.
774-
// However, if we know that we will uplift libstd from stage 1 anyway, building the stage N
775-
// rustc can be wasteful.
776-
// In particular, if we do a cross-compiling dist stage 2 build from T1 to T2, we need:
777-
// - stage 2 libstd for T2 (uplifted from stage 1, where it was built by T1 rustc)
778-
// - stage 2 rustc for T2
779-
// However, without this optimization, we would also build stage 2 rustc for **T1**, which
780-
// is completely wasteful.
781-
let build_compiler =
782-
if compile::Std::should_be_uplifted_from_stage_1(builder, builder.top_stage, target) {
783-
builder.compiler(1, builder.host_target)
784-
} else {
785-
builder.compiler(builder.top_stage, builder.host_target)
786-
};
787-
Std { build_compiler, target }
772+
Std { build_compiler: builder.compiler_for_std(builder.top_stage, target), target }
788773
}
789774
}
790775

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,21 @@ impl<'a> Builder<'a> {
13601360
self.ensure(compile::Assemble { target_compiler: Compiler::new(stage, host) })
13611361
}
13621362

1363+
/// This function can be used to provide a build compiler for building
1364+
/// the standard library, in order to avoid unnecessary rustc builds in case where std uplifting
1365+
/// would happen anyway.
1366+
///
1367+
/// This is an important optimization mainly for CI.
1368+
///
1369+
/// Normally, to build stage N libstd, we need stage N rustc.
1370+
/// However, if we know that we will uplift libstd from stage 1 anyway, building the stage N
1371+
/// rustc can be wasteful.
1372+
/// In particular, if we do a cross-compiling dist stage 2 build from target1 to target2,
1373+
/// we need:
1374+
/// - stage 2 libstd for target2 (uplifted from stage 1, where it was built by target1 rustc)
1375+
/// - stage 2 rustc for target2
1376+
/// However, without this optimization, we would also build stage 2 rustc for **target1**,
1377+
/// which is completely wasteful.
13631378
pub fn compiler_for_std(&self, stage: u32, target: TargetSelection) -> Compiler {
13641379
if compile::Std::should_be_uplifted_from_stage_1(self, stage, target) {
13651380
self.compiler(1, self.host_target)

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

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,9 +1122,8 @@ mod snapshot {
11221122
[doc] book/2018-edition (book) <host>
11231123
[build] rustdoc 1 <host>
11241124
[doc] rustc 1 <host> -> standalone 2 <host>
1125+
[doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
11251126
[build] rustc 1 <host> -> rustc 2 <host>
1126-
[build] rustdoc 2 <host>
1127-
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
11281127
[build] rustc 1 <host> -> error-index 2 <host>
11291128
[doc] rustc 1 <host> -> error-index 2 <host>
11301129
[doc] nomicon (book) <host>
@@ -1141,9 +1140,10 @@ mod snapshot {
11411140
[doc] rustc 1 <host> -> releases 2 <host>
11421141
[build] rustc 0 <host> -> RustInstaller 1 <host>
11431142
[dist] docs <host>
1144-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1145-
[dist] rustc 2 <host> -> json-docs 3 <host>
1143+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1144+
[dist] rustc 1 <host> -> json-docs 2 <host>
11461145
[dist] mingw <host>
1146+
[build] rustdoc 2 <host>
11471147
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
11481148
[dist] rustc <host>
11491149
[dist] rustc 1 <host> -> std 1 <host>
@@ -1183,12 +1183,11 @@ mod snapshot {
11831183
[doc] book/2018-edition (book) <host>
11841184
[build] rustdoc 1 <host>
11851185
[doc] rustc 1 <host> -> standalone 2 <host>
1186+
[doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
11861187
[build] rustc 1 <host> -> rustc 2 <host>
11871188
[build] rustc 1 <host> -> LldWrapper 2 <host>
11881189
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
11891190
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
1190-
[build] rustdoc 2 <host>
1191-
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
11921191
[build] rustc 1 <host> -> error-index 2 <host>
11931192
[doc] rustc 1 <host> -> error-index 2 <host>
11941193
[doc] nomicon (book) <host>
@@ -1205,9 +1204,10 @@ mod snapshot {
12051204
[doc] rustc 1 <host> -> releases 2 <host>
12061205
[build] rustc 0 <host> -> RustInstaller 1 <host>
12071206
[dist] docs <host>
1208-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1209-
[dist] rustc 2 <host> -> json-docs 3 <host>
1207+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1208+
[dist] rustc 1 <host> -> json-docs 2 <host>
12101209
[dist] mingw <host>
1210+
[build] rustdoc 2 <host>
12111211
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host>
12121212
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
12131213
[dist] rustc <host>
@@ -1228,6 +1228,8 @@ mod snapshot {
12281228
[build] rustc 1 <host> -> miri 2 <host>
12291229
[build] rustc 1 <host> -> cargo-miri 2 <host>
12301230
[dist] rustc 1 <host> -> miri 2 <host>
1231+
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1232+
[dist] rustc 2 <host> -> json-docs 3 <host>
12311233
[dist] rustc 1 <host> -> extended 2 <host>
12321234
[dist] reproducible-artifacts <host>
12331235
");
@@ -1261,10 +1263,9 @@ mod snapshot {
12611263
[doc] book/2018-edition (book) <target1>
12621264
[doc] rustc 1 <host> -> standalone 2 <host>
12631265
[doc] rustc 1 <host> -> standalone 2 <target1>
1266+
[doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1267+
[doc] rustc 1 <host> -> std 1 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
12641268
[build] rustc 1 <host> -> rustc 2 <host>
1265-
[build] rustdoc 2 <host>
1266-
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1267-
[doc] rustc 2 <host> -> std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
12681269
[build] rustc 1 <host> -> error-index 2 <host>
12691270
[doc] rustc 1 <host> -> error-index 2 <host>
12701271
[doc] nomicon (book) <host>
@@ -1292,8 +1293,9 @@ mod snapshot {
12921293
[build] rustc 0 <host> -> RustInstaller 1 <host>
12931294
[dist] docs <host>
12941295
[dist] docs <target1>
1295-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1296-
[dist] rustc 2 <host> -> json-docs 3 <host>
1296+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1297+
[dist] rustc 1 <host> -> json-docs 2 <host>
1298+
[build] rustdoc 2 <host>
12971299
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
12981300
[dist] rustc 2 <host> -> json-docs 3 <target1>
12991301
[dist] mingw <host>
@@ -1331,9 +1333,8 @@ mod snapshot {
13311333
[doc] book/2018-edition (book) <host>
13321334
[build] rustdoc 1 <host>
13331335
[doc] rustc 1 <host> -> standalone 2 <host>
1336+
[doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
13341337
[build] rustc 1 <host> -> rustc 2 <host>
1335-
[build] rustdoc 2 <host>
1336-
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
13371338
[build] rustc 1 <host> -> error-index 2 <host>
13381339
[doc] rustc 1 <host> -> error-index 2 <host>
13391340
[build] llvm <target1>
@@ -1356,9 +1357,10 @@ mod snapshot {
13561357
[doc] rustc 1 <host> -> releases 2 <host>
13571358
[build] rustc 0 <host> -> RustInstaller 1 <host>
13581359
[dist] docs <host>
1359-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1360-
[dist] rustc 2 <host> -> json-docs 3 <host>
1360+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1361+
[dist] rustc 1 <host> -> json-docs 2 <host>
13611362
[dist] mingw <host>
1363+
[build] rustdoc 2 <host>
13621364
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
13631365
[dist] rustc <host>
13641366
[build] rustdoc 2 <target1>
@@ -1401,10 +1403,9 @@ mod snapshot {
14011403
[doc] book/2018-edition (book) <target1>
14021404
[doc] rustc 1 <host> -> standalone 2 <host>
14031405
[doc] rustc 1 <host> -> standalone 2 <target1>
1406+
[doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1407+
[doc] rustc 1 <host> -> std 1 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
14041408
[build] rustc 1 <host> -> rustc 2 <host>
1405-
[build] rustdoc 2 <host>
1406-
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1407-
[doc] rustc 2 <host> -> std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
14081409
[build] rustc 1 <host> -> error-index 2 <host>
14091410
[doc] rustc 1 <host> -> error-index 2 <host>
14101411
[build] llvm <target1>
@@ -1437,12 +1438,13 @@ mod snapshot {
14371438
[build] rustc 0 <host> -> RustInstaller 1 <host>
14381439
[dist] docs <host>
14391440
[dist] docs <target1>
1440-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1441-
[dist] rustc 2 <host> -> json-docs 3 <host>
1442-
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
1443-
[dist] rustc 2 <host> -> json-docs 3 <target1>
1441+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1442+
[dist] rustc 1 <host> -> json-docs 2 <host>
1443+
[doc] rustc 1 <host> -> std 1 <target1> crates=[]
1444+
[dist] rustc 1 <host> -> json-docs 2 <target1>
14441445
[dist] mingw <host>
14451446
[dist] mingw <target1>
1447+
[build] rustdoc 2 <host>
14461448
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
14471449
[dist] rustc <host>
14481450
[build] rustdoc 2 <target1>
@@ -1480,9 +1482,7 @@ mod snapshot {
14801482
[build] rustdoc 1 <host>
14811483
[build] rustc 1 <host> -> std 1 <host>
14821484
[doc] rustc 1 <host> -> standalone 2 <target1>
1483-
[build] rustc 1 <host> -> rustc 2 <host>
1484-
[build] rustdoc 2 <host>
1485-
[doc] rustc 2 <host> -> std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1485+
[doc] rustc 1 <host> -> std 1 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
14861486
[doc] nomicon (book) <target1>
14871487
[doc] rustc 1 <host> -> reference (book) 2 <target1>
14881488
[doc] rustdoc (book) <target1>
@@ -1495,6 +1495,8 @@ mod snapshot {
14951495
[doc] rustc 1 <host> -> releases 2 <target1>
14961496
[build] rustc 0 <host> -> RustInstaller 1 <host>
14971497
[dist] docs <target1>
1498+
[build] rustc 1 <host> -> rustc 2 <host>
1499+
[build] rustdoc 2 <host>
14981500
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
14991501
[dist] rustc 2 <host> -> json-docs 3 <target1>
15001502
[dist] mingw <target1>
@@ -1527,10 +1529,7 @@ mod snapshot {
15271529
[build] rustdoc 1 <host>
15281530
[build] rustc 1 <host> -> std 1 <host>
15291531
[doc] rustc 1 <host> -> standalone 2 <target1>
1530-
[build] rustc 1 <host> -> rustc 2 <host>
1531-
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
1532-
[build] rustdoc 2 <host>
1533-
[doc] rustc 2 <host> -> std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
1532+
[doc] rustc 1 <host> -> std 1 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
15341533
[build] llvm <target1>
15351534
[build] rustc 1 <host> -> rustc 2 <target1>
15361535
[build] rustc 1 <host> -> WasmComponentLd 2 <target1>
@@ -1550,8 +1549,8 @@ mod snapshot {
15501549
[doc] rustc 1 <host> -> releases 2 <target1>
15511550
[build] rustc 0 <host> -> RustInstaller 1 <host>
15521551
[dist] docs <target1>
1553-
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
1554-
[dist] rustc 2 <host> -> json-docs 3 <target1>
1552+
[doc] rustc 1 <host> -> std 1 <target1> crates=[]
1553+
[dist] rustc 1 <host> -> json-docs 2 <target1>
15551554
[dist] mingw <target1>
15561555
[build] rustdoc 2 <target1>
15571556
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <target1>
@@ -1583,7 +1582,7 @@ mod snapshot {
15831582
}
15841583

15851584
/// Simulates e.g. the powerpc64 builder, which is fully cross-compiled from x64, but it does
1586-
/// not build docs. Crutically, it shouldn't build host stage 2 rustc.
1585+
/// not build docs. Crucially, it shouldn't build host stage 2 rustc.
15871586
///
15881587
/// This is a regression test for <https://github.com/rust-lang/rust/issues/138123>
15891588
/// and <https://github.com/rust-lang/rust/issues/138004>.
@@ -1673,10 +1672,9 @@ mod snapshot {
16731672
[doc] book/2018-edition (book) <host>
16741673
[build] rustdoc 1 <host>
16751674
[doc] rustc 1 <host> -> standalone 2 <host>
1675+
[doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
16761676
[build] rustc 1 <host> -> rustc 2 <host>
16771677
[build] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
1678-
[build] rustdoc 2 <host>
1679-
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
16801678
[build] rustc 1 <host> -> error-index 2 <host>
16811679
[doc] rustc 1 <host> -> error-index 2 <host>
16821680
[doc] nomicon (book) <host>
@@ -1693,9 +1691,10 @@ mod snapshot {
16931691
[doc] rustc 1 <host> -> releases 2 <host>
16941692
[build] rustc 0 <host> -> RustInstaller 1 <host>
16951693
[dist] docs <host>
1696-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1697-
[dist] rustc 2 <host> -> json-docs 3 <host>
1694+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1695+
[dist] rustc 1 <host> -> json-docs 2 <host>
16981696
[dist] mingw <host>
1697+
[build] rustdoc 2 <host>
16991698
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
17001699
[dist] rustc <host>
17011700
[dist] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
@@ -1755,9 +1754,8 @@ mod snapshot {
17551754
[doc] book/2018-edition (book) <host>
17561755
[build] rustdoc 1 <host>
17571756
[doc] rustc 1 <host> -> standalone 2 <host>
1757+
[doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
17581758
[build] rustc 1 <host> -> rustc 2 <host>
1759-
[build] rustdoc 2 <host>
1760-
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
17611759
[build] rustc 1 <host> -> error-index 2 <host>
17621760
[doc] rustc 1 <host> -> error-index 2 <host>
17631761
[doc] nomicon (book) <host>
@@ -2467,10 +2465,9 @@ mod snapshot {
24672465
[doc] book/2018-edition (book) <host>
24682466
[build] rustdoc 1 <host>
24692467
[doc] rustc 1 <host> -> standalone 2 <host>
2468+
[doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
24702469
[build] rustc 1 <host> -> rustc 2 <host>
24712470
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
2472-
[build] rustdoc 2 <host>
2473-
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
24742471
[build] rustc 1 <host> -> error-index 2 <host>
24752472
[doc] rustc 1 <host> -> error-index 2 <host>
24762473
[doc] nomicon (book) <host>
@@ -2488,6 +2485,7 @@ mod snapshot {
24882485
[build] rustc 0 <host> -> RustInstaller 1 <host>
24892486
[dist] docs <host>
24902487
[dist] rustc 1 <host> -> std 1 <host>
2488+
[build] rustdoc 2 <host>
24912489
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host>
24922490
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
24932491
[dist] rustc <host>

0 commit comments

Comments
 (0)