@@ -32,10 +32,12 @@ fn default_configuration(sess: session::session, argv0: str, input: str) ->
32
32
let mk = attr:: mk_name_value_item_str;
33
33
34
34
ret [ // Target bindings.
35
- mk ( "target_os" , std:: os:: target_os ( ) ) , mk ( "target_arch" , "x86" ) ,
35
+ mk ( "target_os" , std:: os:: target_os ( ) ) ,
36
+ mk ( "target_arch" , "x86" ) ,
36
37
mk ( "target_libc" , libc) ,
37
38
// Build bindings.
38
- mk ( "build_compiler" , argv0) , mk ( "build_input" , input) ] ;
39
+ mk ( "build_compiler" , argv0) ,
40
+ mk ( "build_input" , input) ] ;
39
41
}
40
42
41
43
fn build_configuration ( sess : session:: session , argv0 : str , input : str ) ->
@@ -224,6 +226,7 @@ fn version(argv0: str) {
224
226
let env_vers = #env[ "CFG_VERSION" ] ;
225
227
if str:: byte_len ( env_vers) != 0 u { vers = env_vers; }
226
228
io:: stdout ( ) . write_str ( #fmt[ "%s %s\n " , argv0, vers] ) ;
229
+ io:: stdout ( ) . write_str ( #fmt[ "host: %s\n " , host_triple ( ) ] ) ;
227
230
}
228
231
229
232
fn usage ( argv0 : str ) {
@@ -257,6 +260,7 @@ options:
257
260
--time-passes time the individual phases of the compiler
258
261
--time-llvm-passes time the individual phases of the LLVM backend
259
262
--sysroot <path> override the system root (default: rustc's directory)
263
+ --target <triple> target to compile for (default: host triple)
260
264
--no-typestate don't run the typestate pass (unsafe!)
261
265
--test build test harness
262
266
--gc garbage collect shared data (experimental/temporary)
@@ -295,26 +299,25 @@ fn get_default_sysroot(binary: str) -> str {
295
299
ret dirname;
296
300
}
297
301
298
- fn build_target_config ( ) -> @session:: config {
299
- let triple: str = str:: str_from_cstr ( llvm:: llvm:: LLVMRustGetHostTriple ( ) ) ;
302
+ fn build_target_config ( sopts : @session:: options ) -> @session:: config {
300
303
let target_cfg: @session:: config =
301
- @{ os: get_os ( triple ) ,
302
- arch: get_arch ( triple ) ,
304
+ @{ os: get_os ( sopts . target_triple ) ,
305
+ arch: get_arch ( sopts . target_triple ) ,
303
306
int_type: ast:: ty_i32,
304
307
uint_type: ast:: ty_u32,
305
308
float_type: ast:: ty_f64} ;
306
309
ret target_cfg;
307
310
}
308
311
312
+ fn host_triple ( ) -> str {
313
+ str:: str_from_cstr ( llvm:: llvm:: LLVMRustGetHostTriple ( ) )
314
+ }
315
+
309
316
fn build_session_options( binary : str , match : getopts:: match , binary_dir : str )
310
317
-> @session:: options {
311
318
let library = opt_present ( match , "lib" ) ;
312
319
let static = opt_present ( match , "static" ) ;
313
320
314
- let library_search_paths = [ binary_dir + "/lib" ] ;
315
- let lsp_vec = getopts:: opt_strs( match , "L" ) ;
316
- for lsp: str in lsp_vec { library_search_paths += [ lsp] ; }
317
-
318
321
let parse_only = opt_present ( match , "parse-only" ) ;
319
322
let no_trans = opt_present ( match , "no-trans" ) ;
320
323
@@ -336,6 +339,7 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
336
339
let time_llvm_passes = opt_present ( match , "time-llvm-passes" ) ;
337
340
let run_typestate = !opt_present ( match , "no-typestate" ) ;
338
341
let sysroot_opt = getopts:: opt_maybe_str ( match , "sysroot" ) ;
342
+ let target_opt = getopts:: opt_maybe_str ( match , "target" ) ;
339
343
let opt_level: uint =
340
344
if opt_present ( match , "O" ) {
341
345
if opt_present( match , "OptLevel" ) {
@@ -361,6 +365,17 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
361
365
none. { get_default_sysroot( binary) }
362
366
some( s) { s }
363
367
} ;
368
+ let target =
369
+ alt target_opt {
370
+ none. { host_triple( ) }
371
+ some ( s) { s }
372
+ } ;
373
+
374
+ let library_search_paths = [ binary_dir + "/lib" , // FIXME: legacy
375
+ binary_dir + "/lib/" + target ] ;
376
+ let lsp_vec = getopts:: opt_strs( match , "L" ) ;
377
+ for lsp: str in lsp_vec { library_search_paths += [ lsp] ; }
378
+
364
379
let cfg = parse_cfgspecs ( getopts:: opt_strs ( match , "cfg" ) ) ;
365
380
let test = opt_present ( match , "test" ) ;
366
381
let do_gc = opt_present ( match , "gc" ) ;
@@ -378,6 +393,7 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
378
393
output_type : output_type ,
379
394
library_search_paths : library_search_paths ,
380
395
sysroot : sysroot ,
396
+ target_triple : target ,
381
397
cfg : cfg ,
382
398
test : test ,
383
399
parse_only : parse_only ,
@@ -387,7 +403,7 @@ fn build_session_options(binary: str, match: getopts::match, binary_dir: str)
387
403
}
388
404
389
405
fn build_session ( sopts : @session:: options ) -> session:: session {
390
- let target_cfg = build_target_config ( ) ;
406
+ let target_cfg = build_target_config ( sopts ) ;
391
407
let cstore = cstore:: mk_cstore ( ) ;
392
408
ret session:: session ( target_cfg, sopts, cstore,
393
409
@{ cm: codemap:: new_codemap ( ) , mutable next_id: 0 } ,
@@ -412,9 +428,10 @@ fn opts() -> [getopts::opt] {
412
428
optflag ( "ls" ) , optflag ( "parse-only" ) , optflag ( "no-trans" ) ,
413
429
optflag ( "O" ) , optopt ( "OptLevel" ) , optmulti ( "L" ) , optflag ( "S" ) ,
414
430
optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) , optflag ( "save-temps" ) ,
415
- optopt ( "sysroot" ) , optflag ( "stats" ) , optflag ( "time-passes" ) ,
416
- optflag ( "time-llvm-passes" ) , optflag ( "no-typestate" ) ,
417
- optflag ( "noverify" ) , optmulti ( "cfg" ) , optflag ( "test" ) ,
431
+ optopt ( "sysroot" ) , optopt ( "target" ) , optflag ( "stats" ) ,
432
+ optflag ( "time-passes" ) , optflag ( "time-llvm-passes" ) ,
433
+ optflag ( "no-typestate" ) , optflag ( "noverify" ) ,
434
+ optmulti ( "cfg" ) , optflag ( "test" ) ,
418
435
optflag ( "lib" ) , optflag ( "static" ) , optflag ( "gc" ) ] ;
419
436
}
420
437
0 commit comments