@@ -696,7 +696,7 @@ impl Step for Rustc {
696696 ) ) ;
697697
698698 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 ) ;
700700
701701 if builder. config . rust_profile_use . is_some ( )
702702 && builder. config . rust_profile_generate . is_some ( )
@@ -813,16 +813,21 @@ impl Step for Rustc {
813813 }
814814}
815815
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 ) {
817817 cargo
818818 . arg ( "--features" )
819819 . arg ( builder. rustc_features ( builder. kind ) )
820820 . arg ( "--manifest-path" )
821821 . arg ( builder. src . join ( "compiler/rustc/Cargo.toml" ) ) ;
822- rustc_cargo_env ( builder, cargo, target) ;
822+ rustc_cargo_env ( builder, cargo, target, stage ) ;
823823}
824824
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+ ) {
826831 // Set some configuration variables picked up by build scripts and
827832 // the compiler alike
828833 cargo
@@ -867,83 +872,86 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
867872 cargo. env ( "RUSTC_VERIFY_LLVM_IR" , "1" ) ;
868873 }
869874
870- // Pass down configuration from the LLVM build into the build of
871- // rustc_llvm and rustc_codegen_llvm.
872- //
873875 // Note that this is disabled if LLVM itself is disabled or we're in a check
874876 // build. If we are in a check build we still go ahead here presuming we've
875877 // detected that LLVM is already built and good to go which helps prevent
876878 // 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)
888886 }
887+ }
888+ }
889889
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) ;
907894
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( ) ) ) ;
914919 }
920+ }
915921
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 {
917924 if !llvm_linker_flags. is_empty ( ) {
918- cargo . env ( "LLVM_LINKER_FLAGS" , llvm_linker_flags ) ;
925+ llvm_linker_flags . push_str ( " " ) ;
919926 }
927+ llvm_linker_flags. push_str ( s) ;
928+ }
920929
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" ) ;
947955 }
948956}
949957
@@ -1090,7 +1098,7 @@ impl Step for CodegenBackend {
10901098 cargo
10911099 . arg ( "--manifest-path" )
10921100 . 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 ) ;
10941102
10951103 let tmp_stamp = out_dir. join ( ".tmp.stamp" ) ;
10961104
0 commit comments