Skip to content

Commit 19e0ddb

Browse files
committed
Auto merge of #61212 - alexcrichton:skip-rustc, r=pietroalbini
ci: Attempt to skip a full rustc compile on dist* Currently when we're preparing cross-compiled compilers it can take quite some time because we have to build the compiler itself three different times. The first is the normal bootstrap, the second is a second build for the build platform, and the third is the actual target architecture compiler. The second compiler was historically built exclusively for procedural macros, and long ago we didn't actually need it. This commit tries out avoiding that second compiled compiler, meaning we only compile rustc for the build platform only once. Some local testing shows that this is promising, but bors is of course the ultimate test!
2 parents 4137901 + 7b362bb commit 19e0ddb

File tree

7 files changed

+253
-224
lines changed

7 files changed

+253
-224
lines changed

src/bootstrap/builder.rs

+82-51
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,30 @@ impl<'a> Builder<'a> {
581581
})
582582
}
583583

584+
/// Similar to `compiler`, except handles the full-bootstrap option to
585+
/// silently use the stage1 compiler instead of a stage2 compiler if one is
586+
/// requested.
587+
///
588+
/// Note that this does *not* have the side effect of creating
589+
/// `compiler(stage, host)`, unlike `compiler` above which does have such
590+
/// a side effect. The returned compiler here can only be used to compile
591+
/// new artifacts, it can't be used to rely on the presence of a particular
592+
/// sysroot.
593+
///
594+
/// See `force_use_stage1` for documentation on what each argument is.
595+
pub fn compiler_for(
596+
&self,
597+
stage: u32,
598+
host: Interned<String>,
599+
target: Interned<String>,
600+
) -> Compiler {
601+
if self.build.force_use_stage1(Compiler { stage, host }, target) {
602+
self.compiler(1, self.config.build)
603+
} else {
604+
self.compiler(stage, host)
605+
}
606+
}
607+
584608
pub fn sysroot(&self, compiler: Compiler) -> Interned<PathBuf> {
585609
self.ensure(compile::Sysroot { compiler })
586610
}
@@ -754,11 +778,7 @@ impl<'a> Builder<'a> {
754778
// This is for the original compiler, but if we're forced to use stage 1, then
755779
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
756780
// we copy the libs forward.
757-
let cmp = if self.force_use_stage1(compiler, target) {
758-
self.compiler(1, compiler.host)
759-
} else {
760-
compiler
761-
};
781+
let cmp = self.compiler_for(compiler.stage, compiler.host, target);
762782

763783
let libstd_stamp = match cmd {
764784
"check" | "clippy" | "fix" => check::libstd_stamp(self, cmp, target),
@@ -1358,7 +1378,7 @@ mod __test {
13581378

13591379
assert_eq!(
13601380
first(builder.cache.all::<dist::Docs>()),
1361-
&[dist::Docs { stage: 2, host: a },]
1381+
&[dist::Docs { host: a },]
13621382
);
13631383
assert_eq!(
13641384
first(builder.cache.all::<dist::Mingw>()),
@@ -1373,7 +1393,7 @@ mod __test {
13731393
assert_eq!(
13741394
first(builder.cache.all::<dist::Std>()),
13751395
&[dist::Std {
1376-
compiler: Compiler { host: a, stage: 2 },
1396+
compiler: Compiler { host: a, stage: 1 },
13771397
target: a,
13781398
},]
13791399
);
@@ -1392,8 +1412,8 @@ mod __test {
13921412
assert_eq!(
13931413
first(builder.cache.all::<dist::Docs>()),
13941414
&[
1395-
dist::Docs { stage: 2, host: a },
1396-
dist::Docs { stage: 2, host: b },
1415+
dist::Docs { host: a },
1416+
dist::Docs { host: b },
13971417
]
13981418
);
13991419
assert_eq!(
@@ -1410,7 +1430,7 @@ mod __test {
14101430
first(builder.cache.all::<dist::Std>()),
14111431
&[
14121432
dist::Std {
1413-
compiler: Compiler { host: a, stage: 2 },
1433+
compiler: Compiler { host: a, stage: 1 },
14141434
target: a,
14151435
},
14161436
dist::Std {
@@ -1434,8 +1454,8 @@ mod __test {
14341454
assert_eq!(
14351455
first(builder.cache.all::<dist::Docs>()),
14361456
&[
1437-
dist::Docs { stage: 2, host: a },
1438-
dist::Docs { stage: 2, host: b },
1457+
dist::Docs { host: a },
1458+
dist::Docs { host: b },
14391459
]
14401460
);
14411461
assert_eq!(
@@ -1457,18 +1477,52 @@ mod __test {
14571477
first(builder.cache.all::<dist::Std>()),
14581478
&[
14591479
dist::Std {
1460-
compiler: Compiler { host: a, stage: 2 },
1480+
compiler: Compiler { host: a, stage: 1 },
14611481
target: a,
14621482
},
14631483
dist::Std {
1464-
compiler: Compiler { host: a, stage: 2 },
1484+
compiler: Compiler { host: a, stage: 1 },
14651485
target: b,
14661486
},
14671487
]
14681488
);
14691489
assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
14701490
}
14711491

1492+
#[test]
1493+
fn dist_only_cross_host() {
1494+
let a = INTERNER.intern_str("A");
1495+
let b = INTERNER.intern_str("B");
1496+
let mut build = Build::new(configure(&["B"], &[]));
1497+
build.config.docs = false;
1498+
build.config.extended = true;
1499+
build.hosts = vec![b];
1500+
let mut builder = Builder::new(&build);
1501+
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
1502+
1503+
assert_eq!(
1504+
first(builder.cache.all::<dist::Rustc>()),
1505+
&[
1506+
dist::Rustc {
1507+
compiler: Compiler { host: b, stage: 2 }
1508+
},
1509+
]
1510+
);
1511+
assert_eq!(
1512+
first(builder.cache.all::<compile::Rustc>()),
1513+
&[
1514+
compile::Rustc {
1515+
compiler: Compiler { host: a, stage: 0 },
1516+
target: a,
1517+
},
1518+
compile::Rustc {
1519+
compiler: Compiler { host: a, stage: 1 },
1520+
target: b,
1521+
},
1522+
]
1523+
);
1524+
}
1525+
14721526
#[test]
14731527
fn dist_with_targets_and_hosts() {
14741528
let build = Build::new(configure(&["B"], &["C"]));
@@ -1482,9 +1536,9 @@ mod __test {
14821536
assert_eq!(
14831537
first(builder.cache.all::<dist::Docs>()),
14841538
&[
1485-
dist::Docs { stage: 2, host: a },
1486-
dist::Docs { stage: 2, host: b },
1487-
dist::Docs { stage: 2, host: c },
1539+
dist::Docs { host: a },
1540+
dist::Docs { host: b },
1541+
dist::Docs { host: c },
14881542
]
14891543
);
14901544
assert_eq!(
@@ -1510,11 +1564,11 @@ mod __test {
15101564
first(builder.cache.all::<dist::Std>()),
15111565
&[
15121566
dist::Std {
1513-
compiler: Compiler { host: a, stage: 2 },
1567+
compiler: Compiler { host: a, stage: 1 },
15141568
target: a,
15151569
},
15161570
dist::Std {
1517-
compiler: Compiler { host: a, stage: 2 },
1571+
compiler: Compiler { host: a, stage: 1 },
15181572
target: b,
15191573
},
15201574
dist::Std {
@@ -1541,9 +1595,9 @@ mod __test {
15411595
assert_eq!(
15421596
first(builder.cache.all::<dist::Docs>()),
15431597
&[
1544-
dist::Docs { stage: 2, host: a },
1545-
dist::Docs { stage: 2, host: b },
1546-
dist::Docs { stage: 2, host: c },
1598+
dist::Docs { host: a },
1599+
dist::Docs { host: b },
1600+
dist::Docs { host: c },
15471601
]
15481602
);
15491603
assert_eq!(
@@ -1559,11 +1613,11 @@ mod __test {
15591613
first(builder.cache.all::<dist::Std>()),
15601614
&[
15611615
dist::Std {
1562-
compiler: Compiler { host: a, stage: 2 },
1616+
compiler: Compiler { host: a, stage: 1 },
15631617
target: a,
15641618
},
15651619
dist::Std {
1566-
compiler: Compiler { host: a, stage: 2 },
1620+
compiler: Compiler { host: a, stage: 1 },
15671621
target: b,
15681622
},
15691623
dist::Std {
@@ -1587,8 +1641,8 @@ mod __test {
15871641
assert_eq!(
15881642
first(builder.cache.all::<dist::Docs>()),
15891643
&[
1590-
dist::Docs { stage: 2, host: a },
1591-
dist::Docs { stage: 2, host: b },
1644+
dist::Docs { host: a },
1645+
dist::Docs { host: b },
15921646
]
15931647
);
15941648
assert_eq!(
@@ -1610,11 +1664,11 @@ mod __test {
16101664
first(builder.cache.all::<dist::Std>()),
16111665
&[
16121666
dist::Std {
1613-
compiler: Compiler { host: a, stage: 2 },
1667+
compiler: Compiler { host: a, stage: 1 },
16141668
target: a,
16151669
},
16161670
dist::Std {
1617-
compiler: Compiler { host: a, stage: 2 },
1671+
compiler: Compiler { host: a, stage: 1 },
16181672
target: b,
16191673
},
16201674
]
@@ -1664,10 +1718,6 @@ mod __test {
16641718
compiler: Compiler { host: a, stage: 1 },
16651719
target: b,
16661720
},
1667-
compile::Test {
1668-
compiler: Compiler { host: a, stage: 2 },
1669-
target: b,
1670-
},
16711721
]
16721722
);
16731723
assert_eq!(
@@ -1720,10 +1770,6 @@ mod __test {
17201770
compiler: Compiler { host: b, stage: 2 },
17211771
target: a,
17221772
},
1723-
compile::Rustc {
1724-
compiler: Compiler { host: a, stage: 0 },
1725-
target: b,
1726-
},
17271773
compile::Rustc {
17281774
compiler: Compiler { host: a, stage: 1 },
17291775
target: b,
@@ -1758,10 +1804,6 @@ mod __test {
17581804
compiler: Compiler { host: b, stage: 2 },
17591805
target: a,
17601806
},
1761-
compile::Test {
1762-
compiler: Compiler { host: a, stage: 0 },
1763-
target: b,
1764-
},
17651807
compile::Test {
17661808
compiler: Compiler { host: a, stage: 1 },
17671809
target: b,
@@ -1808,9 +1850,6 @@ mod __test {
18081850
compile::Assemble {
18091851
target_compiler: Compiler { host: a, stage: 1 },
18101852
},
1811-
compile::Assemble {
1812-
target_compiler: Compiler { host: b, stage: 1 },
1813-
},
18141853
compile::Assemble {
18151854
target_compiler: Compiler { host: a, stage: 2 },
18161855
},
@@ -1830,10 +1869,6 @@ mod __test {
18301869
compiler: Compiler { host: a, stage: 1 },
18311870
target: a,
18321871
},
1833-
compile::Rustc {
1834-
compiler: Compiler { host: a, stage: 0 },
1835-
target: b,
1836-
},
18371872
compile::Rustc {
18381873
compiler: Compiler { host: a, stage: 1 },
18391874
target: b,
@@ -1860,10 +1895,6 @@ mod __test {
18601895
compiler: Compiler { host: b, stage: 2 },
18611896
target: a,
18621897
},
1863-
compile::Test {
1864-
compiler: Compiler { host: a, stage: 0 },
1865-
target: b,
1866-
},
18671898
compile::Test {
18681899
compiler: Compiler { host: a, stage: 1 },
18691900
target: b,

src/bootstrap/compile.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ impl Step for Std {
7070

7171
builder.ensure(StartupObjects { compiler, target });
7272

73-
if builder.force_use_stage1(compiler, target) {
74-
let from = builder.compiler(1, builder.config.build);
73+
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
74+
if compiler_to_use != compiler {
7575
builder.ensure(Std {
76-
compiler: from,
76+
compiler: compiler_to_use,
7777
target,
7878
});
79-
builder.info(&format!("Uplifting stage1 std ({} -> {})", from.host, target));
79+
builder.info(&format!("Uplifting stage1 std ({} -> {})", compiler_to_use.host, target));
8080

8181
// Even if we're not building std this stage, the new sysroot must
8282
// still contain the third party objects needed by various targets.
8383
copy_third_party_objects(builder, &compiler, target);
8484

8585
builder.ensure(StdLink {
86-
compiler: from,
86+
compiler: compiler_to_use,
8787
target_compiler: compiler,
8888
target,
8989
});
@@ -403,15 +403,16 @@ impl Step for Test {
403403
return;
404404
}
405405

406-
if builder.force_use_stage1(compiler, target) {
406+
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
407+
if compiler_to_use != compiler {
407408
builder.ensure(Test {
408-
compiler: builder.compiler(1, builder.config.build),
409+
compiler: compiler_to_use,
409410
target,
410411
});
411412
builder.info(
412413
&format!("Uplifting stage1 test ({} -> {})", builder.config.build, target));
413414
builder.ensure(TestLink {
414-
compiler: builder.compiler(1, builder.config.build),
415+
compiler: compiler_to_use,
415416
target_compiler: compiler,
416417
target,
417418
});
@@ -529,15 +530,16 @@ impl Step for Rustc {
529530
return;
530531
}
531532

532-
if builder.force_use_stage1(compiler, target) {
533+
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
534+
if compiler_to_use != compiler {
533535
builder.ensure(Rustc {
534-
compiler: builder.compiler(1, builder.config.build),
536+
compiler: compiler_to_use,
535537
target,
536538
});
537539
builder.info(&format!("Uplifting stage1 rustc ({} -> {})",
538540
builder.config.build, target));
539541
builder.ensure(RustcLink {
540-
compiler: builder.compiler(1, builder.config.build),
542+
compiler: compiler_to_use,
541543
target_compiler: compiler,
542544
target,
543545
});
@@ -687,9 +689,10 @@ impl Step for CodegenBackend {
687689
return;
688690
}
689691

690-
if builder.force_use_stage1(compiler, target) {
692+
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
693+
if compiler_to_use != compiler {
691694
builder.ensure(CodegenBackend {
692-
compiler: builder.compiler(1, builder.config.build),
695+
compiler: compiler_to_use,
693696
target,
694697
backend,
695698
});

0 commit comments

Comments
 (0)