Skip to content

Commit 6058f7f

Browse files
committed
Use compiler_for_std in dist::Std
1 parent 63cbf59 commit 6058f7f

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
@@ -1110,9 +1110,8 @@ mod snapshot {
11101110
[doc] book/2018-edition (book) <host>
11111111
[build] rustdoc 1 <host>
11121112
[doc] rustc 1 <host> -> standalone 2 <host>
1113+
[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]
11131114
[build] rustc 1 <host> -> rustc 2 <host>
1114-
[build] rustdoc 2 <host>
1115-
[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]
11161115
[build] rustc 1 <host> -> error-index 2 <host>
11171116
[doc] rustc 1 <host> -> error-index 2 <host>
11181117
[doc] nomicon (book) <host>
@@ -1129,9 +1128,10 @@ mod snapshot {
11291128
[doc] rustc 1 <host> -> releases 2 <host>
11301129
[build] rustc 0 <host> -> RustInstaller 1 <host>
11311130
[dist] docs <host>
1132-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1133-
[dist] rustc 2 <host> -> json-docs 3 <host>
1131+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1132+
[dist] rustc 1 <host> -> json-docs 2 <host>
11341133
[dist] mingw <host>
1134+
[build] rustdoc 2 <host>
11351135
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
11361136
[dist] rustc <host>
11371137
[dist] rustc 1 <host> -> std 1 <host>
@@ -1171,12 +1171,11 @@ mod snapshot {
11711171
[doc] book/2018-edition (book) <host>
11721172
[build] rustdoc 1 <host>
11731173
[doc] rustc 1 <host> -> standalone 2 <host>
1174+
[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]
11741175
[build] rustc 1 <host> -> rustc 2 <host>
11751176
[build] rustc 1 <host> -> LldWrapper 2 <host>
11761177
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
11771178
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
1178-
[build] rustdoc 2 <host>
1179-
[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]
11801179
[build] rustc 1 <host> -> error-index 2 <host>
11811180
[doc] rustc 1 <host> -> error-index 2 <host>
11821181
[doc] nomicon (book) <host>
@@ -1193,9 +1192,10 @@ mod snapshot {
11931192
[doc] rustc 1 <host> -> releases 2 <host>
11941193
[build] rustc 0 <host> -> RustInstaller 1 <host>
11951194
[dist] docs <host>
1196-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1197-
[dist] rustc 2 <host> -> json-docs 3 <host>
1195+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1196+
[dist] rustc 1 <host> -> json-docs 2 <host>
11981197
[dist] mingw <host>
1198+
[build] rustdoc 2 <host>
11991199
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host>
12001200
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
12011201
[dist] rustc <host>
@@ -1216,6 +1216,8 @@ mod snapshot {
12161216
[build] rustc 1 <host> -> miri 2 <host>
12171217
[build] rustc 1 <host> -> cargo-miri 2 <host>
12181218
[dist] rustc 1 <host> -> miri 2 <host>
1219+
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1220+
[dist] rustc 2 <host> -> json-docs 3 <host>
12191221
[dist] rustc 1 <host> -> extended 2 <host>
12201222
[dist] reproducible-artifacts <host>
12211223
");
@@ -1249,10 +1251,9 @@ mod snapshot {
12491251
[doc] book/2018-edition (book) <target1>
12501252
[doc] rustc 1 <host> -> standalone 2 <host>
12511253
[doc] rustc 1 <host> -> standalone 2 <target1>
1254+
[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]
1255+
[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]
12521256
[build] rustc 1 <host> -> rustc 2 <host>
1253-
[build] rustdoc 2 <host>
1254-
[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]
1255-
[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]
12561257
[build] rustc 1 <host> -> error-index 2 <host>
12571258
[doc] rustc 1 <host> -> error-index 2 <host>
12581259
[doc] nomicon (book) <host>
@@ -1280,8 +1281,9 @@ mod snapshot {
12801281
[build] rustc 0 <host> -> RustInstaller 1 <host>
12811282
[dist] docs <host>
12821283
[dist] docs <target1>
1283-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1284-
[dist] rustc 2 <host> -> json-docs 3 <host>
1284+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1285+
[dist] rustc 1 <host> -> json-docs 2 <host>
1286+
[build] rustdoc 2 <host>
12851287
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
12861288
[dist] rustc 2 <host> -> json-docs 3 <target1>
12871289
[dist] mingw <host>
@@ -1319,9 +1321,8 @@ mod snapshot {
13191321
[doc] book/2018-edition (book) <host>
13201322
[build] rustdoc 1 <host>
13211323
[doc] rustc 1 <host> -> standalone 2 <host>
1324+
[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]
13221325
[build] rustc 1 <host> -> rustc 2 <host>
1323-
[build] rustdoc 2 <host>
1324-
[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]
13251326
[build] rustc 1 <host> -> error-index 2 <host>
13261327
[doc] rustc 1 <host> -> error-index 2 <host>
13271328
[build] llvm <target1>
@@ -1344,9 +1345,10 @@ mod snapshot {
13441345
[doc] rustc 1 <host> -> releases 2 <host>
13451346
[build] rustc 0 <host> -> RustInstaller 1 <host>
13461347
[dist] docs <host>
1347-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1348-
[dist] rustc 2 <host> -> json-docs 3 <host>
1348+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1349+
[dist] rustc 1 <host> -> json-docs 2 <host>
13491350
[dist] mingw <host>
1351+
[build] rustdoc 2 <host>
13501352
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
13511353
[dist] rustc <host>
13521354
[build] rustdoc 2 <target1>
@@ -1389,10 +1391,9 @@ mod snapshot {
13891391
[doc] book/2018-edition (book) <target1>
13901392
[doc] rustc 1 <host> -> standalone 2 <host>
13911393
[doc] rustc 1 <host> -> standalone 2 <target1>
1394+
[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]
1395+
[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]
13921396
[build] rustc 1 <host> -> rustc 2 <host>
1393-
[build] rustdoc 2 <host>
1394-
[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]
1395-
[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]
13961397
[build] rustc 1 <host> -> error-index 2 <host>
13971398
[doc] rustc 1 <host> -> error-index 2 <host>
13981399
[build] llvm <target1>
@@ -1425,12 +1426,13 @@ mod snapshot {
14251426
[build] rustc 0 <host> -> RustInstaller 1 <host>
14261427
[dist] docs <host>
14271428
[dist] docs <target1>
1428-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1429-
[dist] rustc 2 <host> -> json-docs 3 <host>
1430-
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
1431-
[dist] rustc 2 <host> -> json-docs 3 <target1>
1429+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1430+
[dist] rustc 1 <host> -> json-docs 2 <host>
1431+
[doc] rustc 1 <host> -> std 1 <target1> crates=[]
1432+
[dist] rustc 1 <host> -> json-docs 2 <target1>
14321433
[dist] mingw <host>
14331434
[dist] mingw <target1>
1435+
[build] rustdoc 2 <host>
14341436
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
14351437
[dist] rustc <host>
14361438
[build] rustdoc 2 <target1>
@@ -1468,9 +1470,7 @@ mod snapshot {
14681470
[build] rustdoc 1 <host>
14691471
[build] rustc 1 <host> -> std 1 <host>
14701472
[doc] rustc 1 <host> -> standalone 2 <target1>
1471-
[build] rustc 1 <host> -> rustc 2 <host>
1472-
[build] rustdoc 2 <host>
1473-
[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]
1473+
[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]
14741474
[doc] nomicon (book) <target1>
14751475
[doc] rustc 1 <host> -> reference (book) 2 <target1>
14761476
[doc] rustdoc (book) <target1>
@@ -1483,6 +1483,8 @@ 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>
14861488
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
14871489
[dist] rustc 2 <host> -> json-docs 3 <target1>
14881490
[dist] mingw <target1>
@@ -1515,10 +1517,7 @@ mod snapshot {
15151517
[build] rustdoc 1 <host>
15161518
[build] rustc 1 <host> -> std 1 <host>
15171519
[doc] rustc 1 <host> -> standalone 2 <target1>
1518-
[build] rustc 1 <host> -> rustc 2 <host>
1519-
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
1520-
[build] rustdoc 2 <host>
1521-
[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]
1520+
[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]
15221521
[build] llvm <target1>
15231522
[build] rustc 1 <host> -> rustc 2 <target1>
15241523
[build] rustc 1 <host> -> WasmComponentLd 2 <target1>
@@ -1538,8 +1537,8 @@ mod snapshot {
15381537
[doc] rustc 1 <host> -> releases 2 <target1>
15391538
[build] rustc 0 <host> -> RustInstaller 1 <host>
15401539
[dist] docs <target1>
1541-
[doc] rustc 2 <host> -> std 2 <target1> crates=[]
1542-
[dist] rustc 2 <host> -> json-docs 3 <target1>
1540+
[doc] rustc 1 <host> -> std 1 <target1> crates=[]
1541+
[dist] rustc 1 <host> -> json-docs 2 <target1>
15431542
[dist] mingw <target1>
15441543
[build] rustdoc 2 <target1>
15451544
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <target1>
@@ -1571,7 +1570,7 @@ mod snapshot {
15711570
}
15721571

15731572
/// Simulates e.g. the powerpc64 builder, which is fully cross-compiled from x64, but it does
1574-
/// not build docs. Crutically, it shouldn't build host stage 2 rustc.
1573+
/// not build docs. Crucially, it shouldn't build host stage 2 rustc.
15751574
///
15761575
/// This is a regression test for <https://github.com/rust-lang/rust/issues/138123>
15771576
/// and <https://github.com/rust-lang/rust/issues/138004>.
@@ -1661,10 +1660,9 @@ mod snapshot {
16611660
[doc] book/2018-edition (book) <host>
16621661
[build] rustdoc 1 <host>
16631662
[doc] rustc 1 <host> -> standalone 2 <host>
1663+
[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]
16641664
[build] rustc 1 <host> -> rustc 2 <host>
16651665
[build] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
1666-
[build] rustdoc 2 <host>
1667-
[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]
16681666
[build] rustc 1 <host> -> error-index 2 <host>
16691667
[doc] rustc 1 <host> -> error-index 2 <host>
16701668
[doc] nomicon (book) <host>
@@ -1681,9 +1679,10 @@ mod snapshot {
16811679
[doc] rustc 1 <host> -> releases 2 <host>
16821680
[build] rustc 0 <host> -> RustInstaller 1 <host>
16831681
[dist] docs <host>
1684-
[doc] rustc 2 <host> -> std 2 <host> crates=[]
1685-
[dist] rustc 2 <host> -> json-docs 3 <host>
1682+
[doc] rustc 1 <host> -> std 1 <host> crates=[]
1683+
[dist] rustc 1 <host> -> json-docs 2 <host>
16861684
[dist] mingw <host>
1685+
[build] rustdoc 2 <host>
16871686
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
16881687
[dist] rustc <host>
16891688
[dist] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
@@ -1727,9 +1726,8 @@ mod snapshot {
17271726
[doc] book/2018-edition (book) <host>
17281727
[build] rustdoc 1 <host>
17291728
[doc] rustc 1 <host> -> standalone 2 <host>
1729+
[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]
17301730
[build] rustc 1 <host> -> rustc 2 <host>
1731-
[build] rustdoc 2 <host>
1732-
[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]
17331731
[build] rustc 1 <host> -> error-index 2 <host>
17341732
[doc] rustc 1 <host> -> error-index 2 <host>
17351733
[doc] nomicon (book) <host>
@@ -2439,10 +2437,9 @@ mod snapshot {
24392437
[doc] book/2018-edition (book) <host>
24402438
[build] rustdoc 1 <host>
24412439
[doc] rustc 1 <host> -> standalone 2 <host>
2440+
[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]
24422441
[build] rustc 1 <host> -> rustc 2 <host>
24432442
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
2444-
[build] rustdoc 2 <host>
2445-
[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]
24462443
[build] rustc 1 <host> -> error-index 2 <host>
24472444
[doc] rustc 1 <host> -> error-index 2 <host>
24482445
[doc] nomicon (book) <host>
@@ -2460,6 +2457,7 @@ mod snapshot {
24602457
[build] rustc 0 <host> -> RustInstaller 1 <host>
24612458
[dist] docs <host>
24622459
[dist] rustc 1 <host> -> std 1 <host>
2460+
[build] rustdoc 2 <host>
24632461
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host>
24642462
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
24652463
[dist] rustc <host>

0 commit comments

Comments
 (0)