@@ -1007,102 +1007,150 @@ impl Step for LibcxxVersionTool {
10071007}
10081008
10091009macro_rules! tool_extended {
1010- ( ( $sel: ident, $builder: ident) ,
1011- $( $name: ident,
1012- $path: expr,
1013- $tool_name: expr,
1014- stable = $stable: expr
1015- $( , tool_std = $tool_std: literal) ?
1016- $( , allow_features = $allow_features: expr) ?
1017- $( , add_bins_to_sysroot = $add_bins_to_sysroot: expr) ?
1018- ; ) +) => {
1019- $(
1020- #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
1010+ (
1011+ $name: ident {
1012+ path: $path: expr,
1013+ tool_name: $tool_name: expr,
1014+ stable: $stable: expr
1015+ $( , add_bins_to_sysroot: $add_bins_to_sysroot: expr ) ?
1016+ $( , ) ?
1017+ }
1018+ ) => {
1019+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
10211020 pub struct $name {
10221021 pub compiler: Compiler ,
10231022 pub target: TargetSelection ,
1024- pub extra_features: Vec <String >,
10251023 }
10261024
10271025 impl Step for $name {
10281026 type Output = PathBuf ;
1029- const DEFAULT : bool = true ; // Overwritten below
1027+ const DEFAULT : bool = true ; // Overridden by `should_run_tool_build_step`
10301028 const ONLY_HOSTS : bool = true ;
10311029
10321030 fn should_run( run: ShouldRun <' _>) -> ShouldRun <' _> {
1033- let builder = run. builder;
1034- run. path( $path) . default_condition(
1035- builder. config. extended
1036- && builder. config. tools. as_ref( ) . map_or(
1037- // By default, on nightly/dev enable all tools, else only
1038- // build stable tools.
1039- $stable || builder. build. unstable_features( ) ,
1040- // If `tools` is set, search list for this tool.
1041- |tools| {
1042- tools. iter( ) . any( |tool| match tool. as_ref( ) {
1043- "clippy" => $tool_name == "clippy-driver" ,
1044- x => $tool_name == x,
1045- } )
1046- } ) ,
1031+ should_run_tool_build_step(
1032+ run,
1033+ $tool_name,
1034+ $path,
1035+ $stable,
10471036 )
10481037 }
10491038
10501039 fn make_run( run: RunConfig <' _>) {
10511040 run. builder. ensure( $name {
10521041 compiler: run. builder. compiler( run. builder. top_stage, run. builder. config. build) ,
10531042 target: run. target,
1054- extra_features: Vec :: new( ) ,
10551043 } ) ;
10561044 }
10571045
1058- #[ allow( unused_mut) ]
1059- fn run( mut $sel, $builder: & Builder <' _>) -> PathBuf {
1060- let tool = $builder. ensure( ToolBuild {
1061- compiler: $sel. compiler,
1062- target: $sel. target,
1063- tool: $tool_name,
1064- mode: if false $( || $tool_std) ? { Mode :: ToolStd } else { Mode :: ToolRustc } ,
1065- path: $path,
1066- extra_features: $sel. extra_features,
1067- source_type: SourceType :: InTree ,
1068- allow_features: concat!( $( $allow_features) * ) ,
1069- cargo_args: vec![ ]
1070- } ) ;
1071-
1072- if ( false $( || !$add_bins_to_sysroot. is_empty( ) ) ?) && $sel. compiler. stage > 0 {
1073- let bindir = $builder. sysroot( $sel. compiler) . join( "bin" ) ;
1074- t!( fs:: create_dir_all( & bindir) ) ;
1075-
1076- #[ allow( unused_variables) ]
1077- let tools_out = $builder
1078- . cargo_out( $sel. compiler, Mode :: ToolRustc , $sel. target) ;
1046+ fn run( self , builder: & Builder <' _>) -> PathBuf {
1047+ let Self { compiler, target } = self ;
1048+ run_tool_build_step(
1049+ builder,
1050+ compiler,
1051+ target,
1052+ $tool_name,
1053+ $path,
1054+ None $( . or( Some ( & $add_bins_to_sysroot) ) ) ?,
1055+ )
1056+ }
1057+ }
1058+ }
1059+ }
10791060
1080- $( for add_bin in $add_bins_to_sysroot {
1081- let bin_source = tools_out. join( exe( add_bin, $sel. target) ) ;
1082- let bin_destination = bindir. join( exe( add_bin, $sel. compiler. host) ) ;
1083- $builder. copy_link( & bin_source, & bin_destination) ;
1084- } ) ?
1061+ fn should_run_tool_build_step < ' a > (
1062+ run : ShouldRun < ' a > ,
1063+ tool_name : & ' static str ,
1064+ path : & ' static str ,
1065+ stable : bool ,
1066+ ) -> ShouldRun < ' a > {
1067+ let builder = run. builder ;
1068+ run. path ( path) . default_condition (
1069+ builder. config . extended
1070+ && builder. config . tools . as_ref ( ) . map_or (
1071+ // By default, on nightly/dev enable all tools, else only
1072+ // build stable tools.
1073+ stable || builder. build . unstable_features ( ) ,
1074+ // If `tools` is set, search list for this tool.
1075+ |tools| {
1076+ tools. iter ( ) . any ( |tool| match tool. as_ref ( ) {
1077+ "clippy" => tool_name == "clippy-driver" ,
1078+ x => tool_name == x,
1079+ } )
1080+ } ,
1081+ ) ,
1082+ )
1083+ }
10851084
1086- let tool = bindir. join( exe( $tool_name, $sel. compiler. host) ) ;
1087- tool
1088- } else {
1089- tool
1090- }
1091- }
1085+ fn run_tool_build_step (
1086+ builder : & Builder < ' _ > ,
1087+ compiler : Compiler ,
1088+ target : TargetSelection ,
1089+ tool_name : & ' static str ,
1090+ path : & ' static str ,
1091+ add_bins_to_sysroot : Option < & [ & str ] > ,
1092+ ) -> PathBuf {
1093+ let tool = builder. ensure ( ToolBuild {
1094+ compiler,
1095+ target,
1096+ tool : tool_name,
1097+ mode : Mode :: ToolRustc ,
1098+ path,
1099+ extra_features : vec ! [ ] ,
1100+ source_type : SourceType :: InTree ,
1101+ allow_features : "" ,
1102+ cargo_args : vec ! [ ] ,
1103+ } ) ;
1104+
1105+ // FIXME: This should just be an if-let-chain, but those are unstable.
1106+ if let Some ( add_bins_to_sysroot) =
1107+ add_bins_to_sysroot. filter ( |bins| !bins. is_empty ( ) && compiler. stage > 0 )
1108+ {
1109+ let bindir = builder. sysroot ( compiler) . join ( "bin" ) ;
1110+ t ! ( fs:: create_dir_all( & bindir) ) ;
1111+
1112+ let tools_out = builder. cargo_out ( compiler, Mode :: ToolRustc , target) ;
1113+
1114+ for add_bin in add_bins_to_sysroot {
1115+ let bin_source = tools_out. join ( exe ( add_bin, target) ) ;
1116+ let bin_destination = bindir. join ( exe ( add_bin, compiler. host ) ) ;
1117+ builder. copy_link ( & bin_source, & bin_destination) ;
10921118 }
1093- ) +
1119+
1120+ // Return a path into the bin dir.
1121+ bindir. join ( exe ( tool_name, compiler. host ) )
1122+ } else {
1123+ tool
10941124 }
10951125}
10961126
1097- tool_extended ! ( ( self , builder) ,
1098- Cargofmt , "src/tools/rustfmt" , "cargo-fmt" , stable=true ;
1099- CargoClippy , "src/tools/clippy" , "cargo-clippy" , stable=true ;
1100- Clippy , "src/tools/clippy" , "clippy-driver" , stable=true , add_bins_to_sysroot = [ "clippy-driver" , "cargo-clippy" ] ;
1101- Miri , "src/tools/miri" , "miri" , stable=false , add_bins_to_sysroot = [ "miri" ] ;
1102- CargoMiri , "src/tools/miri/cargo-miri" , "cargo-miri" , stable=false , add_bins_to_sysroot = [ "cargo-miri" ] ;
1103- Rls , "src/tools/rls" , "rls" , stable=true ;
1104- Rustfmt , "src/tools/rustfmt" , "rustfmt" , stable=true , add_bins_to_sysroot = [ "rustfmt" , "cargo-fmt" ] ;
1105- ) ;
1127+ tool_extended ! ( Cargofmt { path: "src/tools/rustfmt" , tool_name: "cargo-fmt" , stable: true } ) ;
1128+ tool_extended ! ( CargoClippy { path: "src/tools/clippy" , tool_name: "cargo-clippy" , stable: true } ) ;
1129+ tool_extended ! ( Clippy {
1130+ path: "src/tools/clippy" ,
1131+ tool_name: "clippy-driver" ,
1132+ stable: true ,
1133+ add_bins_to_sysroot: [ "clippy-driver" , "cargo-clippy" ]
1134+ } ) ;
1135+ tool_extended ! ( Miri {
1136+ path: "src/tools/miri" ,
1137+ tool_name: "miri" ,
1138+ stable: false ,
1139+ add_bins_to_sysroot: [ "miri" ]
1140+ } ) ;
1141+ tool_extended ! ( CargoMiri {
1142+ path: "src/tools/miri/cargo-miri" ,
1143+ tool_name: "cargo-miri" ,
1144+ stable: false ,
1145+ add_bins_to_sysroot: [ "cargo-miri" ]
1146+ } ) ;
1147+ tool_extended ! ( Rls { path: "src/tools/rls" , tool_name: "rls" , stable: true } ) ;
1148+ tool_extended ! ( Rustfmt {
1149+ path: "src/tools/rustfmt" ,
1150+ tool_name: "rustfmt" ,
1151+ stable: true ,
1152+ add_bins_to_sysroot: [ "rustfmt" , "cargo-fmt" ]
1153+ } ) ;
11061154
11071155#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
11081156pub struct TestFloatParse {
0 commit comments