@@ -12,7 +12,7 @@ use std::process::Command;
1212use std:: time:: { Duration , Instant } ;
1313
1414use crate :: cache:: { Cache , Interned , INTERNER } ;
15- use crate :: config:: { SplitDebuginfo , TargetSelection } ;
15+ use crate :: config:: { SplitDebuginfo , TargetSelection , DryRun } ;
1616use crate :: doc;
1717use crate :: flags:: { Color , Subcommand } ;
1818use crate :: install;
@@ -1114,7 +1114,12 @@ impl<'a> Builder<'a> {
11141114 target : TargetSelection ,
11151115 cmd : & str ,
11161116 ) -> 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+
11181123 // Run cargo from the source root so it can find .cargo/config.
11191124 // This matters when using vendoring and the working directory is outside the repository.
11201125 cargo. current_dir ( & self . src ) ;
@@ -1236,6 +1241,24 @@ impl<'a> Builder<'a> {
12361241 compiler. stage
12371242 } ;
12381243
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+
12391262 let mut rustflags = Rustflags :: new ( target) ;
12401263 if stage != 0 {
12411264 if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
@@ -1253,35 +1276,12 @@ impl<'a> Builder<'a> {
12531276 // NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
12541277 // so it has no way of knowing the sysroot.
12551278 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) ;
12621280 // Only run clippy on a very limited subset of crates (in particular, not build scripts).
12631281 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" ) ;
12841282 }
1283+
1284+ rustflags. arg ( "--cfg=bootstrap" ) ;
12851285 }
12861286
12871287 let use_new_symbol_mangling = match self . config . rust_new_symbol_mangling {
@@ -1405,6 +1405,10 @@ impl<'a> Builder<'a> {
14051405 Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => String :: new ( ) ,
14061406 } ;
14071407
1408+ if self . jobs ( ) > 1 {
1409+ //panic!("TESTING: Run with one job only!");
1410+ }
1411+
14081412 cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
14091413
14101414 // FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005
@@ -1455,18 +1459,6 @@ impl<'a> Builder<'a> {
14551459
14561460 let want_rustdoc = self . doc_tests != DocTests :: No ;
14571461
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-
14701462 // Clear the output directory if the real rustc we're using has changed;
14711463 // Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc.
14721464 //
@@ -1489,6 +1481,11 @@ impl<'a> Builder<'a> {
14891481 . env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
14901482 . env ( "RUSTC_REAL" , self . rustc ( compiler) )
14911483 . 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+
14921489 . env ( "RUSTC_SYSROOT" , & sysroot)
14931490 . env ( "RUSTC_LIBDIR" , & libdir)
14941491 . env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -1502,11 +1499,8 @@ impl<'a> Builder<'a> {
15021499 )
15031500 . env ( "RUSTC_ERROR_METADATA_DST" , self . extended_error_dir ( ) )
15041501 . 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" ) ) ;
15101504
15111505 // Dealing with rpath here is a little special, so let's go into some
15121506 // detail. First off, `-rpath` is a linker option on Unix platforms
0 commit comments