@@ -365,12 +365,36 @@ pub(crate) fn get_tool_rustc_compiler(
365
365
builder. compiler ( target_compiler. stage . saturating_sub ( 1 ) , builder. config . host_target )
366
366
}
367
367
368
- /// Returns the smallest stage compiler that is able to compile code for the given `target`.
369
- pub ( crate ) fn get_compiler_for_target ( builder : & Builder < ' _ > , target : TargetSelection ) -> Compiler {
368
+ /// Determines how to build a `ToolTarget`, i.e. which compiler should be used to compile it.
369
+ /// The compiler stage is automatically auto-bumped if we need to cross-compile a stage 1 tool.
370
+ pub enum ToolTargetBuildMode {
371
+ /// Build the tool using rustc that corresponds to the selected CLI stage.
372
+ Build ( TargetSelection ) ,
373
+ /// Build the tool so that it can be attached to the sysroot of the passed compiler.
374
+ /// Since we always dist stage 2+, the compiler that builds the tool in this case has to be
375
+ /// stage 1+.
376
+ Dist ( Compiler ) ,
377
+ }
378
+
379
+ /// Returns compiler that is able to compile a `ToolTarget` tool with the given `mode`.
380
+ pub ( crate ) fn get_tool_target_compiler (
381
+ builder : & Builder < ' _ > ,
382
+ mode : ToolTargetBuildMode ,
383
+ ) -> Compiler {
384
+ let ( target, min_build_compiler_stage) = match mode {
385
+ ToolTargetBuildMode :: Build ( target) => {
386
+ assert ! ( builder. top_stage > 0 ) ;
387
+ ( target, builder. top_stage - 1 )
388
+ }
389
+ ToolTargetBuildMode :: Dist ( target_compiler) => {
390
+ assert ! ( target_compiler. stage > 0 ) ;
391
+ ( target_compiler. host , target_compiler. stage - 1 )
392
+ }
393
+ } ;
370
394
let compiler = if builder. host_target == target {
371
- builder. compiler ( 0 , builder. host_target )
395
+ builder. compiler ( min_build_compiler_stage , builder. host_target )
372
396
} else {
373
- builder. compiler ( 1 , builder. host_target )
397
+ builder. compiler ( min_build_compiler_stage . max ( 1 ) , builder. host_target )
374
398
} ;
375
399
builder. std ( compiler, target) ;
376
400
compiler
@@ -533,7 +557,6 @@ bootstrap_tool!(
533
557
// rustdoc-gui-test has a crate dependency on compiletest, so it needs the same unstable features.
534
558
RustdocGUITest , "src/tools/rustdoc-gui-test" , "rustdoc-gui-test" , is_unstable_tool = true , allow_features = COMPILETEST_ALLOW_FEATURES ;
535
559
CoverageDump , "src/tools/coverage-dump" , "coverage-dump" ;
536
- WasmComponentLd , "src/tools/wasm-component-ld" , "wasm-component-ld" , is_unstable_tool = true , allow_features = "min_specialization" ;
537
560
UnicodeTableGenerator , "src/tools/unicode-table-generator" , "unicode-table-generator" ;
538
561
FeaturesStatusDump , "src/tools/features-status-dump" , "features-status-dump" ;
539
562
OptimizedDist , "src/tools/opt-dist" , "opt-dist" , submodules = & [ "src/tools/rustc-perf" ] ;
@@ -661,7 +684,10 @@ impl Step for RemoteTestServer {
661
684
662
685
fn make_run ( run : RunConfig < ' _ > ) {
663
686
run. builder . ensure ( RemoteTestServer {
664
- build_compiler : get_compiler_for_target ( run. builder , run. target ) ,
687
+ build_compiler : get_tool_target_compiler (
688
+ run. builder ,
689
+ ToolTargetBuildMode :: Build ( run. target ) ,
690
+ ) ,
665
691
target : run. target ,
666
692
} ) ;
667
693
}
@@ -935,6 +961,75 @@ impl Step for LldWrapper {
935
961
}
936
962
}
937
963
964
+ /// Builds the `wasm-component-ld` linker wrapper, which is shipped with rustc to be executed on the
965
+ /// host platform where rustc runs.
966
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
967
+ pub struct WasmComponentLd {
968
+ build_compiler : Compiler ,
969
+ target : TargetSelection ,
970
+ }
971
+
972
+ impl WasmComponentLd {
973
+ /// Returns `WasmComponentLd` that should be **used** by the passed compiler.
974
+ pub fn for_compiler ( builder : & Builder < ' _ > , target_compiler : Compiler ) -> Self {
975
+ Self {
976
+ build_compiler : get_tool_target_compiler (
977
+ builder,
978
+ ToolTargetBuildMode :: Dist ( target_compiler) ,
979
+ ) ,
980
+ target : target_compiler. host ,
981
+ }
982
+ }
983
+ }
984
+
985
+ impl Step for WasmComponentLd {
986
+ type Output = ToolBuildResult ;
987
+
988
+ const ONLY_HOSTS : bool = true ;
989
+
990
+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
991
+ run. path ( "src/tools/wasm-component-ld" )
992
+ }
993
+
994
+ fn make_run ( run : RunConfig < ' _ > ) {
995
+ run. builder . ensure ( WasmComponentLd {
996
+ build_compiler : get_tool_target_compiler (
997
+ run. builder ,
998
+ ToolTargetBuildMode :: Build ( run. target ) ,
999
+ ) ,
1000
+ target : run. target ,
1001
+ } ) ;
1002
+ }
1003
+
1004
+ #[ cfg_attr(
1005
+ feature = "tracing" ,
1006
+ instrument(
1007
+ level = "debug" ,
1008
+ name = "WasmComponentLd::run" ,
1009
+ skip_all,
1010
+ fields( build_compiler = ?self . build_compiler) ,
1011
+ ) ,
1012
+ ) ]
1013
+ fn run ( self , builder : & Builder < ' _ > ) -> ToolBuildResult {
1014
+ builder. ensure ( ToolBuild {
1015
+ build_compiler : self . build_compiler ,
1016
+ target : self . target ,
1017
+ tool : "wasm-component-ld" ,
1018
+ mode : Mode :: ToolTarget ,
1019
+ path : "src/tools/wasm-component-ld" ,
1020
+ source_type : SourceType :: InTree ,
1021
+ extra_features : vec ! [ ] ,
1022
+ allow_features : "min-specialization" ,
1023
+ cargo_args : vec ! [ ] ,
1024
+ artifact_kind : ToolArtifactKind :: Binary ,
1025
+ } )
1026
+ }
1027
+
1028
+ fn metadata ( & self ) -> Option < StepMetadata > {
1029
+ Some ( StepMetadata :: build ( "WasmComponentLd" , self . target ) . built_by ( self . build_compiler ) )
1030
+ }
1031
+ }
1032
+
938
1033
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
939
1034
pub struct RustAnalyzer {
940
1035
pub compiler : Compiler ,
0 commit comments