8
8
//! out to `rust-installer` still. This may one day be replaced with bits and
9
9
//! pieces of `rustup.rs`!
10
10
11
+ use std:: collections:: HashSet ;
11
12
use std:: env;
12
13
use std:: fs;
13
14
use std:: path:: { Path , PathBuf } ;
@@ -45,6 +46,18 @@ fn missing_tool(tool_name: &str, skip: bool) {
45
46
}
46
47
}
47
48
49
+ fn should_build_extended_tool ( builder : & Builder < ' _ > , tool : & str ) -> bool {
50
+ if !builder. config . extended {
51
+ return false ;
52
+ }
53
+
54
+ if let Some ( tools) = & builder. config . tools {
55
+ tools. is_empty ( ) || tools. contains ( tool)
56
+ } else {
57
+ true
58
+ }
59
+ }
60
+
48
61
#[ derive( Debug , PartialOrd , Ord , Copy , Clone , Hash , PartialEq , Eq ) ]
49
62
pub struct Docs {
50
63
pub host : TargetSelection ,
@@ -671,11 +684,10 @@ pub struct Analysis {
671
684
672
685
impl Step for Analysis {
673
686
type Output = Option < GeneratedTarball > ;
674
- const DEFAULT : bool = true ;
675
687
676
688
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
677
- let builder = run. builder ;
678
- run. path ( "analysis" ) . default_condition ( builder . config . extended )
689
+ let default = should_build_extended_tool ( & run. builder , "analysis" ) ;
690
+ run. path ( "analysis" ) . default_condition ( default )
679
691
}
680
692
681
693
fn make_run ( run : RunConfig < ' _ > ) {
@@ -696,7 +708,6 @@ impl Step for Analysis {
696
708
fn run ( self , builder : & Builder < ' _ > ) -> Option < GeneratedTarball > {
697
709
let compiler = self . compiler ;
698
710
let target = self . target ;
699
- assert ! ( builder. config. extended) ;
700
711
if compiler. host != builder. config . build {
701
712
return None ;
702
713
}
@@ -955,7 +966,8 @@ impl Step for Cargo {
955
966
const ONLY_HOSTS : bool = true ;
956
967
957
968
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
958
- run. path ( "cargo" )
969
+ let default = should_build_extended_tool ( & run. builder , "cargo" ) ;
970
+ run. path ( "cargo" ) . default_condition ( default)
959
971
}
960
972
961
973
fn make_run ( run : RunConfig < ' _ > ) {
@@ -1009,7 +1021,8 @@ impl Step for Rls {
1009
1021
const ONLY_HOSTS : bool = true ;
1010
1022
1011
1023
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1012
- run. path ( "rls" )
1024
+ let default = should_build_extended_tool ( & run. builder , "rls" ) ;
1025
+ run. path ( "rls" ) . default_condition ( default)
1013
1026
}
1014
1027
1015
1028
fn make_run ( run : RunConfig < ' _ > ) {
@@ -1026,7 +1039,6 @@ impl Step for Rls {
1026
1039
fn run ( self , builder : & Builder < ' _ > ) -> Option < GeneratedTarball > {
1027
1040
let compiler = self . compiler ;
1028
1041
let target = self . target ;
1029
- assert ! ( builder. config. extended) ;
1030
1042
1031
1043
let rls = builder
1032
1044
. ensure ( tool:: Rls { compiler, target, extra_features : Vec :: new ( ) } )
@@ -1055,7 +1067,8 @@ impl Step for RustAnalyzer {
1055
1067
const ONLY_HOSTS : bool = true ;
1056
1068
1057
1069
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1058
- run. path ( "rust-analyzer" )
1070
+ let default = should_build_extended_tool ( & run. builder , "rust-analyzer" ) ;
1071
+ run. path ( "rust-analyzer" ) . default_condition ( default)
1059
1072
}
1060
1073
1061
1074
fn make_run ( run : RunConfig < ' _ > ) {
@@ -1078,7 +1091,6 @@ impl Step for RustAnalyzer {
1078
1091
}
1079
1092
let compiler = self . compiler ;
1080
1093
let target = self . target ;
1081
- assert ! ( builder. config. extended) ;
1082
1094
1083
1095
if target. contains ( "riscv64" ) {
1084
1096
// riscv64 currently has an LLVM bug that makes rust-analyzer unable
@@ -1110,7 +1122,8 @@ impl Step for Clippy {
1110
1122
const ONLY_HOSTS : bool = true ;
1111
1123
1112
1124
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1113
- run. path ( "clippy" )
1125
+ let default = should_build_extended_tool ( & run. builder , "clippy" ) ;
1126
+ run. path ( "clippy" ) . default_condition ( default)
1114
1127
}
1115
1128
1116
1129
fn make_run ( run : RunConfig < ' _ > ) {
@@ -1127,7 +1140,6 @@ impl Step for Clippy {
1127
1140
fn run ( self , builder : & Builder < ' _ > ) -> Option < GeneratedTarball > {
1128
1141
let compiler = self . compiler ;
1129
1142
let target = self . target ;
1130
- assert ! ( builder. config. extended) ;
1131
1143
1132
1144
// Prepare the image directory
1133
1145
// We expect clippy to build, because we've exited this step above if tool
@@ -1160,7 +1172,8 @@ impl Step for Miri {
1160
1172
const ONLY_HOSTS : bool = true ;
1161
1173
1162
1174
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1163
- run. path ( "miri" )
1175
+ let default = should_build_extended_tool ( & run. builder , "miri" ) ;
1176
+ run. path ( "miri" ) . default_condition ( default)
1164
1177
}
1165
1178
1166
1179
fn make_run ( run : RunConfig < ' _ > ) {
@@ -1183,7 +1196,6 @@ impl Step for Miri {
1183
1196
}
1184
1197
let compiler = self . compiler ;
1185
1198
let target = self . target ;
1186
- assert ! ( builder. config. extended) ;
1187
1199
1188
1200
let miri = builder
1189
1201
. ensure ( tool:: Miri { compiler, target, extra_features : Vec :: new ( ) } )
@@ -1219,7 +1231,8 @@ impl Step for Rustfmt {
1219
1231
const ONLY_HOSTS : bool = true ;
1220
1232
1221
1233
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1222
- run. path ( "rustfmt" )
1234
+ let default = should_build_extended_tool ( & run. builder , "rustfmt" ) ;
1235
+ run. path ( "rustfmt" ) . default_condition ( default)
1223
1236
}
1224
1237
1225
1238
fn make_run ( run : RunConfig < ' _ > ) {
@@ -1344,6 +1357,17 @@ impl Step for Extended {
1344
1357
builder. info ( & format ! ( "Dist extended stage{} ({})" , compiler. stage, target) ) ;
1345
1358
1346
1359
let mut tarballs = Vec :: new ( ) ;
1360
+ let mut built_tools = HashSet :: new ( ) ;
1361
+ macro_rules! add_tool {
1362
+ ( $name: expr => $step: expr) => {
1363
+ if should_build_extended_tool( builder, $name) {
1364
+ if let Some ( tarball) = builder. ensure( $step) {
1365
+ tarballs. push( tarball) ;
1366
+ built_tools. insert( $name) ;
1367
+ }
1368
+ }
1369
+ } ;
1370
+ }
1347
1371
1348
1372
// When rust-std package split from rustc, we needed to ensure that during
1349
1373
// upgrades rustc was upgraded before rust-std. To avoid rustc clobbering
@@ -1356,16 +1380,17 @@ impl Step for Extended {
1356
1380
tarballs. push ( builder. ensure ( Docs { host : target } ) ) ;
1357
1381
}
1358
1382
1359
- let cargo_installer = builder. ensure ( Cargo { compiler, target } ) ;
1360
- let rustfmt_installer = builder. ensure ( Rustfmt { compiler, target } ) ;
1383
+ add_tool ! ( "cargo" => Cargo { compiler, target } ) ;
1384
+ add_tool ! ( "rustfmt" => Rustfmt { compiler, target } ) ;
1385
+ add_tool ! ( "rls" => Rls { compiler, target } ) ;
1386
+ add_tool ! ( "rust-analyzer" => RustAnalyzer { compiler, target } ) ;
1387
+ add_tool ! ( "llvm-tools" => LlvmTools { target } ) ;
1388
+ add_tool ! ( "clippy" => Clippy { compiler, target } ) ;
1389
+ add_tool ! ( "miri" => Miri { compiler, target } ) ;
1390
+ add_tool ! ( "analysis" => Analysis { compiler, target } ) ;
1391
+
1361
1392
let rust_demangler_installer = builder. ensure ( RustDemangler { compiler, target } ) ;
1362
- let rls_installer = builder. ensure ( Rls { compiler, target } ) ;
1363
- let rust_analyzer_installer = builder. ensure ( RustAnalyzer { compiler, target } ) ;
1364
- let llvm_tools_installer = builder. ensure ( LlvmTools { target } ) ;
1365
- let clippy_installer = builder. ensure ( Clippy { compiler, target } ) ;
1366
- let miri_installer = builder. ensure ( Miri { compiler, target } ) ;
1367
1393
let mingw_installer = builder. ensure ( Mingw { host : target } ) ;
1368
- let analysis_installer = builder. ensure ( Analysis { compiler, target } ) ;
1369
1394
1370
1395
let etc = builder. src . join ( "src/etc/installer" ) ;
1371
1396
@@ -1374,17 +1399,8 @@ impl Step for Extended {
1374
1399
return ;
1375
1400
}
1376
1401
1377
- tarballs. extend ( cargo_installer) ;
1378
- tarballs. extend ( clippy_installer) ;
1379
1402
tarballs. extend ( rust_demangler_installer. clone ( ) ) ;
1380
- tarballs. extend ( rls_installer. clone ( ) ) ;
1381
- tarballs. extend ( rust_analyzer_installer. clone ( ) ) ;
1382
- tarballs. extend ( miri_installer. clone ( ) ) ;
1383
- tarballs. extend ( rustfmt_installer. clone ( ) ) ;
1384
- tarballs. extend ( llvm_tools_installer) ;
1385
- if let Some ( analysis_installer) = analysis_installer {
1386
- tarballs. push ( analysis_installer) ;
1387
- }
1403
+
1388
1404
if target. contains ( "pc-windows-gnu" ) {
1389
1405
tarballs. push ( mingw_installer. unwrap ( ) ) ;
1390
1406
}
@@ -1434,17 +1450,11 @@ impl Step for Extended {
1434
1450
if rust_demangler_installer. is_none ( ) {
1435
1451
contents = filter ( & contents, "rust-demangler" ) ;
1436
1452
}
1437
- if rls_installer. is_none ( ) {
1438
- contents = filter ( & contents, "rls" ) ;
1439
- }
1440
- if rust_analyzer_installer. is_none ( ) {
1441
- contents = filter ( & contents, "rust-analyzer" ) ;
1442
- }
1443
- if miri_installer. is_none ( ) {
1444
- contents = filter ( & contents, "miri" ) ;
1445
- }
1446
- if rustfmt_installer. is_none ( ) {
1447
- contents = filter ( & contents, "rustfmt" ) ;
1453
+
1454
+ for tool in & [ "rls" , "rust-analyzer" , "miri" , "rustfmt" ] {
1455
+ if !built_tools. contains ( tool) {
1456
+ contents = filter ( & contents, tool) ;
1457
+ }
1448
1458
}
1449
1459
let ret = tmp. join ( p. file_name ( ) . unwrap ( ) ) ;
1450
1460
t ! ( fs:: write( & ret, & contents) ) ;
@@ -1485,16 +1495,11 @@ impl Step for Extended {
1485
1495
if rust_demangler_installer. is_some ( ) {
1486
1496
prepare ( "rust-demangler" ) ;
1487
1497
}
1488
- if rls_installer. is_some ( ) {
1489
- prepare ( "rls" ) ;
1490
- }
1491
- if rust_analyzer_installer. is_some ( ) {
1492
- prepare ( "rust-analyzer" ) ;
1493
- }
1494
- if miri_installer. is_some ( ) {
1495
- prepare ( "miri" ) ;
1498
+ for tool in & [ "rls" , "rust-analyzer" , "miri" ] {
1499
+ if built_tools. contains ( tool) {
1500
+ prepare ( tool) ;
1501
+ }
1496
1502
}
1497
-
1498
1503
// create an 'uninstall' package
1499
1504
builder. install ( & etc. join ( "pkg/postinstall" ) , & pkg. join ( "uninstall" ) , 0o755 ) ;
1500
1505
pkgbuild ( "uninstall" ) ;
@@ -1554,14 +1559,10 @@ impl Step for Extended {
1554
1559
if rust_demangler_installer. is_some ( ) {
1555
1560
prepare ( "rust-demangler" ) ;
1556
1561
}
1557
- if rls_installer. is_some ( ) {
1558
- prepare ( "rls" ) ;
1559
- }
1560
- if rust_analyzer_installer. is_some ( ) {
1561
- prepare ( "rust-analyzer" ) ;
1562
- }
1563
- if miri_installer. is_some ( ) {
1564
- prepare ( "miri" ) ;
1562
+ for tool in & [ "rls" , "rust-analyzer" , "miri" ] {
1563
+ if built_tools. contains ( tool) {
1564
+ prepare ( tool) ;
1565
+ }
1565
1566
}
1566
1567
if target. contains ( "windows-gnu" ) {
1567
1568
prepare ( "rust-mingw" ) ;
@@ -1640,7 +1641,7 @@ impl Step for Extended {
1640
1641
. arg ( "-out" )
1641
1642
. arg ( exe. join ( "StdGroup.wxs" ) ) ,
1642
1643
) ;
1643
- if rls_installer . is_some ( ) {
1644
+ if built_tools . contains ( "rls" ) {
1644
1645
builder. run (
1645
1646
Command :: new ( & heat)
1646
1647
. current_dir ( & exe)
@@ -1659,7 +1660,7 @@ impl Step for Extended {
1659
1660
. arg ( etc. join ( "msi/remove-duplicates.xsl" ) ) ,
1660
1661
) ;
1661
1662
}
1662
- if rust_analyzer_installer . is_some ( ) {
1663
+ if built_tools . contains ( "rust-analyzer" ) {
1663
1664
builder. run (
1664
1665
Command :: new ( & heat)
1665
1666
. current_dir ( & exe)
@@ -1714,7 +1715,7 @@ impl Step for Extended {
1714
1715
. arg ( etc. join ( "msi/remove-duplicates.xsl" ) ) ,
1715
1716
) ;
1716
1717
}
1717
- if miri_installer . is_some ( ) {
1718
+ if built_tools . contains ( "miri" ) {
1718
1719
builder. run (
1719
1720
Command :: new ( & heat)
1720
1721
. current_dir ( & exe)
@@ -1790,13 +1791,13 @@ impl Step for Extended {
1790
1791
if rust_demangler_installer. is_some ( ) {
1791
1792
cmd. arg ( "-dRustDemanglerDir=rust-demangler" ) ;
1792
1793
}
1793
- if rls_installer . is_some ( ) {
1794
+ if built_tools . contains ( "rls" ) {
1794
1795
cmd. arg ( "-dRlsDir=rls" ) ;
1795
1796
}
1796
- if rust_analyzer_installer . is_some ( ) {
1797
+ if built_tools . contains ( "rust-analyzer" ) {
1797
1798
cmd. arg ( "-dRustAnalyzerDir=rust-analyzer" ) ;
1798
1799
}
1799
- if miri_installer . is_some ( ) {
1800
+ if built_tools . contains ( "miri" ) {
1800
1801
cmd. arg ( "-dMiriDir=miri" ) ;
1801
1802
}
1802
1803
if target. contains ( "windows-gnu" ) {
@@ -1815,13 +1816,13 @@ impl Step for Extended {
1815
1816
if rust_demangler_installer. is_some ( ) {
1816
1817
candle ( "RustDemanglerGroup.wxs" . as_ref ( ) ) ;
1817
1818
}
1818
- if rls_installer . is_some ( ) {
1819
+ if built_tools . contains ( "rls" ) {
1819
1820
candle ( "RlsGroup.wxs" . as_ref ( ) ) ;
1820
1821
}
1821
- if rust_analyzer_installer . is_some ( ) {
1822
+ if built_tools . contains ( "rust-analyzer" ) {
1822
1823
candle ( "RustAnalyzerGroup.wxs" . as_ref ( ) ) ;
1823
1824
}
1824
- if miri_installer . is_some ( ) {
1825
+ if built_tools . contains ( "miri" ) {
1825
1826
candle ( "MiriGroup.wxs" . as_ref ( ) ) ;
1826
1827
}
1827
1828
candle ( "AnalysisGroup.wxs" . as_ref ( ) ) ;
@@ -1855,16 +1856,16 @@ impl Step for Extended {
1855
1856
. arg ( "ClippyGroup.wixobj" )
1856
1857
. current_dir ( & exe) ;
1857
1858
1858
- if rls_installer . is_some ( ) {
1859
+ if built_tools . contains ( "rls" ) {
1859
1860
cmd. arg ( "RlsGroup.wixobj" ) ;
1860
1861
}
1861
- if rust_analyzer_installer . is_some ( ) {
1862
+ if built_tools . contains ( "rust-analyzer" ) {
1862
1863
cmd. arg ( "RustAnalyzerGroup.wixobj" ) ;
1863
1864
}
1864
1865
if rust_demangler_installer. is_some ( ) {
1865
1866
cmd. arg ( "RustDemanglerGroup.wixobj" ) ;
1866
1867
}
1867
- if miri_installer . is_some ( ) {
1868
+ if built_tools . contains ( "miri" ) {
1868
1869
cmd. arg ( "MiriGroup.wixobj" ) ;
1869
1870
}
1870
1871
@@ -1994,7 +1995,8 @@ impl Step for LlvmTools {
1994
1995
const ONLY_HOSTS : bool = true ;
1995
1996
1996
1997
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1997
- run. path ( "llvm-tools" )
1998
+ let default = should_build_extended_tool ( & run. builder , "llvm-tools" ) ;
1999
+ run. path ( "llvm-tools" ) . default_condition ( default)
1998
2000
}
1999
2001
2000
2002
fn make_run ( run : RunConfig < ' _ > ) {
@@ -2003,7 +2005,6 @@ impl Step for LlvmTools {
2003
2005
2004
2006
fn run ( self , builder : & Builder < ' _ > ) -> Option < GeneratedTarball > {
2005
2007
let target = self . target ;
2006
- assert ! ( builder. config. extended) ;
2007
2008
2008
2009
/* run only if llvm-config isn't used */
2009
2010
if let Some ( config) = builder. config . target_config . get ( & target) {
0 commit comments