@@ -33,17 +33,12 @@ use {Build, Compiler, Mode};
3333/// This will build the standard library for a particular stage of the build
3434/// using the `compiler` targeting the `target` architecture. The artifacts
3535/// created will also be linked into the sysroot directory.
36- pub fn std < ' a > ( build : & ' a Build , target : & str , compiler : & Compiler < ' a > ) {
37- println ! ( "Building stage{} std artifacts ({} -> {})" , compiler. stage,
38- compiler. host, target) ;
39-
36+ pub fn std ( build : & Build , target : & str , compiler : & Compiler ) {
4037 let libdir = build. sysroot_libdir ( compiler, target) ;
41- let _ = fs:: remove_dir_all ( & libdir) ;
4238 t ! ( fs:: create_dir_all( & libdir) ) ;
4339
44- // Some platforms have startup objects that may be required to produce the
45- // libstd dynamic library, for example.
46- build_startup_objects ( build, target, & libdir) ;
40+ println ! ( "Building stage{} std artifacts ({} -> {})" , compiler. stage,
41+ compiler. host, target) ;
4742
4843 let out_dir = build. cargo_out ( compiler, Mode :: Libstd , target) ;
4944 build. clear_if_dirty ( & out_dir, & build. compiler_path ( compiler) ) ;
@@ -65,29 +60,30 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
6560
6661 build. run ( & mut cargo) ;
6762 update_mtime ( & libstd_stamp ( build, & compiler, target) ) ;
68- std_link ( build, target, compiler. stage , compiler. host ) ;
6963}
7064
7165/// Link all libstd rlibs/dylibs into the sysroot location.
7266///
73- /// Links those artifacts generated in the given `stage` for `target` produced
74- /// by `compiler` into `host`'s sysroot.
67+ /// Links those artifacts generated by `compiler` to a the `stage` compiler's
68+ /// sysroot for the specified `host` and `target`.
69+ ///
70+ /// Note that this assumes that `compiler` has already generated the libstd
71+ /// libraries for `target`, and this method will find them in the relevant
72+ /// output directory.
7573pub fn std_link ( build : & Build ,
76- target : & str ,
77- stage : u32 ,
78- host : & str ) {
79- let compiler = Compiler :: new ( stage, & build. config . build ) ;
80- let target_compiler = Compiler :: new ( compiler. stage , host) ;
74+ compiler : & Compiler ,
75+ target_compiler : & Compiler ,
76+ target : & str ) {
77+ println ! ( "Copying stage{} std from stage{} ({} -> {} / {})" ,
78+ target_compiler. stage,
79+ compiler. stage,
80+ compiler. host,
81+ target_compiler. host,
82+ target) ;
8183 let libdir = build. sysroot_libdir ( & target_compiler, target) ;
8284 let out_dir = build. cargo_out ( & compiler, Mode :: Libstd , target) ;
8385
84- // If we're linking one compiler host's output into another, then we weren't
85- // called from the `std` method above. In that case we clean out what's
86- // already there.
87- if host != compiler. host {
88- let _ = fs:: remove_dir_all ( & libdir) ;
89- t ! ( fs:: create_dir_all( & libdir) ) ;
90- }
86+ t ! ( fs:: create_dir_all( & libdir) ) ;
9187 add_to_sysroot ( & out_dir, & libdir) ;
9288
9389 if target. contains ( "musl" ) && !target. contains ( "mips" ) {
@@ -110,20 +106,23 @@ fn copy_musl_third_party_objects(build: &Build, target: &str, into: &Path) {
110106/// They don't require any library support as they're just plain old object
111107/// files, so we just use the nightly snapshot compiler to always build them (as
112108/// no other compilers are guaranteed to be available).
113- fn build_startup_objects ( build : & Build , target : & str , into : & Path ) {
109+ pub fn build_startup_objects ( build : & Build , for_compiler : & Compiler , target : & str ) {
114110 if !target. contains ( "pc-windows-gnu" ) {
115111 return
116112 }
113+
117114 let compiler = Compiler :: new ( 0 , & build. config . build ) ;
118115 let compiler_path = build. compiler_path ( & compiler) ;
116+ let into = build. sysroot_libdir ( for_compiler, target) ;
117+ t ! ( fs:: create_dir_all( & into) ) ;
119118
120119 for file in t ! ( fs:: read_dir( build. src. join( "src/rtstartup" ) ) ) {
121120 let file = t ! ( file) ;
122121 let mut cmd = Command :: new ( & compiler_path) ;
123122 build. run ( cmd. env ( "RUSTC_BOOTSTRAP" , "1" )
124123 . arg ( "--target" ) . arg ( target)
125124 . arg ( "--emit=obj" )
126- . arg ( "--out-dir" ) . arg ( into)
125+ . arg ( "--out-dir" ) . arg ( & into)
127126 . arg ( file. path ( ) ) ) ;
128127 }
129128
@@ -137,7 +136,7 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) {
137136/// This will build libtest and supporting libraries for a particular stage of
138137/// the build using the `compiler` targeting the `target` architecture. The
139138/// artifacts created will also be linked into the sysroot directory.
140- pub fn test < ' a > ( build : & ' a Build , target : & str , compiler : & Compiler < ' a > ) {
139+ pub fn test ( build : & Build , target : & str , compiler : & Compiler ) {
141140 println ! ( "Building stage{} test artifacts ({} -> {})" , compiler. stage,
142141 compiler. host, target) ;
143142 let out_dir = build. cargo_out ( compiler, Mode :: Libtest , target) ;
@@ -147,19 +146,19 @@ pub fn test<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
147146 . arg ( build. src . join ( "src/rustc/test_shim/Cargo.toml" ) ) ;
148147 build. run ( & mut cargo) ;
149148 update_mtime ( & libtest_stamp ( build, compiler, target) ) ;
150- test_link ( build, target, compiler. stage , compiler. host ) ;
151149}
152150
153- /// Link all libtest rlibs/dylibs into the sysroot location.
154- ///
155- /// Links those artifacts generated in the given `stage` for `target` produced
156- /// by `compiler` into `host`'s sysroot.
151+ /// Same as `std_link`, only for libtest
157152pub fn test_link ( build : & Build ,
158- target : & str ,
159- stage : u32 ,
160- host : & str ) {
161- let compiler = Compiler :: new ( stage, & build. config . build ) ;
162- let target_compiler = Compiler :: new ( compiler. stage , host) ;
153+ compiler : & Compiler ,
154+ target_compiler : & Compiler ,
155+ target : & str ) {
156+ println ! ( "Copying stage{} test from stage{} ({} -> {} / {})" ,
157+ target_compiler. stage,
158+ compiler. stage,
159+ compiler. host,
160+ target_compiler. host,
161+ target) ;
163162 let libdir = build. sysroot_libdir ( & target_compiler, target) ;
164163 let out_dir = build. cargo_out ( & compiler, Mode :: Libtest , target) ;
165164 add_to_sysroot ( & out_dir, & libdir) ;
@@ -170,7 +169,7 @@ pub fn test_link(build: &Build,
170169/// This will build the compiler for a particular stage of the build using
171170/// the `compiler` targeting the `target` architecture. The artifacts
172171/// created will also be linked into the sysroot directory.
173- pub fn rustc < ' a > ( build : & ' a Build , target : & str , compiler : & Compiler < ' a > ) {
172+ pub fn rustc ( build : & Build , target : & str , compiler : & Compiler ) {
174173 println ! ( "Building stage{} compiler artifacts ({} -> {})" ,
175174 compiler. stage, compiler. host, target) ;
176175
@@ -222,20 +221,19 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
222221 cargo. env ( "CFG_DEFAULT_AR" , s) ;
223222 }
224223 build. run ( & mut cargo) ;
225-
226- rustc_link ( build, target, compiler. stage , compiler. host ) ;
227224}
228225
229- /// Link all librustc rlibs/dylibs into the sysroot location.
230- ///
231- /// Links those artifacts generated in the given `stage` for `target` produced
232- /// by `compiler` into `host`'s sysroot.
226+ /// Same as `std_link`, only for librustc
233227pub fn rustc_link ( build : & Build ,
234- target : & str ,
235- stage : u32 ,
236- host : & str ) {
237- let compiler = Compiler :: new ( stage, & build. config . build ) ;
238- let target_compiler = Compiler :: new ( compiler. stage , host) ;
228+ compiler : & Compiler ,
229+ target_compiler : & Compiler ,
230+ target : & str ) {
231+ println ! ( "Copying stage{} rustc from stage{} ({} -> {} / {})" ,
232+ target_compiler. stage,
233+ compiler. stage,
234+ compiler. host,
235+ target_compiler. host,
236+ target) ;
239237 let libdir = build. sysroot_libdir ( & target_compiler, target) ;
240238 let out_dir = build. cargo_out ( & compiler, Mode :: Librustc , target) ;
241239 add_to_sysroot ( & out_dir, & libdir) ;
@@ -259,6 +257,17 @@ fn compiler_file(compiler: &Path, file: &str) -> PathBuf {
259257 PathBuf :: from ( out. trim ( ) )
260258}
261259
260+ pub fn create_sysroot ( build : & Build , compiler : & Compiler ) {
261+ // nothing to do in stage0
262+ if compiler. stage == 0 {
263+ return
264+ }
265+
266+ let sysroot = build. sysroot ( compiler) ;
267+ let _ = fs:: remove_dir_all ( & sysroot) ;
268+ t ! ( fs:: create_dir_all( & sysroot) ) ;
269+ }
270+
262271/// Prepare a new compiler from the artifacts in `stage`
263272///
264273/// This will assemble a compiler in `build/$host/stage$stage`. The compiler
@@ -269,18 +278,17 @@ pub fn assemble_rustc(build: &Build, stage: u32, host: &str) {
269278 if stage == 0 {
270279 return
271280 }
281+
282+ println ! ( "Copying stage{} compiler ({})" , stage, host) ;
283+
272284 // The compiler that we're assembling
273285 let target_compiler = Compiler :: new ( stage, host) ;
274286
275287 // The compiler that compiled the compiler we're assembling
276288 let build_compiler = Compiler :: new ( stage - 1 , & build. config . build ) ;
277289
278- // Clear out old files
279- let sysroot = build. sysroot ( & target_compiler) ;
280- let _ = fs:: remove_dir_all ( & sysroot) ;
281- t ! ( fs:: create_dir_all( & sysroot) ) ;
282-
283290 // Link in all dylibs to the libdir
291+ let sysroot = build. sysroot ( & target_compiler) ;
284292 let sysroot_libdir = sysroot. join ( libdir ( host) ) ;
285293 t ! ( fs:: create_dir_all( & sysroot_libdir) ) ;
286294 let src_libdir = build. sysroot_libdir ( & build_compiler, host) ;
0 commit comments