@@ -83,6 +83,12 @@ pub struct Build {
83
83
compiler_rt_built : RefCell < HashMap < String , PathBuf > > ,
84
84
}
85
85
86
+ pub enum Mode {
87
+ Libstd ,
88
+ Librustc ,
89
+ Tool ,
90
+ }
91
+
86
92
impl Build {
87
93
pub fn new ( flags : Flags , config : Config ) -> Build {
88
94
let cwd = t ! ( env:: current_dir( ) ) ;
@@ -241,14 +247,17 @@ impl Build {
241
247
/// Cargo for the specified stage, whether or not the standard library is
242
248
/// being built, and using the specified compiler targeting `target`.
243
249
// FIXME: aren't stage/compiler duplicated?
244
- fn cargo ( & self , stage : u32 , compiler : & Compiler , is_std : bool ,
245
- target : & str , cmd : & str ) -> Command {
250
+ fn cargo ( & self ,
251
+ stage : u32 ,
252
+ compiler : & Compiler ,
253
+ mode : Mode ,
254
+ target : Option < & str > ,
255
+ cmd : & str ) -> Command {
246
256
let mut cargo = Command :: new ( & self . cargo ) ;
247
257
let host = compiler. host ;
248
- let out_dir = self . stage_out ( stage, host, is_std ) ;
258
+ let out_dir = self . stage_out ( stage, host, mode ) ;
249
259
cargo. env ( "CARGO_TARGET_DIR" , out_dir)
250
260
. arg ( cmd)
251
- . arg ( "--target" ) . arg ( target)
252
261
. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
253
262
254
263
// Customize the compiler we're running. Specify the compiler to cargo
@@ -265,24 +274,28 @@ impl Build {
265
274
. env ( "RUSTC_SNAPSHOT" , & self . rustc )
266
275
. env ( "RUSTC_SYSROOT" , self . sysroot ( stage, host) )
267
276
. env ( "RUSTC_SNAPSHOT_LIBDIR" , self . rustc_snapshot_libdir ( ) )
268
- . env ( "RUSTC_FLAGS" , self . rustc_flags ( target) . join ( " " ) )
269
277
. env ( "RUSTC_RPATH" , self . config . rust_rpath . to_string ( ) )
270
278
. env ( "RUSTDOC" , self . tool ( compiler, "rustdoc" ) ) ;
271
279
272
- // Specify some variuos options for build scripts used throughout the
273
- // build.
274
- //
275
- // FIXME: the guard against msvc shouldn't need to be here
276
- if !target. contains ( "msvc" ) {
277
- cargo. env ( format ! ( "CC_{}" , target) , self . cc ( target) )
278
- . env ( format ! ( "AR_{}" , target) , self . ar ( target) )
279
- . env ( format ! ( "CFLAGS_{}" , target) , self . cflags ( target) ) ;
280
- }
280
+ if let Some ( target) = target {
281
+ cargo. env ( "RUSTC_FLAGS" , self . rustc_flags ( target) . join ( " " ) ) ;
282
+ cargo. arg ( "--target" ) . arg ( target) ;
283
+
284
+ // Specify some various options for build scripts used throughout
285
+ // the build.
286
+ //
287
+ // FIXME: the guard against msvc shouldn't need to be here
288
+ if !target. contains ( "msvc" ) {
289
+ cargo. env ( format ! ( "CC_{}" , target) , self . cc ( target) )
290
+ . env ( format ! ( "AR_{}" , target) , self . ar ( target) )
291
+ . env ( format ! ( "CFLAGS_{}" , target) , self . cflags ( target) ) ;
292
+ }
281
293
282
- // Environment variables *required* needed throughout the build
283
- //
284
- // FIXME: should update code to not require this env vars
285
- cargo. env ( "CFG_COMPILER_HOST_TRIPLE" , target) ;
294
+ // Environment variables *required* needed throughout the build
295
+ //
296
+ // FIXME: should update code to not require this env vars
297
+ cargo. env ( "CFG_COMPILER_HOST_TRIPLE" , target) ;
298
+ }
286
299
287
300
if self . config . verbose || self . flags . verbose {
288
301
cargo. arg ( "-v" ) ;
@@ -306,7 +319,7 @@ impl Build {
306
319
307
320
/// Get the specified tool next to the specified compiler
308
321
fn tool ( & self , compiler : & Compiler , tool : & str ) -> PathBuf {
309
- self . stage_out ( compiler. stage , compiler. host , false )
322
+ self . stage_out ( compiler. stage , compiler. host , Mode :: Tool )
310
323
. join ( self . cargo_dir ( ) )
311
324
. join ( exe ( tool, compiler. host ) )
312
325
}
@@ -319,8 +332,8 @@ impl Build {
319
332
let host = compiler. host ;
320
333
let stage = compiler. stage ;
321
334
let paths = vec ! [
322
- self . cargo_out( stage, host, true , host) . join( "deps" ) ,
323
- self . cargo_out( stage, host, false , host) . join( "deps" ) ,
335
+ self . cargo_out( stage, host, Mode :: Libstd , host) . join( "deps" ) ,
336
+ self . cargo_out( stage, host, Mode :: Librustc , host) . join( "deps" ) ,
324
337
] ;
325
338
add_lib_path ( paths, & mut cmd) ;
326
339
return cmd
@@ -363,7 +376,7 @@ impl Build {
363
376
364
377
fn sysroot ( & self , stage : u32 , host : & str ) -> PathBuf {
365
378
if stage == 0 {
366
- self . stage_out ( stage, host, false )
379
+ self . stage_out ( stage, host, Mode :: Librustc )
367
380
} else {
368
381
self . out . join ( host) . join ( format ! ( "stage{}" , stage) )
369
382
}
@@ -377,19 +390,21 @@ impl Build {
377
390
/// Returns the root directory for all output generated in a particular
378
391
/// stage when running with a particular host compiler.
379
392
///
380
- /// The `is_std` flag indicates whether the root directory is for the
381
- /// bootstrap of the standard library or for the compiler.
382
- fn stage_out ( & self , stage : u32 , host : & str , is_std : bool ) -> PathBuf {
383
- self . out . join ( host)
384
- . join ( format ! ( "stage{}{}" , stage, if is_std { "-std" } else { "-rustc" } ) )
393
+ /// The mode indicates what the root directory is for.
394
+ fn stage_out ( & self , stage : u32 , host : & str , mode : Mode ) -> PathBuf {
395
+ let suffix = match mode {
396
+ Mode :: Libstd => "-std" ,
397
+ _ => "-rustc" ,
398
+ } ;
399
+ self . out . join ( host) . join ( format ! ( "stage{}{}" , stage, suffix) )
385
400
}
386
401
387
402
/// Returns the root output directory for all Cargo output in a given stage,
388
403
/// running a particular comipler, wehther or not we're building the
389
404
/// standard library, and targeting the specified architecture.
390
- fn cargo_out ( & self , stage : u32 , host : & str , is_std : bool ,
405
+ fn cargo_out ( & self , stage : u32 , host : & str , mode : Mode ,
391
406
target : & str ) -> PathBuf {
392
- self . stage_out ( stage, host, is_std ) . join ( target) . join ( self . cargo_dir ( ) )
407
+ self . stage_out ( stage, host, mode ) . join ( target) . join ( self . cargo_dir ( ) )
393
408
}
394
409
395
410
/// Root output directory for LLVM compiled for `target`
0 commit comments