@@ -13,7 +13,7 @@ use std::process::Command;
13
13
use std:: time:: { Duration , Instant } ;
14
14
15
15
use crate :: cache:: { Cache , Interned , INTERNER } ;
16
- use crate :: config:: { SplitDebuginfo , TargetSelection } ;
16
+ use crate :: config:: { SplitDebuginfo , TargetSelection , DryRun } ;
17
17
use crate :: doc;
18
18
use crate :: flags:: { Color , Subcommand } ;
19
19
use crate :: install;
@@ -1171,7 +1171,12 @@ impl<'a> Builder<'a> {
1171
1171
target : TargetSelection ,
1172
1172
cmd : & str ,
1173
1173
) -> Command {
1174
- let mut cargo = Command :: new ( & self . initial_cargo ) ;
1174
+ let mut cargo = if cmd == "clippy" {
1175
+ Command :: new ( self . initial_rustc . parent ( ) . unwrap ( ) . join ( "cargo-clippy" ) )
1176
+ } else {
1177
+ Command :: new ( & self . initial_cargo )
1178
+ } ;
1179
+
1175
1180
// Run cargo from the source root so it can find .cargo/config.
1176
1181
// This matters when using vendoring and the working directory is outside the repository.
1177
1182
cargo. current_dir ( & self . src ) ;
@@ -1293,6 +1298,24 @@ impl<'a> Builder<'a> {
1293
1298
compiler. stage
1294
1299
} ;
1295
1300
1301
+ // We synthetically interpret a stage0 compiler used to build tools as a
1302
+ // "raw" compiler in that it's the exact snapshot we download. Normally
1303
+ // the stage0 build means it uses libraries build by the stage0
1304
+ // compiler, but for tools we just use the precompiled libraries that
1305
+ // we've downloaded
1306
+ let use_snapshot = mode == Mode :: ToolBootstrap ;
1307
+ assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
1308
+
1309
+ let maybe_sysroot = self . sysroot ( compiler) ;
1310
+ let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
1311
+ let libdir = self . rustc_libdir ( compiler) ;
1312
+
1313
+ let sysroot_str = sysroot. as_os_str ( ) . to_str ( ) . expect ( "sysroot should be UTF-8" ) ;
1314
+ if !matches ! ( self . config. dry_run, DryRun :: SelfCheck ) {
1315
+ self . verbose_than ( 0 , & format ! ( "using sysroot {sysroot_str}" ) ) ;
1316
+ self . verbose_than ( 1 , & format ! ( "running cargo with mode {mode:?}" ) ) ;
1317
+ }
1318
+
1296
1319
let mut rustflags = Rustflags :: new ( target) ;
1297
1320
if stage != 0 {
1298
1321
if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
@@ -1310,35 +1333,12 @@ impl<'a> Builder<'a> {
1310
1333
// NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
1311
1334
// so it has no way of knowing the sysroot.
1312
1335
rustflags. arg ( "--sysroot" ) ;
1313
- rustflags. arg (
1314
- self . sysroot ( compiler)
1315
- . as_os_str ( )
1316
- . to_str ( )
1317
- . expect ( "sysroot must be valid UTF-8" ) ,
1318
- ) ;
1336
+ rustflags. arg ( sysroot_str) ;
1319
1337
// Only run clippy on a very limited subset of crates (in particular, not build scripts).
1320
1338
cargo. arg ( "-Zunstable-options" ) ;
1321
- // Explicitly does *not* set `--cfg=bootstrap`, since we're using a nightly clippy.
1322
- let host_version = Command :: new ( "rustc" ) . arg ( "--version" ) . output ( ) . map_err ( |_| ( ) ) ;
1323
- let output = host_version. and_then ( |output| {
1324
- if output. status . success ( ) {
1325
- Ok ( output)
1326
- } else {
1327
- Err ( ( ) )
1328
- }
1329
- } ) . unwrap_or_else ( |_| {
1330
- eprintln ! (
1331
- "error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
1332
- ) ;
1333
- eprintln ! ( "help: try `rustup component add clippy`" ) ;
1334
- crate :: detail_exit_macro!( 1 ) ;
1335
- } ) ;
1336
- if !t ! ( std:: str :: from_utf8( & output. stdout) ) . contains ( "nightly" ) {
1337
- rustflags. arg ( "--cfg=bootstrap" ) ;
1338
- }
1339
- } else {
1340
- rustflags. arg ( "--cfg=bootstrap" ) ;
1341
1339
}
1340
+
1341
+ rustflags. arg ( "--cfg=bootstrap" ) ;
1342
1342
}
1343
1343
1344
1344
let use_new_symbol_mangling = match self . config . rust_new_symbol_mangling {
@@ -1470,6 +1470,10 @@ impl<'a> Builder<'a> {
1470
1470
Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => String :: new ( ) ,
1471
1471
} ;
1472
1472
1473
+ if self . jobs ( ) > 1 {
1474
+ //panic!("TESTING: Run with one job only!");
1475
+ }
1476
+
1473
1477
cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
1474
1478
1475
1479
// FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
@@ -1520,18 +1524,6 @@ impl<'a> Builder<'a> {
1520
1524
1521
1525
let want_rustdoc = self . doc_tests != DocTests :: No ;
1522
1526
1523
- // We synthetically interpret a stage0 compiler used to build tools as a
1524
- // "raw" compiler in that it's the exact snapshot we download. Normally
1525
- // the stage0 build means it uses libraries build by the stage0
1526
- // compiler, but for tools we just use the precompiled libraries that
1527
- // we've downloaded
1528
- let use_snapshot = mode == Mode :: ToolBootstrap ;
1529
- assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
1530
-
1531
- let maybe_sysroot = self . sysroot ( compiler) ;
1532
- let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
1533
- let libdir = self . rustc_libdir ( compiler) ;
1534
-
1535
1527
// Clear the output directory if the real rustc we're using has changed;
1536
1528
// Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc.
1537
1529
//
@@ -1554,6 +1546,11 @@ impl<'a> Builder<'a> {
1554
1546
. env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
1555
1547
. env ( "RUSTC_REAL" , self . rustc ( compiler) )
1556
1548
. env ( "RUSTC_STAGE" , stage. to_string ( ) )
1549
+
1550
+ // set for clippy to know the sysroot
1551
+ . env ( "SYSROOT" , & sysroot)
1552
+ . env ( "RUSTC_COMMAND" , cmd)
1553
+
1557
1554
. env ( "RUSTC_SYSROOT" , & sysroot)
1558
1555
. env ( "RUSTC_LIBDIR" , & libdir)
1559
1556
. env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -1567,11 +1564,8 @@ impl<'a> Builder<'a> {
1567
1564
)
1568
1565
. env ( "RUSTC_ERROR_METADATA_DST" , self . extended_error_dir ( ) )
1569
1566
. env ( "RUSTC_BREAK_ON_ICE" , "1" ) ;
1570
- // Clippy support is a hack and uses the default `cargo-clippy` in path.
1571
- // Don't override RUSTC so that the `cargo-clippy` in path will be run.
1572
- if cmd != "clippy" {
1573
- cargo. env ( "RUSTC" , self . bootstrap_out . join ( "rustc" ) ) ;
1574
- }
1567
+
1568
+ cargo. env ( "RUSTC" , self . bootstrap_out . join ( "rustc" ) ) ;
1575
1569
1576
1570
// Dealing with rpath here is a little special, so let's go into some
1577
1571
// detail. First off, `-rpath` is a linker option on Unix platforms
0 commit comments