@@ -58,6 +58,30 @@ pub fn std<'a>(build: &'a Build, stage: u32, target: &str,
58
58
}
59
59
60
60
build. run ( & mut cargo) ;
61
+ std_link ( build, stage, target, compiler, host) ;
62
+ }
63
+
64
+ /// Link all libstd rlibs/dylibs into the sysroot location.
65
+ ///
66
+ /// Links those artifacts generated in the given `stage` for `target` produced
67
+ /// by `compiler` into `host`'s sysroot.
68
+ pub fn std_link ( build : & Build ,
69
+ stage : u32 ,
70
+ target : & str ,
71
+ compiler : & Compiler ,
72
+ host : & str ) {
73
+ let libdir = build. sysroot_libdir ( stage, host, target) ;
74
+ let out_dir = build. cargo_out ( stage, compiler. host , true , target) ;
75
+
76
+ // If we're linking one compiler host's output into another, then we weren't
77
+ // called from the `std` method above. In that case we clean out what's
78
+ // already there and then also link compiler-rt into place.
79
+ if host != compiler. host {
80
+ let _ = fs:: remove_dir_all ( & libdir) ;
81
+ t ! ( fs:: create_dir_all( & libdir) ) ;
82
+ t ! ( fs:: hard_link( & build. compiler_rt_built. borrow( ) [ target] ,
83
+ libdir. join( staticlib( "compiler-rt" , target) ) ) ) ;
84
+ }
61
85
add_to_sysroot ( & out_dir, & libdir) ;
62
86
}
63
87
@@ -99,7 +123,6 @@ pub fn rustc<'a>(build: &'a Build, stage: u32, target: &str,
99
123
host, target) ;
100
124
101
125
let out_dir = build. cargo_out ( stage, & host, false , target) ;
102
- let rustc = out_dir. join ( exe ( "rustc" , target) ) ;
103
126
build. clear_if_dirty ( & out_dir, & libstd_shim ( build, stage, & host, target) ) ;
104
127
105
128
let mut cargo = build. cargo ( stage, compiler, false , target, "build" ) ;
@@ -131,10 +154,13 @@ pub fn rustc<'a>(build: &'a Build, stage: u32, target: &str,
131
154
if !build. unstable_features {
132
155
cargo. env ( "CFG_DISABLE_UNSTABLE_FEATURES" , "1" ) ;
133
156
}
134
- if let Some ( config) = build. config . target_config . get ( target) {
135
- if let Some ( ref s) = config. llvm_config {
136
- cargo. env ( "LLVM_CONFIG" , s) ;
137
- }
157
+ let target_config = build. config . target_config . get ( target) ;
158
+ if let Some ( ref s) = target_config. and_then ( |c| c. llvm_config . as_ref ( ) ) {
159
+ cargo. env ( "LLVM_CONFIG" , s) ;
160
+ } else {
161
+ let llvm_config = build. llvm_out ( & build. config . build ) . join ( "bin" )
162
+ . join ( exe ( "llvm-config" , target) ) ;
163
+ cargo. env ( "LLVM_CONFIG" , llvm_config) ;
138
164
}
139
165
if build. config . llvm_static_stdcpp {
140
166
cargo. env ( "LLVM_STATIC_STDCPP" ,
@@ -148,12 +174,21 @@ pub fn rustc<'a>(build: &'a Build, stage: u32, target: &str,
148
174
}
149
175
build. run ( & mut cargo) ;
150
176
151
- let sysroot_libdir = build . sysroot_libdir ( stage , host , target) ;
152
- add_to_sysroot ( & out_dir , & sysroot_libdir ) ;
177
+ rustc_link ( build , stage , target, compiler , compiler . host ) ;
178
+ }
153
179
154
- if host == target {
155
- assemble_compiler ( build, stage, target, & rustc) ;
156
- }
180
+ /// Link all librustc rlibs/dylibs into the sysroot location.
181
+ ///
182
+ /// Links those artifacts generated in the given `stage` for `target` produced
183
+ /// by `compiler` into `host`'s sysroot.
184
+ pub fn rustc_link ( build : & Build ,
185
+ stage : u32 ,
186
+ target : & str ,
187
+ compiler : & Compiler ,
188
+ host : & str ) {
189
+ let libdir = build. sysroot_libdir ( stage, host, target) ;
190
+ let out_dir = build. cargo_out ( stage, compiler. host , false , target) ;
191
+ add_to_sysroot ( & out_dir, & libdir) ;
157
192
}
158
193
159
194
/// Cargo's output path for the standard library in a given stage, compiled
@@ -169,39 +204,42 @@ fn compiler_file(compiler: &Path, file: &str) -> String {
169
204
170
205
/// Prepare a new compiler from the artifacts in `stage`
171
206
///
172
- /// This will link the compiler built by ` host` during the stage
173
- /// specified to the sysroot location for `host` to be the official
174
- /// `stage + 1` compiler for that host. This means that the `rustc` binary
175
- /// itself will be linked into place along with all supporting dynamic
176
- /// libraries.
177
- fn assemble_compiler ( build : & Build , stage : u32 , host : & str , rustc : & Path ) {
207
+ /// This will assemble a compiler in `build/$ host/stage$stage`. The compiler
208
+ /// must have been previously produced by the `stage - 1` build.config.build
209
+ /// compiler.
210
+ pub fn assemble_rustc ( build : & Build , stage : u32 , host : & str ) {
211
+ assert ! ( stage > 0 , "the stage0 compiler isn't assembled, it's downloaded" ) ;
212
+
178
213
// Clear out old files
179
- let sysroot = build. sysroot ( stage + 1 , host) ;
214
+ let sysroot = build. sysroot ( stage, host) ;
180
215
let _ = fs:: remove_dir_all ( & sysroot) ;
181
216
t ! ( fs:: create_dir_all( & sysroot) ) ;
182
217
183
218
// Link in all dylibs to the libdir
184
219
let sysroot_libdir = sysroot. join ( libdir ( host) ) ;
185
220
t ! ( fs:: create_dir_all( & sysroot_libdir) ) ;
186
- let src_libdir = build. sysroot_libdir ( stage, host , host) ;
221
+ let src_libdir = build. sysroot_libdir ( stage - 1 , & build . config . build , host) ;
187
222
for f in t ! ( fs:: read_dir( & src_libdir) ) . map ( |f| t ! ( f) ) {
188
223
let filename = f. file_name ( ) . into_string ( ) . unwrap ( ) ;
189
224
if is_dylib ( & filename) {
190
225
t ! ( fs:: hard_link( & f. path( ) , sysroot_libdir. join( & filename) ) ) ;
191
226
}
192
227
}
193
228
229
+ let out_dir = build. cargo_out ( stage - 1 , & build. config . build , false , host) ;
230
+
194
231
// Link the compiler binary itself into place
232
+ let rustc = out_dir. join ( exe ( "rustc" , host) ) ;
195
233
let bindir = sysroot. join ( "bin" ) ;
196
234
t ! ( fs:: create_dir_all( & bindir) ) ;
197
- let compiler = build. compiler_path ( & Compiler :: new ( stage + 1 , host) ) ;
235
+ let compiler = build. compiler_path ( & Compiler :: new ( stage, host) ) ;
198
236
let _ = fs:: remove_file ( & compiler) ;
199
237
t ! ( fs:: hard_link( rustc, compiler) ) ;
200
238
201
239
// See if rustdoc exists to link it into place
202
- let exe = exe ( "rustdoc" , host) ;
203
- let rustdoc_src = rustc . parent ( ) . unwrap ( ) . join ( & exe ) ;
204
- let rustdoc_dst = bindir. join ( exe ) ;
240
+ let rustdoc = exe ( "rustdoc" , host) ;
241
+ let rustdoc_src = out_dir . join ( & rustdoc ) ;
242
+ let rustdoc_dst = bindir. join ( & rustdoc ) ;
205
243
if fs:: metadata ( & rustdoc_src) . is_ok ( ) {
206
244
let _ = fs:: remove_file ( & rustdoc_dst) ;
207
245
t ! ( fs:: hard_link( & rustdoc_src, & rustdoc_dst) ) ;
0 commit comments