@@ -577,6 +577,25 @@ impl<'a> Builder<'a> {
577577 } )
578578 }
579579
580+ /// Similar to `compiler`, except handles the full-bootstrap option to
581+ /// silently use the stage1 compiler instead of a stage2 compiler if one is
582+ /// requested.
583+ ///
584+ /// Note that this does *not* have the side effect of creating
585+ /// `compiler(stage, host)`, unlike `compiler` above which does have such
586+ /// a side effect. The returned compiler here can only be used to compile
587+ /// new artifacts, it can't be used to rely on the presence of a particular
588+ /// sysroot.
589+ ///
590+ /// See `force_use_stage1` for documentation on what each argument is.
591+ pub fn compiler_for ( & self , stage : u32 , host : Interned < String > , target : Interned < String > ) -> Compiler {
592+ if self . build . force_use_stage1 ( Compiler { stage, host } , target) {
593+ self . compiler ( 1 , self . config . build )
594+ } else {
595+ self . compiler ( stage, host)
596+ }
597+ }
598+
580599 pub fn sysroot ( & self , compiler : Compiler ) -> Interned < PathBuf > {
581600 self . ensure ( compile:: Sysroot { compiler } )
582601 }
@@ -750,11 +769,7 @@ impl<'a> Builder<'a> {
750769 // This is for the original compiler, but if we're forced to use stage 1, then
751770 // std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
752771 // we copy the libs forward.
753- let cmp = if self . force_use_stage1 ( compiler, target) {
754- self . compiler ( 1 , compiler. host )
755- } else {
756- compiler
757- } ;
772+ let cmp = self . compiler_for ( compiler. stage , compiler. host , target) ;
758773
759774 let libstd_stamp = match cmd {
760775 "check" => check:: libstd_stamp ( self , cmp, target) ,
@@ -1371,7 +1386,7 @@ mod __test {
13711386 assert_eq ! (
13721387 first( builder. cache. all:: <dist:: Std >( ) ) ,
13731388 & [ dist:: Std {
1374- compiler: Compiler { host: a, stage: 2 } ,
1389+ compiler: Compiler { host: a, stage: 1 } ,
13751390 target: a,
13761391 } , ]
13771392 ) ;
@@ -1408,7 +1423,7 @@ mod __test {
14081423 first( builder. cache. all:: <dist:: Std >( ) ) ,
14091424 & [
14101425 dist:: Std {
1411- compiler: Compiler { host: a, stage: 2 } ,
1426+ compiler: Compiler { host: a, stage: 1 } ,
14121427 target: a,
14131428 } ,
14141429 dist:: Std {
@@ -1455,18 +1470,51 @@ mod __test {
14551470 first( builder. cache. all:: <dist:: Std >( ) ) ,
14561471 & [
14571472 dist:: Std {
1458- compiler: Compiler { host: a, stage: 2 } ,
1473+ compiler: Compiler { host: a, stage: 1 } ,
14591474 target: a,
14601475 } ,
14611476 dist:: Std {
1462- compiler: Compiler { host: a, stage: 2 } ,
1477+ compiler: Compiler { host: a, stage: 1 } ,
14631478 target: b,
14641479 } ,
14651480 ]
14661481 ) ;
14671482 assert_eq ! ( first( builder. cache. all:: <dist:: Src >( ) ) , & [ dist:: Src ] ) ;
14681483 }
14691484
1485+ #[ test]
1486+ fn dist_only_cross_host ( ) {
1487+ let a = INTERNER . intern_str ( "A" ) ;
1488+ let b = INTERNER . intern_str ( "B" ) ;
1489+ let mut build = Build :: new ( configure ( & [ "B" ] , & [ ] ) ) ;
1490+ build. config . docs = false ;
1491+ build. hosts = vec ! [ b] ;
1492+ let mut builder = Builder :: new ( & build) ;
1493+ builder. run_step_descriptions ( & Builder :: get_step_descriptions ( Kind :: Dist ) , & [ ] ) ;
1494+
1495+ assert_eq ! (
1496+ first( builder. cache. all:: <dist:: Rustc >( ) ) ,
1497+ & [
1498+ dist:: Rustc {
1499+ compiler: Compiler { host: b, stage: 2 }
1500+ } ,
1501+ ]
1502+ ) ;
1503+ assert_eq ! (
1504+ first( builder. cache. all:: <compile:: Rustc >( ) ) ,
1505+ & [
1506+ compile:: Rustc {
1507+ compiler: Compiler { host: a, stage: 0 } ,
1508+ target: a,
1509+ } ,
1510+ compile:: Rustc {
1511+ compiler: Compiler { host: a, stage: 1 } ,
1512+ target: b,
1513+ } ,
1514+ ]
1515+ ) ;
1516+ }
1517+
14701518 #[ test]
14711519 fn dist_with_targets_and_hosts ( ) {
14721520 let build = Build :: new ( configure ( & [ "B" ] , & [ "C" ] ) ) ;
@@ -1508,11 +1556,11 @@ mod __test {
15081556 first( builder. cache. all:: <dist:: Std >( ) ) ,
15091557 & [
15101558 dist:: Std {
1511- compiler: Compiler { host: a, stage: 2 } ,
1559+ compiler: Compiler { host: a, stage: 1 } ,
15121560 target: a,
15131561 } ,
15141562 dist:: Std {
1515- compiler: Compiler { host: a, stage: 2 } ,
1563+ compiler: Compiler { host: a, stage: 1 } ,
15161564 target: b,
15171565 } ,
15181566 dist:: Std {
@@ -1557,11 +1605,11 @@ mod __test {
15571605 first( builder. cache. all:: <dist:: Std >( ) ) ,
15581606 & [
15591607 dist:: Std {
1560- compiler: Compiler { host: a, stage: 2 } ,
1608+ compiler: Compiler { host: a, stage: 1 } ,
15611609 target: a,
15621610 } ,
15631611 dist:: Std {
1564- compiler: Compiler { host: a, stage: 2 } ,
1612+ compiler: Compiler { host: a, stage: 1 } ,
15651613 target: b,
15661614 } ,
15671615 dist:: Std {
@@ -1608,11 +1656,11 @@ mod __test {
16081656 first( builder. cache. all:: <dist:: Std >( ) ) ,
16091657 & [
16101658 dist:: Std {
1611- compiler: Compiler { host: a, stage: 2 } ,
1659+ compiler: Compiler { host: a, stage: 1 } ,
16121660 target: a,
16131661 } ,
16141662 dist:: Std {
1615- compiler: Compiler { host: a, stage: 2 } ,
1663+ compiler: Compiler { host: a, stage: 1 } ,
16161664 target: b,
16171665 } ,
16181666 ]
@@ -1662,10 +1710,6 @@ mod __test {
16621710 compiler: Compiler { host: a, stage: 1 } ,
16631711 target: b,
16641712 } ,
1665- compile:: Test {
1666- compiler: Compiler { host: a, stage: 2 } ,
1667- target: b,
1668- } ,
16691713 ]
16701714 ) ;
16711715 assert_eq ! (
@@ -1718,10 +1762,6 @@ mod __test {
17181762 compiler: Compiler { host: b, stage: 2 } ,
17191763 target: a,
17201764 } ,
1721- compile:: Rustc {
1722- compiler: Compiler { host: a, stage: 0 } ,
1723- target: b,
1724- } ,
17251765 compile:: Rustc {
17261766 compiler: Compiler { host: a, stage: 1 } ,
17271767 target: b,
@@ -1756,10 +1796,6 @@ mod __test {
17561796 compiler: Compiler { host: b, stage: 2 } ,
17571797 target: a,
17581798 } ,
1759- compile:: Test {
1760- compiler: Compiler { host: a, stage: 0 } ,
1761- target: b,
1762- } ,
17631799 compile:: Test {
17641800 compiler: Compiler { host: a, stage: 1 } ,
17651801 target: b,
@@ -1806,9 +1842,6 @@ mod __test {
18061842 compile:: Assemble {
18071843 target_compiler: Compiler { host: a, stage: 1 } ,
18081844 } ,
1809- compile:: Assemble {
1810- target_compiler: Compiler { host: b, stage: 1 } ,
1811- } ,
18121845 compile:: Assemble {
18131846 target_compiler: Compiler { host: a, stage: 2 } ,
18141847 } ,
@@ -1828,10 +1861,6 @@ mod __test {
18281861 compiler: Compiler { host: a, stage: 1 } ,
18291862 target: a,
18301863 } ,
1831- compile:: Rustc {
1832- compiler: Compiler { host: a, stage: 0 } ,
1833- target: b,
1834- } ,
18351864 compile:: Rustc {
18361865 compiler: Compiler { host: a, stage: 1 } ,
18371866 target: b,
@@ -1858,10 +1887,6 @@ mod __test {
18581887 compiler: Compiler { host: b, stage: 2 } ,
18591888 target: a,
18601889 } ,
1861- compile:: Test {
1862- compiler: Compiler { host: a, stage: 0 } ,
1863- target: b,
1864- } ,
18651890 compile:: Test {
18661891 compiler: Compiler { host: a, stage: 1 } ,
18671892 target: b,
0 commit comments