@@ -747,9 +747,16 @@ fn copy_target_libs(
747747 }
748748}
749749
750+ /// Builds the standard library (`rust-std`) dist component for a given `target`.
751+ /// This includes the standard library dynamic library file (e.g. .so/.dll), along with stdlib
752+ /// .rlibs.
753+ ///
754+ /// Note that due to uplifting, we actually ship the stage 1 library
755+ /// (built using the stage1 compiler) even with a stage 2 dist, unless `full-bootstrap` is enabled.
750756#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
751757pub struct Std {
752- pub compiler : Compiler ,
758+ /// Compiler that will build the standard library.
759+ pub build_compiler : Compiler ,
753760 pub target : TargetSelection ,
754761}
755762
@@ -762,39 +769,51 @@ impl Step for Std {
762769 }
763770
764771 fn make_run ( run : RunConfig < ' _ > ) {
772+ // This is a build time optimization for running just `x dist rust-std` (without
773+ // `x dist rustc`).
774+ // If we know that we will be uplifting a stage2+ library from stage 1 anyway,
775+ // there is no point in building a stage2 rustc, which will then not do anything (because
776+ // the stdlib will be uplifted).
777+ let top_stage = run. builder . top_stage ;
778+ let stage = if top_stage > 1
779+ && compile:: Std :: should_be_uplifted_from_stage_1 ( run. builder , top_stage, run. target )
780+ {
781+ run. builder . info ( & format ! (
782+ "Note: stage {top_stage} library for `{}` would be uplifted from stage 1, so stage was downgraded from {top_stage} to 1 to avoid needless compiler build(s)" ,
783+ run. target
784+ ) ) ;
785+ 1
786+ } else {
787+ top_stage
788+ } ;
765789 run. builder . ensure ( Std {
766- compiler : run. builder . compiler_for (
767- run. builder . top_stage ,
768- run. builder . config . host_target ,
769- run. target ,
770- ) ,
790+ build_compiler : run. builder . compiler ( stage, run. builder . config . host_target ) ,
771791 target : run. target ,
772792 } ) ;
773793 }
774794
775795 fn run ( self , builder : & Builder < ' _ > ) -> Option < GeneratedTarball > {
776- let compiler = self . compiler ;
796+ let build_compiler = self . build_compiler ;
777797 let target = self . target ;
778798
779- if skip_host_target_lib ( builder, compiler ) {
799+ if skip_host_target_lib ( builder, build_compiler ) {
780800 return None ;
781801 }
782802
783- builder. std ( compiler , target) ;
803+ builder. std ( build_compiler , target) ;
784804
785805 let mut tarball = Tarball :: new ( builder, "rust-std" , & target. triple ) ;
786806 tarball. include_target_in_component_name ( true ) ;
787807
788- let compiler_to_use = builder. compiler_for ( compiler. stage , compiler. host , target) ;
789- let stamp = build_stamp:: libstd_stamp ( builder, compiler_to_use, target) ;
808+ let stamp = build_stamp:: libstd_stamp ( builder, build_compiler, target) ;
790809 verify_uefi_rlib_format ( builder, target, & stamp) ;
791810 copy_target_libs ( builder, target, tarball. image_dir ( ) , & stamp) ;
792811
793812 Some ( tarball. generate ( ) )
794813 }
795814
796815 fn metadata ( & self ) -> Option < StepMetadata > {
797- Some ( StepMetadata :: dist ( "std" , self . target ) . built_by ( self . compiler ) )
816+ Some ( StepMetadata :: dist ( "std" , self . target ) . built_by ( self . build_compiler ) )
798817 }
799818}
800819
@@ -1630,7 +1649,8 @@ impl Step for Extended {
16301649 // the std files during uninstall. To do this ensure that rustc comes
16311650 // before rust-std in the list below.
16321651 tarballs. push ( builder. ensure ( Rustc { target_compiler } ) ) ;
1633- tarballs. push ( builder. ensure ( Std { compiler, target } ) . expect ( "missing std" ) ) ;
1652+ tarballs
1653+ . push ( builder. ensure ( Std { build_compiler : compiler, target } ) . expect ( "missing std" ) ) ;
16341654
16351655 if target. is_windows_gnu ( ) {
16361656 tarballs. push ( builder. ensure ( Mingw { target } ) . expect ( "missing mingw" ) ) ;
0 commit comments