@@ -138,7 +138,7 @@ impl Step for Std {
138138 let compiler = self . compiler ;
139139
140140 // We already have std ready to be used for stage 0.
141- if compiler. stage == 0 {
141+ if compiler. stage == 0 && !builder . config . build_std_on_stage0 {
142142 builder. ensure ( StdLink :: from_std (
143143 self ,
144144 builder. compiler ( compiler. stage , builder. config . build ) ,
@@ -604,7 +604,7 @@ impl Step for StdLink {
604604 // Special case for stage0, to make `rustup toolchain link` and `x dist --stage 0`
605605 // work for stage0-sysroot. We only do this if the stage0 compiler comes from beta,
606606 // and is not set to a custom path.
607- if compiler. stage == 0 && is_downloaded_beta_stage0 {
607+ if compiler. stage == 0 && is_downloaded_beta_stage0 && !builder . config . build_std_on_stage0 {
608608 // Copy bin files from stage0/bin to stage0-sysroot/bin
609609 let sysroot = builder. out . join ( & compiler. host . triple ) . join ( "stage0-sysroot" ) ;
610610
@@ -616,7 +616,18 @@ impl Step for StdLink {
616616
617617 // Copy all *.so files from stage0/lib to stage0-sysroot/lib
618618 let stage0_lib_dir = builder. out . join ( & host) . join ( "stage0/lib" ) ;
619- builder. cp_r ( & stage0_lib_dir, & sysroot. join ( "lib" ) ) ;
619+
620+ if !builder. config . build_std_on_stage0 {
621+ builder. cp_r ( & stage0_lib_dir, & sysroot. join ( "lib" ) ) ;
622+ } else if let Ok ( files) = fs:: read_dir ( & stage0_lib_dir) {
623+ for file in files {
624+ let file = t ! ( file) ;
625+ let path = file. path ( ) ;
626+ if path. is_file ( ) && is_dylib ( & file. file_name ( ) . into_string ( ) . unwrap ( ) ) {
627+ builder. copy ( & path, & sysroot. join ( "lib" ) . join ( path. file_name ( ) . unwrap ( ) ) ) ;
628+ }
629+ }
630+ }
620631
621632 // Copy codegen-backends from stage0
622633 let sysroot_codegen_backends = builder. sysroot_codegen_backends ( compiler) ;
@@ -630,7 +641,7 @@ impl Step for StdLink {
630641 if stage0_codegen_backends. exists ( ) {
631642 builder. cp_r ( & stage0_codegen_backends, & sysroot_codegen_backends) ;
632643 }
633- } else if compiler. stage == 0 {
644+ } else if compiler. stage == 0 && !builder . config . build_std_on_stage0 {
634645 let sysroot = builder. out . join ( & compiler. host . triple ) . join ( "stage0-sysroot" ) ;
635646 builder. cp_r ( & builder. initial_sysroot . join ( "lib" ) , & sysroot. join ( "lib" ) ) ;
636647 } else {
0 commit comments