@@ -33,17 +33,12 @@ use {Build, Compiler, Mode};
33
33
/// This will build the standard library for a particular stage of the build
34
34
/// using the `compiler` targeting the `target` architecture. The artifacts
35
35
/// 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 ) {
40
37
let libdir = build. sysroot_libdir ( compiler, target) ;
41
- let _ = fs:: remove_dir_all ( & libdir) ;
42
38
t ! ( fs:: create_dir_all( & libdir) ) ;
43
39
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) ;
47
42
48
43
let out_dir = build. cargo_out ( compiler, Mode :: Libstd , target) ;
49
44
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>) {
65
60
66
61
build. run ( & mut cargo) ;
67
62
update_mtime ( & libstd_stamp ( build, & compiler, target) ) ;
68
- std_link ( build, target, compiler. stage , compiler. host ) ;
69
63
}
70
64
71
65
/// Link all libstd rlibs/dylibs into the sysroot location.
72
66
///
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.
75
73
pub 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) ;
81
83
let libdir = build. sysroot_libdir ( & target_compiler, target) ;
82
84
let out_dir = build. cargo_out ( & compiler, Mode :: Libstd , target) ;
83
85
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) ) ;
91
87
add_to_sysroot ( & out_dir, & libdir) ;
92
88
93
89
if target. contains ( "musl" ) && !target. contains ( "mips" ) {
@@ -110,20 +106,23 @@ fn copy_musl_third_party_objects(build: &Build, target: &str, into: &Path) {
110
106
/// They don't require any library support as they're just plain old object
111
107
/// files, so we just use the nightly snapshot compiler to always build them (as
112
108
/// 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 ) {
114
110
if !target. contains ( "pc-windows-gnu" ) {
115
111
return
116
112
}
113
+
117
114
let compiler = Compiler :: new ( 0 , & build. config . build ) ;
118
115
let compiler_path = build. compiler_path ( & compiler) ;
116
+ let into = build. sysroot_libdir ( for_compiler, target) ;
117
+ t ! ( fs:: create_dir_all( & into) ) ;
119
118
120
119
for file in t ! ( fs:: read_dir( build. src. join( "src/rtstartup" ) ) ) {
121
120
let file = t ! ( file) ;
122
121
let mut cmd = Command :: new ( & compiler_path) ;
123
122
build. run ( cmd. env ( "RUSTC_BOOTSTRAP" , "1" )
124
123
. arg ( "--target" ) . arg ( target)
125
124
. arg ( "--emit=obj" )
126
- . arg ( "--out-dir" ) . arg ( into)
125
+ . arg ( "--out-dir" ) . arg ( & into)
127
126
. arg ( file. path ( ) ) ) ;
128
127
}
129
128
@@ -137,7 +136,7 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) {
137
136
/// This will build libtest and supporting libraries for a particular stage of
138
137
/// the build using the `compiler` targeting the `target` architecture. The
139
138
/// 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 ) {
141
140
println ! ( "Building stage{} test artifacts ({} -> {})" , compiler. stage,
142
141
compiler. host, target) ;
143
142
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>) {
147
146
. arg ( build. src . join ( "src/rustc/test_shim/Cargo.toml" ) ) ;
148
147
build. run ( & mut cargo) ;
149
148
update_mtime ( & libtest_stamp ( build, compiler, target) ) ;
150
- test_link ( build, target, compiler. stage , compiler. host ) ;
151
149
}
152
150
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
157
152
pub 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) ;
163
162
let libdir = build. sysroot_libdir ( & target_compiler, target) ;
164
163
let out_dir = build. cargo_out ( & compiler, Mode :: Libtest , target) ;
165
164
add_to_sysroot ( & out_dir, & libdir) ;
@@ -170,7 +169,7 @@ pub fn test_link(build: &Build,
170
169
/// This will build the compiler for a particular stage of the build using
171
170
/// the `compiler` targeting the `target` architecture. The artifacts
172
171
/// 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 ) {
174
173
println ! ( "Building stage{} compiler artifacts ({} -> {})" ,
175
174
compiler. stage, compiler. host, target) ;
176
175
@@ -222,20 +221,19 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
222
221
cargo. env ( "CFG_DEFAULT_AR" , s) ;
223
222
}
224
223
build. run ( & mut cargo) ;
225
-
226
- rustc_link ( build, target, compiler. stage , compiler. host ) ;
227
224
}
228
225
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
233
227
pub 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) ;
239
237
let libdir = build. sysroot_libdir ( & target_compiler, target) ;
240
238
let out_dir = build. cargo_out ( & compiler, Mode :: Librustc , target) ;
241
239
add_to_sysroot ( & out_dir, & libdir) ;
@@ -259,6 +257,17 @@ fn compiler_file(compiler: &Path, file: &str) -> PathBuf {
259
257
PathBuf :: from ( out. trim ( ) )
260
258
}
261
259
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
+
262
271
/// Prepare a new compiler from the artifacts in `stage`
263
272
///
264
273
/// 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) {
269
278
if stage == 0 {
270
279
return
271
280
}
281
+
282
+ println ! ( "Copying stage{} compiler ({})" , stage, host) ;
283
+
272
284
// The compiler that we're assembling
273
285
let target_compiler = Compiler :: new ( stage, host) ;
274
286
275
287
// The compiler that compiled the compiler we're assembling
276
288
let build_compiler = Compiler :: new ( stage - 1 , & build. config . build ) ;
277
289
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
-
283
290
// Link in all dylibs to the libdir
291
+ let sysroot = build. sysroot ( & target_compiler) ;
284
292
let sysroot_libdir = sysroot. join ( libdir ( host) ) ;
285
293
t ! ( fs:: create_dir_all( & sysroot_libdir) ) ;
286
294
let src_libdir = build. sysroot_libdir ( & build_compiler, host) ;
0 commit comments