@@ -1310,7 +1310,12 @@ impl<'a> Builder<'a> {
1310
1310
target : TargetSelection ,
1311
1311
cmd : & str ,
1312
1312
) -> Cargo {
1313
- let mut cargo = Command :: new ( & self . initial_cargo ) ;
1313
+ let mut cargo = if cmd == "clippy" {
1314
+ Command :: new ( self . initial_rustc . parent ( ) . unwrap ( ) . join ( "cargo-clippy" ) )
1315
+ } else {
1316
+ Command :: new ( & self . initial_cargo )
1317
+ } ;
1318
+
1314
1319
let out_dir = self . stage_out ( compiler, mode) ;
1315
1320
1316
1321
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
@@ -1391,6 +1396,22 @@ impl<'a> Builder<'a> {
1391
1396
compiler. stage
1392
1397
} ;
1393
1398
1399
+ // We synthetically interpret a stage0 compiler used to build tools as a
1400
+ // "raw" compiler in that it's the exact snapshot we download. Normally
1401
+ // the stage0 build means it uses libraries build by the stage0
1402
+ // compiler, but for tools we just use the precompiled libraries that
1403
+ // we've downloaded
1404
+ let use_snapshot = mode == Mode :: ToolBootstrap ;
1405
+ assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
1406
+
1407
+ let maybe_sysroot = self . sysroot ( compiler) ;
1408
+ let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
1409
+ let libdir = self . rustc_libdir ( compiler) ;
1410
+
1411
+ let sysroot_str = sysroot. as_os_str ( ) . to_str ( ) . expect ( "sysroot should be UTF-8" ) ;
1412
+ self . verbose_than ( 0 , & format ! ( "using sysroot {sysroot_str}" ) ) ;
1413
+ self . verbose_than ( 1 , & format ! ( "running cargo with mode {mode:?}" ) ) ;
1414
+
1394
1415
let mut rustflags = Rustflags :: new ( target) ;
1395
1416
if stage != 0 {
1396
1417
if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
@@ -1408,35 +1429,12 @@ impl<'a> Builder<'a> {
1408
1429
// NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
1409
1430
// so it has no way of knowing the sysroot.
1410
1431
rustflags. arg ( "--sysroot" ) ;
1411
- rustflags. arg (
1412
- self . sysroot ( compiler)
1413
- . as_os_str ( )
1414
- . to_str ( )
1415
- . expect ( "sysroot must be valid UTF-8" ) ,
1416
- ) ;
1432
+ rustflags. arg ( sysroot_str) ;
1417
1433
// Only run clippy on a very limited subset of crates (in particular, not build scripts).
1418
1434
cargo. arg ( "-Zunstable-options" ) ;
1419
- // Explicitly does *not* set `--cfg=bootstrap`, since we're using a nightly clippy.
1420
- let host_version = Command :: new ( "rustc" ) . arg ( "--version" ) . output ( ) . map_err ( |_| ( ) ) ;
1421
- let output = host_version. and_then ( |output| {
1422
- if output. status . success ( ) {
1423
- Ok ( output)
1424
- } else {
1425
- Err ( ( ) )
1426
- }
1427
- } ) . unwrap_or_else ( |_| {
1428
- eprintln ! (
1429
- "error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
1430
- ) ;
1431
- eprintln ! ( "help: try `rustup component add clippy`" ) ;
1432
- std:: process:: exit ( 1 ) ;
1433
- } ) ;
1434
- if !t ! ( std:: str :: from_utf8( & output. stdout) ) . contains ( "nightly" ) {
1435
- rustflags. arg ( "--cfg=bootstrap" ) ;
1436
- }
1437
- } else {
1438
- rustflags. arg ( "--cfg=bootstrap" ) ;
1439
1435
}
1436
+
1437
+ rustflags. arg ( "--cfg=bootstrap" ) ;
1440
1438
}
1441
1439
1442
1440
let use_new_symbol_mangling = match self . config . rust_new_symbol_mangling {
@@ -1556,6 +1554,10 @@ impl<'a> Builder<'a> {
1556
1554
Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => { }
1557
1555
}
1558
1556
1557
+ if self . jobs ( ) > 1 {
1558
+ //panic!("TESTING: Run with one job only!");
1559
+ }
1560
+
1559
1561
cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
1560
1562
// Remove make-related flags to ensure Cargo can correctly set things up
1561
1563
cargo. env_remove ( "MAKEFLAGS" ) ;
@@ -1609,18 +1611,6 @@ impl<'a> Builder<'a> {
1609
1611
1610
1612
let want_rustdoc = self . doc_tests != DocTests :: No ;
1611
1613
1612
- // We synthetically interpret a stage0 compiler used to build tools as a
1613
- // "raw" compiler in that it's the exact snapshot we download. Normally
1614
- // the stage0 build means it uses libraries build by the stage0
1615
- // compiler, but for tools we just use the precompiled libraries that
1616
- // we've downloaded
1617
- let use_snapshot = mode == Mode :: ToolBootstrap ;
1618
- assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
1619
-
1620
- let maybe_sysroot = self . sysroot ( compiler) ;
1621
- let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
1622
- let libdir = self . rustc_libdir ( compiler) ;
1623
-
1624
1614
// Clear the output directory if the real rustc we're using has changed;
1625
1615
// Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc.
1626
1616
//
@@ -1643,6 +1633,10 @@ impl<'a> Builder<'a> {
1643
1633
. env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
1644
1634
. env ( "RUSTC_REAL" , self . rustc ( compiler) )
1645
1635
. env ( "RUSTC_STAGE" , stage. to_string ( ) )
1636
+
1637
+ // set for clippy to know the sysroot
1638
+ . env ( "SYSROOT" , & sysroot)
1639
+
1646
1640
. env ( "RUSTC_SYSROOT" , & sysroot)
1647
1641
. env ( "RUSTC_LIBDIR" , & libdir)
1648
1642
. env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -1656,11 +1650,8 @@ impl<'a> Builder<'a> {
1656
1650
)
1657
1651
. env ( "RUSTC_ERROR_METADATA_DST" , self . extended_error_dir ( ) )
1658
1652
. env ( "RUSTC_BREAK_ON_ICE" , "1" ) ;
1659
- // Clippy support is a hack and uses the default `cargo-clippy` in path.
1660
- // Don't override RUSTC so that the `cargo-clippy` in path will be run.
1661
- if cmd != "clippy" {
1662
- cargo. env ( "RUSTC" , self . bootstrap_out . join ( "rustc" ) ) ;
1663
- }
1653
+
1654
+ cargo. env ( "RUSTC" , self . bootstrap_out . join ( "rustc" ) ) ;
1664
1655
1665
1656
// Dealing with rpath here is a little special, so let's go into some
1666
1657
// detail. First off, `-rpath` is a linker option on Unix platforms
0 commit comments