@@ -881,17 +881,50 @@ impl Step for Cargo {
881
881
}
882
882
}
883
883
884
+ /// Represents a built LldWrapper, the `lld-wrapper` tool itself, and a directory
885
+ /// containing a build of LLD.
886
+ #[ derive( Clone ) ]
887
+ pub struct BuiltLldWrapper {
888
+ tool : ToolBuildResult ,
889
+ lld_dir : PathBuf ,
890
+ }
891
+
884
892
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
885
893
pub struct LldWrapper {
886
894
pub build_compiler : Compiler ,
887
- pub target_compiler : Compiler ,
895
+ pub target : TargetSelection ,
896
+ }
897
+
898
+ impl LldWrapper {
899
+ /// Returns `LldWrapper` that should be **used** by the passed compiler.
900
+ pub fn for_compiler ( builder : & Builder < ' _ > , target_compiler : Compiler ) -> Self {
901
+ Self {
902
+ build_compiler : get_tool_target_compiler (
903
+ builder,
904
+ ToolTargetBuildMode :: Dist ( target_compiler) ,
905
+ ) ,
906
+ target : target_compiler. host ,
907
+ }
908
+ }
888
909
}
889
910
890
911
impl Step for LldWrapper {
891
- type Output = ToolBuildResult ;
912
+ type Output = BuiltLldWrapper ;
913
+
914
+ const ONLY_HOSTS : bool = true ;
892
915
893
916
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
894
- run. never ( )
917
+ run. path ( "src/tools/lld-wrapper" )
918
+ }
919
+
920
+ fn make_run ( run : RunConfig < ' _ > ) {
921
+ run. builder . ensure ( LldWrapper {
922
+ build_compiler : get_tool_target_compiler (
923
+ run. builder ,
924
+ ToolTargetBuildMode :: Build ( run. target ) ,
925
+ ) ,
926
+ target : run. target ,
927
+ } ) ;
895
928
}
896
929
897
930
#[ cfg_attr(
@@ -900,64 +933,58 @@ impl Step for LldWrapper {
900
933
level = "debug" ,
901
934
name = "LldWrapper::run" ,
902
935
skip_all,
903
- fields( build_compiler = ?self . build_compiler, target_compiler = ? self . target_compiler ) ,
936
+ fields( build_compiler = ?self . build_compiler) ,
904
937
) ,
905
938
) ]
906
- fn run ( self , builder : & Builder < ' _ > ) -> ToolBuildResult {
907
- if builder. config . dry_run ( ) {
908
- return ToolBuildResult {
909
- tool_path : Default :: default ( ) ,
910
- build_compiler : self . build_compiler ,
911
- target_compiler : self . target_compiler ,
912
- } ;
913
- }
914
-
915
- let target = self . target_compiler . host ;
916
-
917
- let tool_result = builder. ensure ( ToolBuild {
939
+ fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
940
+ let lld_dir = builder. ensure ( llvm:: Lld { target : self . target } ) ;
941
+ let tool = builder. ensure ( ToolBuild {
918
942
build_compiler : self . build_compiler ,
919
- target,
943
+ target : self . target ,
920
944
tool : "lld-wrapper" ,
921
- mode : Mode :: ToolStd ,
945
+ mode : Mode :: ToolTarget ,
922
946
path : "src/tools/lld-wrapper" ,
923
947
source_type : SourceType :: InTree ,
924
948
extra_features : Vec :: new ( ) ,
925
949
allow_features : "" ,
926
950
cargo_args : Vec :: new ( ) ,
927
951
artifact_kind : ToolArtifactKind :: Binary ,
928
952
} ) ;
953
+ BuiltLldWrapper { tool, lld_dir }
954
+ }
955
+
956
+ fn metadata ( & self ) -> Option < StepMetadata > {
957
+ Some ( StepMetadata :: build ( "LldWrapper" , self . target ) . built_by ( self . build_compiler ) )
958
+ }
959
+ }
960
+
961
+ pub ( crate ) fn copy_lld_artifacts (
962
+ builder : & Builder < ' _ > ,
963
+ lld_wrapper : BuiltLldWrapper ,
964
+ target_compiler : Compiler ,
965
+ ) {
966
+ let target = target_compiler. host ;
967
+
968
+ let libdir_bin = builder. sysroot_target_bindir ( target_compiler, target) ;
969
+ t ! ( fs:: create_dir_all( & libdir_bin) ) ;
929
970
930
- let libdir_bin = builder . sysroot_target_bindir ( self . target_compiler , target) ;
931
- t ! ( fs :: create_dir_all ( & libdir_bin ) ) ;
971
+ let src_exe = exe ( "lld" , target) ;
972
+ let dst_exe = exe ( "rust-lld" , target ) ;
932
973
933
- let lld_install = builder. ensure ( llvm:: Lld { target } ) ;
934
- let src_exe = exe ( "lld" , target) ;
935
- let dst_exe = exe ( "rust-lld" , target) ;
974
+ builder. copy_link (
975
+ & lld_wrapper. lld_dir . join ( "bin" ) . join ( src_exe) ,
976
+ & libdir_bin. join ( dst_exe) ,
977
+ FileType :: Executable ,
978
+ ) ;
979
+ let self_contained_lld_dir = libdir_bin. join ( "gcc-ld" ) ;
980
+ t ! ( fs:: create_dir_all( & self_contained_lld_dir) ) ;
936
981
982
+ for name in crate :: LLD_FILE_NAMES {
937
983
builder. copy_link (
938
- & lld_install . join ( "bin" ) . join ( src_exe ) ,
939
- & libdir_bin . join ( dst_exe ) ,
984
+ & lld_wrapper . tool . tool_path ,
985
+ & self_contained_lld_dir . join ( exe ( name , target ) ) ,
940
986
FileType :: Executable ,
941
987
) ;
942
- let self_contained_lld_dir = libdir_bin. join ( "gcc-ld" ) ;
943
- t ! ( fs:: create_dir_all( & self_contained_lld_dir) ) ;
944
-
945
- for name in crate :: LLD_FILE_NAMES {
946
- builder. copy_link (
947
- & tool_result. tool_path ,
948
- & self_contained_lld_dir. join ( exe ( name, target) ) ,
949
- FileType :: Executable ,
950
- ) ;
951
- }
952
-
953
- tool_result
954
- }
955
-
956
- fn metadata ( & self ) -> Option < StepMetadata > {
957
- Some (
958
- StepMetadata :: build ( "LldWrapper" , self . target_compiler . host )
959
- . built_by ( self . build_compiler ) ,
960
- )
961
988
}
962
989
}
963
990
0 commit comments