@@ -1051,46 +1051,64 @@ macro_rules! tool_extended {
10511051 } ) ;
10521052 }
10531053
1054- #[ allow( unused_mut) ]
10551054 fn run( self , builder: & Builder <' _>) -> PathBuf {
10561055 let Self { compiler, target } = self ;
1057- let tool = builder. ensure( ToolBuild {
1056+ run_tool_build_step(
1057+ builder,
10581058 compiler,
10591059 target,
1060- tool: $tool_name,
1061- mode: Mode :: ToolRustc ,
1062- path: $path,
1063- extra_features: vec![ ] ,
1064- source_type: SourceType :: InTree ,
1065- allow_features: "" ,
1066- cargo_args: vec![ ]
1067- } ) ;
1068-
1069- if ( false $( || !$add_bins_to_sysroot. is_empty( ) ) ?) && compiler. stage > 0 {
1070- let bindir = builder. sysroot( compiler) . join( "bin" ) ;
1071- t!( fs:: create_dir_all( & bindir) ) ;
1072-
1073- #[ allow( unused_variables) ]
1074- let tools_out = builder
1075- . cargo_out( compiler, Mode :: ToolRustc , target) ;
1076-
1077- $( for add_bin in $add_bins_to_sysroot {
1078- let bin_source = tools_out. join( exe( add_bin, target) ) ;
1079- let bin_destination = bindir. join( exe( add_bin, compiler. host) ) ;
1080- builder. copy_link( & bin_source, & bin_destination) ;
1081- } ) ?
1082-
1083- let tool = bindir. join( exe( $tool_name, compiler. host) ) ;
1084- tool
1085- } else {
1086- tool
1087- }
1060+ $tool_name,
1061+ $path,
1062+ None $( . or( Some ( & $add_bins_to_sysroot) ) ) ?,
1063+ )
10881064 }
10891065 }
10901066 ) +
10911067 }
10921068}
10931069
1070+ fn run_tool_build_step (
1071+ builder : & Builder < ' _ > ,
1072+ compiler : Compiler ,
1073+ target : TargetSelection ,
1074+ tool_name : & ' static str ,
1075+ path : & ' static str ,
1076+ add_bins_to_sysroot : Option < & [ & str ] > ,
1077+ ) -> PathBuf {
1078+ let tool = builder. ensure ( ToolBuild {
1079+ compiler,
1080+ target,
1081+ tool : tool_name,
1082+ mode : Mode :: ToolRustc ,
1083+ path,
1084+ extra_features : vec ! [ ] ,
1085+ source_type : SourceType :: InTree ,
1086+ allow_features : "" ,
1087+ cargo_args : vec ! [ ] ,
1088+ } ) ;
1089+
1090+ // FIXME: This should just be an if-let-chain, but those are unstable.
1091+ if let Some ( add_bins_to_sysroot) =
1092+ add_bins_to_sysroot. filter ( |bins| !bins. is_empty ( ) && compiler. stage > 0 )
1093+ {
1094+ let bindir = builder. sysroot ( compiler) . join ( "bin" ) ;
1095+ t ! ( fs:: create_dir_all( & bindir) ) ;
1096+
1097+ let tools_out = builder. cargo_out ( compiler, Mode :: ToolRustc , target) ;
1098+
1099+ for add_bin in add_bins_to_sysroot {
1100+ let bin_source = tools_out. join ( exe ( add_bin, target) ) ;
1101+ let bin_destination = bindir. join ( exe ( add_bin, compiler. host ) ) ;
1102+ builder. copy_link ( & bin_source, & bin_destination) ;
1103+ }
1104+
1105+ // Return a path into the bin dir.
1106+ bindir. join ( exe ( tool_name, compiler. host ) )
1107+ } else {
1108+ tool
1109+ }
1110+ }
1111+
10941112tool_extended ! (
10951113 Cargofmt , "src/tools/rustfmt" , "cargo-fmt" , stable=true ;
10961114 CargoClippy , "src/tools/clippy" , "cargo-clippy" , stable=true ;
0 commit comments