@@ -438,7 +438,9 @@ impl Step for TestLink {
438
438
439
439
#[ derive( Debug , PartialOrd , Ord , Copy , Clone , PartialEq , Eq , Hash ) ]
440
440
pub struct Rustc {
441
+ /// The target which our new compiler will run on
441
442
pub target : Interned < String > ,
443
+ /// The compiler we're using to compile rustc
442
444
pub compiler : Compiler ,
443
445
}
444
446
@@ -467,7 +469,9 @@ impl Step for Rustc {
467
469
let compiler = self . compiler ;
468
470
let target = self . target ;
469
471
470
- builder. ensure ( Test { compiler, target } ) ;
472
+ if compiler. stage != 0 {
473
+ builder. ensure ( Test { compiler, target } ) ;
474
+ }
471
475
472
476
if builder. force_use_stage1 ( compiler, target) {
473
477
builder. ensure ( Rustc {
@@ -485,13 +489,18 @@ impl Step for Rustc {
485
489
}
486
490
487
491
// Ensure that build scripts have a std to link against.
488
- builder. ensure ( Std {
489
- compiler : builder. compiler ( self . compiler . stage , builder. config . build ) ,
490
- target : builder. config . build ,
491
- } ) ;
492
+ if compiler. stage != 0 {
493
+ builder. ensure ( Std {
494
+ compiler : builder. compiler ( self . compiler . stage , builder. config . build ) ,
495
+ target : builder. config . build ,
496
+ } ) ;
497
+ }
492
498
let cargo_out = builder. cargo_out ( compiler, Mode :: Librustc , target) ;
493
- builder. clear_if_dirty ( & cargo_out, & libstd_stamp ( builder, compiler, target) ) ;
494
- builder. clear_if_dirty ( & cargo_out, & libtest_stamp ( builder, compiler, target) ) ;
499
+
500
+ if compiler. stage != 0 {
501
+ builder. clear_if_dirty ( & cargo_out, & libstd_stamp ( builder, compiler, target) ) ;
502
+ builder. clear_if_dirty ( & cargo_out, & libtest_stamp ( builder, compiler, target) ) ;
503
+ }
495
504
496
505
let mut cargo = builder. cargo ( compiler, Mode :: Librustc , target, "build" ) ;
497
506
rustc_cargo ( builder, & mut cargo) ;
@@ -843,17 +852,9 @@ impl Step for Sysroot {
843
852
844
853
/// Returns the sysroot for the `compiler` specified that *this build system
845
854
/// generates*.
846
- ///
847
- /// That is, the sysroot for the stage0 compiler is not what the compiler
848
- /// thinks it is by default, but it's the same as the default for stages
849
- /// 1-3.
850
855
fn run ( self , builder : & Builder ) -> Interned < PathBuf > {
851
856
let compiler = self . compiler ;
852
- let sysroot = if compiler. stage == 0 {
853
- builder. out . join ( & compiler. host ) . join ( "stage0-sysroot" )
854
- } else {
855
- builder. out . join ( & compiler. host ) . join ( format ! ( "stage{}" , compiler. stage) )
856
- } ;
857
+ let sysroot = builder. out . join ( & compiler. host ) . join ( format ! ( "stage{}" , compiler. stage) ) ;
857
858
let _ = fs:: remove_dir_all ( & sysroot) ;
858
859
t ! ( fs:: create_dir_all( & sysroot) ) ;
859
860
INTERNER . intern_path ( sysroot)
@@ -883,8 +884,9 @@ impl Step for Assemble {
883
884
/// compiler.
884
885
fn run ( self , builder : & Builder ) -> Compiler {
885
886
let target_compiler = self . target_compiler ;
887
+ let stage = target_compiler. stage ;
886
888
887
- if target_compiler . stage == 0 {
889
+ if stage == 0 {
888
890
assert_eq ! ( builder. config. build, target_compiler. host,
889
891
"Cannot obtain compiler for non-native build triple at stage 0" ) ;
890
892
// The stage 0 compiler for the build triple is always pre-built.
@@ -921,8 +923,10 @@ impl Step for Assemble {
921
923
for stage in 0 ..min ( target_compiler. stage , builder. config . keep_stage . unwrap ( ) ) {
922
924
let target_compiler = builder. compiler ( stage, target_compiler. host ) ;
923
925
let target = target_compiler. host ;
924
- builder. ensure ( StdLink { compiler, target_compiler, target } ) ;
925
- builder. ensure ( TestLink { compiler, target_compiler, target } ) ;
926
+ if stage != 1 {
927
+ builder. ensure ( StdLink { compiler, target_compiler, target } ) ;
928
+ builder. ensure ( TestLink { compiler, target_compiler, target } ) ;
929
+ }
926
930
builder. ensure ( RustcLink { compiler, target_compiler, target } ) ;
927
931
}
928
932
} else {
@@ -947,7 +951,6 @@ impl Step for Assemble {
947
951
None
948
952
} ;
949
953
950
- let stage = target_compiler. stage ;
951
954
let host = target_compiler. host ;
952
955
builder. info ( & format ! ( "Assembling stage{} compiler ({})" , stage, host) ) ;
953
956
@@ -963,6 +966,16 @@ impl Step for Assemble {
963
966
}
964
967
}
965
968
969
+ if stage == 1 {
970
+ // Copy the dynamic libraries from the bootstrap compiler
971
+ // which are needed to run the stage1 compiler
972
+ copy_libs_from_bootstrap (
973
+ builder,
974
+ build_compiler,
975
+ & sysroot_libdir,
976
+ & [ "std" , "test" , "term" ] ) ;
977
+ }
978
+
966
979
copy_codegen_backends_to_sysroot ( builder,
967
980
build_compiler,
968
981
target_compiler) ;
@@ -983,6 +996,37 @@ impl Step for Assemble {
983
996
}
984
997
}
985
998
999
+ fn copy_libs_from_bootstrap (
1000
+ builder : & Builder ,
1001
+ compiler : Compiler ,
1002
+ out_dir : & Path ,
1003
+ libs : & [ & str ] )
1004
+ {
1005
+ if builder. config . dry_run {
1006
+ return ;
1007
+ }
1008
+
1009
+ let base_libdir = builder. config
1010
+ . initial_rustc . parent ( ) . unwrap ( )
1011
+ . parent ( ) . unwrap ( )
1012
+ . join ( "lib" ) . join ( "rustlib" ) . join ( compiler. host ) . join ( "lib" ) ;
1013
+ t ! ( fs:: create_dir_all( & out_dir) ) ;
1014
+ let mut files: Vec < PathBuf > = Vec :: new ( ) ;
1015
+ for f in t ! ( fs:: read_dir( & base_libdir) ) . map ( |f| t ! ( f) ) {
1016
+ let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
1017
+ let should_copy = is_dylib ( & filename) && libs. iter ( ) . any ( |lib| {
1018
+ filename. starts_with ( & format ! ( "{}-" , lib) ) ||
1019
+ filename. starts_with ( & format ! ( "lib{}-" , lib) )
1020
+ } ) ;
1021
+ if !should_copy {
1022
+ continue ;
1023
+ }
1024
+ let dest = & out_dir. join ( filename) ;
1025
+ builder. copy ( & f. path ( ) , & dest) ;
1026
+ files. push ( dest. into ( ) ) ;
1027
+ }
1028
+ }
1029
+
986
1030
/// Link some files into a rustc sysroot.
987
1031
///
988
1032
/// For a particular stage this will link the file listed in `stamp` into the
@@ -1122,6 +1166,11 @@ pub fn run_cargo(builder: &Builder, cargo: &mut Command, stamp: &Path, is_check:
1122
1166
deps. push ( path_to_add. into ( ) ) ;
1123
1167
}
1124
1168
1169
+ update_stamp_file ( builder, stamp, deps)
1170
+ }
1171
+
1172
+ pub fn update_stamp_file ( builder : & Builder , stamp : & Path , mut deps : Vec < PathBuf > ) -> Vec < PathBuf >
1173
+ {
1125
1174
// Now we want to update the contents of the stamp file, if necessary. First
1126
1175
// we read off the previous contents along with its mtime. If our new
1127
1176
// contents (the list of files to copy) is different or if any dep's mtime
0 commit comments