@@ -1310,7 +1310,12 @@ impl<'a> Builder<'a> {
13101310 target : TargetSelection ,
13111311 cmd : & str ,
13121312 ) -> 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+
13141319 let out_dir = self . stage_out ( compiler, mode) ;
13151320
13161321 // Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
@@ -1391,6 +1396,22 @@ impl<'a> Builder<'a> {
13911396 compiler. stage
13921397 } ;
13931398
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+
13941415 let mut rustflags = Rustflags :: new ( target) ;
13951416 if stage != 0 {
13961417 if let Ok ( s) = env:: var ( "CARGOFLAGS_NOT_BOOTSTRAP" ) {
@@ -1408,35 +1429,12 @@ impl<'a> Builder<'a> {
14081429 // NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
14091430 // so it has no way of knowing the sysroot.
14101431 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) ;
14171433 // Only run clippy on a very limited subset of crates (in particular, not build scripts).
14181434 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" ) ;
14391435 }
1436+
1437+ rustflags. arg ( "--cfg=bootstrap" ) ;
14401438 }
14411439
14421440 let use_new_symbol_mangling = match self . config . rust_new_symbol_mangling {
@@ -1556,6 +1554,10 @@ impl<'a> Builder<'a> {
15561554 Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => { }
15571555 }
15581556
1557+ if self . jobs ( ) > 1 {
1558+ //panic!("TESTING: Run with one job only!");
1559+ }
1560+
15591561 cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
15601562 // Remove make-related flags to ensure Cargo can correctly set things up
15611563 cargo. env_remove ( "MAKEFLAGS" ) ;
@@ -1609,18 +1611,6 @@ impl<'a> Builder<'a> {
16091611
16101612 let want_rustdoc = self . doc_tests != DocTests :: No ;
16111613
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-
16241614 // Clear the output directory if the real rustc we're using has changed;
16251615 // Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc.
16261616 //
@@ -1643,6 +1633,10 @@ impl<'a> Builder<'a> {
16431633 . env ( "RUSTBUILD_NATIVE_DIR" , self . native_dir ( target) )
16441634 . env ( "RUSTC_REAL" , self . rustc ( compiler) )
16451635 . env ( "RUSTC_STAGE" , stage. to_string ( ) )
1636+
1637+ // set for clippy to know the sysroot
1638+ . env ( "SYSROOT" , & sysroot)
1639+
16461640 . env ( "RUSTC_SYSROOT" , & sysroot)
16471641 . env ( "RUSTC_LIBDIR" , & libdir)
16481642 . env ( "RUSTDOC" , self . bootstrap_out . join ( "rustdoc" ) )
@@ -1656,11 +1650,8 @@ impl<'a> Builder<'a> {
16561650 )
16571651 . env ( "RUSTC_ERROR_METADATA_DST" , self . extended_error_dir ( ) )
16581652 . 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" ) ) ;
16641655
16651656 // Dealing with rpath here is a little special, so let's go into some
16661657 // detail. First off, `-rpath` is a linker option on Unix platforms
0 commit comments