@@ -12,7 +12,7 @@ use std::process::Command;
12
12
use std:: time:: { Duration , Instant } ;
13
13
14
14
use crate :: cache:: { Cache , Interned , INTERNER } ;
15
- use crate :: config:: { SplitDebuginfo , TargetSelection } ;
15
+ use crate :: config:: { SplitDebuginfo , TargetSelection , DryRun } ;
16
16
use crate :: doc;
17
17
use crate :: flags:: { Color , Subcommand } ;
18
18
use crate :: install;
@@ -1114,7 +1114,12 @@ impl<'a> Builder<'a> {
1114
1114
target : TargetSelection ,
1115
1115
cmd : & str ,
1116
1116
) -> Command {
1117
- let mut cargo = Command :: new ( & self . initial_cargo ) ;
1117
+ let mut cargo = if cmd == "clippy" {
1118
+ Command :: new ( self . initial_rustc . parent ( ) . unwrap ( ) . join ( "cargo-clippy" ) )
1119
+ } else {
1120
+ Command :: new ( & self . initial_cargo )
1121
+ } ;
1122
+
1118
1123
// Run cargo from the source root so it can find .cargo/config.
1119
1124
// This matters when using vendoring and the working directory is outside the repository.
1120
1125
cargo. current_dir ( & self . src ) ;
@@ -1236,6 +1241,24 @@ impl<'a> Builder<'a> {
1236
1241
compiler. stage
1237
1242
} ;
1238
1243
1244
+ // We synthetically interpret a stage0 compiler used to build tools as a
1245
+ // "raw" compiler in that it's the exact snapshot we download. Normally
1246
+ // the stage0 build means it uses libraries build by the stage0
1247
+ // compiler, but for tools we just use the precompiled libraries that
1248
+ // we've downloaded
1249
+ let use_snapshot = mode == Mode :: ToolBootstrap ;
1250
+ assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
1251
+
1252
+ let maybe_sysroot = self . sysroot ( compiler) ;
1253
+ let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
1254
+ let libdir = self . rustc_libdir ( compiler) ;
1255
+
1256
+ let sysroot_str = sysroot. as_os_str ( ) . to_str ( ) . expect ( "sysroot should be UTF-8" ) ;
1257
+ if !matches ! ( self . config. dry_run, DryRun :: SelfCheck ) {
1258
+ self . verbose_than ( 0 , & format ! ( "using sysroot {sysroot_str}" ) ) ;
1259
+ self . verbose_than ( 1 , & format ! ( "running cargo with mode {mode:?}" ) ) ;
1260
+ }
1261
+
1239
1262
let mut rustflags = Rustflags :: new ( target) ;
1240
1263
if stage != 0 {
1241
1264
if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
@@ -1253,35 +1276,12 @@ impl<'a> Builder<'a> {
1253
1276
// NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
1254
1277
// so it has no way of knowing the sysroot.
1255
1278
rustflags. arg ( "--sysroot" ) ;
1256
- rustflags. arg (
1257
- self . sysroot ( compiler)
1258
- . as_os_str ( )
1259
- . to_str ( )
1260
- . expect ( "sysroot must be valid UTF-8" ) ,
1261
- ) ;
1279
+ rustflags. arg ( sysroot_str) ;
1262
1280
// Only run clippy on a very limited subset of crates (in particular, not build scripts).
1263
1281
cargo. arg ( "-Zunstable-options" ) ;
1264
- // Explicitly does *not* set `--cfg=bootstrap`, since we're using a nightly clippy.
1265
- let host_version = Command :: new ( "rustc" ) . arg ( "--version" ) . output ( ) . map_err ( |_| ( ) ) ;
1266
- let output = host_version. and_then ( |output| {
1267
- if output. status . success ( ) {
1268
- Ok ( output)
1269
- } else {
1270
- Err ( ( ) )
1271
- }
1272
- } ) . unwrap_or_else ( |_| {
1273
- eprintln ! (
1274
- "error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
1275
- ) ;
1276
- eprintln ! ( "help: try `rustup component add clippy`" ) ;
1277
- crate :: detail_exit ( 1 ) ;
1278
- } ) ;
1279
- if !t ! ( std:: str :: from_utf8( & output. stdout) ) . contains ( "nightly" ) {
1280
- rustflags. arg ( "--cfg=bootstrap" ) ;
1281
- }
1282
- } else {
1283
- rustflags. arg ( "--cfg=bootstrap" ) ;
1284
1282
}
1283
+
1284
+ rustflags. arg ( "--cfg=bootstrap" ) ;
1285
1285
}
1286
1286
1287
1287
let use_new_symbol_mangling = match self . config . rust_new_symbol_mangling {
@@ -1405,6 +1405,10 @@ impl<'a> Builder<'a> {
1405
1405
Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => String :: new ( ) ,
1406
1406
} ;
1407
1407
1408
+ if self . jobs ( ) > 1 {
1409
+ //panic!("TESTING: Run with one job only!");
1410
+ }
1411
+
1408
1412
cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
1409
1413
1410
1414
// FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
@@ -1455,18 +1459,6 @@ impl<'a> Builder<'a> {
1455
1459
1456
1460
let want_rustdoc = self . doc_tests != DocTests :: No ;
1457
1461
1458
- // We synthetically interpret a stage0 compiler used to build tools as a
1459
- // "raw" compiler in that it's the exact snapshot we download. Normally
1460
- // the stage0 build means it uses libraries build by the stage0
1461
- // compiler, but for tools we just use the precompiled libraries that
1462
- // we've downloaded
1463
- let use_snapshot = mode == Mode :: ToolBootstrap ;
1464
- assert ! ( !use_snapshot || stage == 0 || self . local_rebuild) ;
1465
-
1466
- let maybe_sysroot = self . sysroot ( compiler) ;
1467
- let sysroot = if use_snapshot { self . rustc_snapshot_sysroot ( ) } else { & maybe_sysroot } ;
1468
- let libdir = self . rustc_libdir ( compiler) ;
1469
-
1470
1462
// Clear the output directory if the real rustc we're using has changed;
1471
1463
// Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc.
1472
1464
//
@@ -1489,6 +1481,11 @@ impl<'a> Builder<'a> {
1489
1481
. env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
1490
1482
. env ( "RUSTC_REAL" , self . rustc ( compiler) )
1491
1483
. env ( "RUSTC_STAGE" , stage. to_string ( ) )
1484
+
1485
+ // set for clippy to know the sysroot
1486
+ . env ( "SYSROOT" , & sysroot)
1487
+ . env ( "RUSTC_COMMAND" , cmd)
1488
+
1492
1489
. env ( "RUSTC_SYSROOT" , & sysroot)
1493
1490
. env ( "RUSTC_LIBDIR" , & libdir)
1494
1491
. env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -1502,11 +1499,8 @@ impl<'a> Builder<'a> {
1502
1499
)
1503
1500
. env ( "RUSTC_ERROR_METADATA_DST" , self . extended_error_dir ( ) )
1504
1501
. env ( "RUSTC_BREAK_ON_ICE" , "1" ) ;
1505
- // Clippy support is a hack and uses the default `cargo-clippy` in path.
1506
- // Don't override RUSTC so that the `cargo-clippy` in path will be run.
1507
- if cmd != "clippy" {
1508
- cargo. env ( "RUSTC" , self . bootstrap_out . join ( "rustc" ) ) ;
1509
- }
1502
+
1503
+ cargo. env ( "RUSTC" , self . bootstrap_out . join ( "rustc" ) ) ;
1510
1504
1511
1505
// Dealing with rpath here is a little special, so let's go into some
1512
1506
// detail. First off, `-rpath` is a linker option on Unix platforms
0 commit comments