@@ -696,7 +696,7 @@ impl Step for Rustc {
696
696
) ) ;
697
697
698
698
let mut cargo = builder. cargo ( compiler, Mode :: Rustc , SourceType :: InTree , target, "build" ) ;
699
- rustc_cargo ( builder, & mut cargo, target) ;
699
+ rustc_cargo ( builder, & mut cargo, target, compiler . stage ) ;
700
700
701
701
if builder. config . rust_profile_use . is_some ( )
702
702
&& builder. config . rust_profile_generate . is_some ( )
@@ -813,16 +813,21 @@ impl Step for Rustc {
813
813
}
814
814
}
815
815
816
- pub fn rustc_cargo ( builder : & Builder < ' _ > , cargo : & mut Cargo , target : TargetSelection ) {
816
+ pub fn rustc_cargo ( builder : & Builder < ' _ > , cargo : & mut Cargo , target : TargetSelection , stage : u32 ) {
817
817
cargo
818
818
. arg ( "--features" )
819
819
. arg ( builder. rustc_features ( builder. kind ) )
820
820
. arg ( "--manifest-path" )
821
821
. arg ( builder. src . join ( "compiler/rustc/Cargo.toml" ) ) ;
822
- rustc_cargo_env ( builder, cargo, target) ;
822
+ rustc_cargo_env ( builder, cargo, target, stage ) ;
823
823
}
824
824
825
- pub fn rustc_cargo_env ( builder : & Builder < ' _ > , cargo : & mut Cargo , target : TargetSelection ) {
825
+ pub fn rustc_cargo_env (
826
+ builder : & Builder < ' _ > ,
827
+ cargo : & mut Cargo ,
828
+ target : TargetSelection ,
829
+ stage : u32 ,
830
+ ) {
826
831
// Set some configuration variables picked up by build scripts and
827
832
// the compiler alike
828
833
cargo
@@ -867,83 +872,86 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
867
872
cargo. env ( "RUSTC_VERIFY_LLVM_IR" , "1" ) ;
868
873
}
869
874
870
- // Pass down configuration from the LLVM build into the build of
871
- // rustc_llvm and rustc_codegen_llvm.
872
- //
873
875
// Note that this is disabled if LLVM itself is disabled or we're in a check
874
876
// build. If we are in a check build we still go ahead here presuming we've
875
877
// detected that LLVM is already built and good to go which helps prevent
876
878
// busting caches (e.g. like #71152).
877
- if builder. config . llvm_enabled ( )
878
- && ( builder. kind != Kind :: Check
879
- || crate :: llvm:: prebuilt_llvm_config ( builder, target) . is_ok ( ) )
880
- {
881
- if builder. is_rust_llvm ( target) {
882
- cargo. env ( "LLVM_RUSTLLVM" , "1" ) ;
883
- }
884
- let llvm:: LlvmResult { llvm_config, .. } = builder. ensure ( llvm:: Llvm { target } ) ;
885
- cargo. env ( "LLVM_CONFIG" , & llvm_config) ;
886
- if let Some ( s) = target_config. and_then ( |c| c. llvm_config . as_ref ( ) ) {
887
- cargo. env ( "CFG_LLVM_ROOT" , s) ;
879
+ if builder. config . llvm_enabled ( ) {
880
+ let building_is_expensive = crate :: llvm:: prebuilt_llvm_config ( builder, target) . is_err ( ) ;
881
+ // `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
882
+ let can_skip_build = builder. kind == Kind :: Check && builder. top_stage == stage;
883
+ let should_skip_build = building_is_expensive && can_skip_build;
884
+ if !should_skip_build {
885
+ rustc_llvm_env ( builder, cargo, target)
888
886
}
887
+ }
888
+ }
889
889
890
- // Some LLVM linker flags (-L and -l) may be needed to link `rustc_llvm`. Its build script
891
- // expects these to be passed via the `LLVM_LINKER_FLAGS` env variable, separated by
892
- // whitespace.
893
- //
894
- // For example:
895
- // - on windows, when `clang-cl` is used with instrumentation, we need to manually add
896
- // clang's runtime library resource directory so that the profiler runtime library can be
897
- // found. This is to avoid the linker errors about undefined references to
898
- // `__llvm_profile_instrument_memop` when linking `rustc_driver`.
899
- let mut llvm_linker_flags = String :: new ( ) ;
900
- if builder. config . llvm_profile_generate && target. contains ( "msvc" ) {
901
- if let Some ( ref clang_cl_path) = builder. config . llvm_clang_cl {
902
- // Add clang's runtime library directory to the search path
903
- let clang_rt_dir = get_clang_cl_resource_dir ( clang_cl_path) ;
904
- llvm_linker_flags. push_str ( & format ! ( "-L{}" , clang_rt_dir. display( ) ) ) ;
905
- }
906
- }
890
+ /// Pass down configuration from the LLVM build into the build of
891
+ /// rustc_llvm and rustc_codegen_llvm.
892
+ fn rustc_llvm_env ( builder : & Builder < ' _ > , cargo : & mut Cargo , target : TargetSelection ) {
893
+ let target_config = builder. config . target_config . get ( & target) ;
907
894
908
- // The config can also specify its own llvm linker flags.
909
- if let Some ( ref s) = builder. config . llvm_ldflags {
910
- if !llvm_linker_flags. is_empty ( ) {
911
- llvm_linker_flags. push_str ( " " ) ;
912
- }
913
- llvm_linker_flags. push_str ( s) ;
895
+ if builder. is_rust_llvm ( target) {
896
+ cargo. env ( "LLVM_RUSTLLVM" , "1" ) ;
897
+ }
898
+ let llvm:: LlvmResult { llvm_config, .. } = builder. ensure ( llvm:: Llvm { target } ) ;
899
+ cargo. env ( "LLVM_CONFIG" , & llvm_config) ;
900
+ if let Some ( s) = target_config. and_then ( |c| c. llvm_config . as_ref ( ) ) {
901
+ cargo. env ( "CFG_LLVM_ROOT" , s) ;
902
+ }
903
+
904
+ // Some LLVM linker flags (-L and -l) may be needed to link `rustc_llvm`. Its build script
905
+ // expects these to be passed via the `LLVM_LINKER_FLAGS` env variable, separated by
906
+ // whitespace.
907
+ //
908
+ // For example:
909
+ // - on windows, when `clang-cl` is used with instrumentation, we need to manually add
910
+ // clang's runtime library resource directory so that the profiler runtime library can be
911
+ // found. This is to avoid the linker errors about undefined references to
912
+ // `__llvm_profile_instrument_memop` when linking `rustc_driver`.
913
+ let mut llvm_linker_flags = String :: new ( ) ;
914
+ if builder. config . llvm_profile_generate && target. contains ( "msvc" ) {
915
+ if let Some ( ref clang_cl_path) = builder. config . llvm_clang_cl {
916
+ // Add clang's runtime library directory to the search path
917
+ let clang_rt_dir = get_clang_cl_resource_dir ( clang_cl_path) ;
918
+ llvm_linker_flags. push_str ( & format ! ( "-L{}" , clang_rt_dir. display( ) ) ) ;
914
919
}
920
+ }
915
921
916
- // Set the linker flags via the env var that `rustc_llvm`'s build script will read.
922
+ // The config can also specify its own llvm linker flags.
923
+ if let Some ( ref s) = builder. config . llvm_ldflags {
917
924
if !llvm_linker_flags. is_empty ( ) {
918
- cargo . env ( "LLVM_LINKER_FLAGS" , llvm_linker_flags ) ;
925
+ llvm_linker_flags . push_str ( " " ) ;
919
926
}
927
+ llvm_linker_flags. push_str ( s) ;
928
+ }
920
929
921
- // Building with a static libstdc++ is only supported on linux right now,
922
- // not for MSVC or macOS
923
- if builder. config . llvm_static_stdcpp
924
- && !target. contains ( "freebsd" )
925
- && !target. contains ( "msvc" )
926
- && !target. contains ( "apple" )
927
- && !target. contains ( "solaris" )
928
- {
929
- let file = compiler_file (
930
- builder,
931
- builder. cxx ( target) . unwrap ( ) ,
932
- target,
933
- CLang :: Cxx ,
934
- "libstdc++.a" ,
935
- ) ;
936
- cargo. env ( "LLVM_STATIC_STDCPP" , file) ;
937
- }
938
- if builder. llvm_link_shared ( ) {
939
- cargo. env ( "LLVM_LINK_SHARED" , "1" ) ;
940
- }
941
- if builder. config . llvm_use_libcxx {
942
- cargo. env ( "LLVM_USE_LIBCXX" , "1" ) ;
943
- }
944
- if builder. config . llvm_optimize && !builder. config . llvm_release_debuginfo {
945
- cargo. env ( "LLVM_NDEBUG" , "1" ) ;
946
- }
930
+ // Set the linker flags via the env var that `rustc_llvm`'s build script will read.
931
+ if !llvm_linker_flags. is_empty ( ) {
932
+ cargo. env ( "LLVM_LINKER_FLAGS" , llvm_linker_flags) ;
933
+ }
934
+
935
+ // Building with a static libstdc++ is only supported on linux right now,
936
+ // not for MSVC or macOS
937
+ if builder. config . llvm_static_stdcpp
938
+ && !target. contains ( "freebsd" )
939
+ && !target. contains ( "msvc" )
940
+ && !target. contains ( "apple" )
941
+ && !target. contains ( "solaris" )
942
+ {
943
+ let file =
944
+ compiler_file ( builder, builder. cxx ( target) . unwrap ( ) , target, CLang :: Cxx , "libstdc++.a" ) ;
945
+ cargo. env ( "LLVM_STATIC_STDCPP" , file) ;
946
+ }
947
+ if builder. llvm_link_shared ( ) {
948
+ cargo. env ( "LLVM_LINK_SHARED" , "1" ) ;
949
+ }
950
+ if builder. config . llvm_use_libcxx {
951
+ cargo. env ( "LLVM_USE_LIBCXX" , "1" ) ;
952
+ }
953
+ if builder. config . llvm_optimize && !builder. config . llvm_release_debuginfo {
954
+ cargo. env ( "LLVM_NDEBUG" , "1" ) ;
947
955
}
948
956
}
949
957
@@ -1090,7 +1098,7 @@ impl Step for CodegenBackend {
1090
1098
cargo
1091
1099
. arg ( "--manifest-path" )
1092
1100
. arg ( builder. src . join ( format ! ( "compiler/rustc_codegen_{}/Cargo.toml" , backend) ) ) ;
1093
- rustc_cargo_env ( builder, & mut cargo, target) ;
1101
+ rustc_cargo_env ( builder, & mut cargo, target, compiler . stage ) ;
1094
1102
1095
1103
let tmp_stamp = out_dir. join ( ".tmp.stamp" ) ;
1096
1104
0 commit comments