14
14
#![ doc( html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png" ,
15
15
html_favicon_url = "http://www.rust-lang.org/favicon.ico" ,
16
16
html_root_url = "http://doc.rust-lang.org/master/" ) ]
17
+ #![ cfg_attr( target_os = "nacl" , allow( dead_code) ) ]
17
18
18
19
#![ feature( rustc_private, libc, collections, exit_status) ]
19
20
@@ -32,7 +33,7 @@ use std::env;
32
33
use std:: ptr;
33
34
use std:: ffi;
34
35
use std:: fmt:: Display ;
35
- use std:: path:: Path ;
36
+ use std:: path:: { Path , PathBuf } ;
36
37
37
38
// From librustc:
38
39
pub fn host_triple ( ) -> & ' static str {
@@ -56,17 +57,30 @@ fn get_native_arch() -> &'static str {
56
57
}
57
58
}
58
59
59
- fn optgroups ( ) -> Vec < OptGroup > {
60
+ fn inner_optgroups ( ) -> Vec < OptGroup > {
60
61
vec ! ( optflag( "h" , "help" , "Display this message" ) ,
61
62
reqopt( "o" , "" , "Write the linked output to this file" , "" ) ,
62
63
optopt( "" , "opt-level" , "Optimize with possible levels 0-3" , "LEVEL" ) ,
63
64
optflag( "" , "save-temps" , "Save temp files" ) ,
64
65
optopt( "" , "target" , "The target triple to codegen for" , "" ) ,
65
- reqopt( "" , "cross-path" , "The path to the Pepper SDK" , "" ) ,
66
66
optmulti( "" , "raw" , "The specified bitcodes have had none of the usual PNaCl IR \
67
67
legalization passes run on them", "" ) ,
68
68
optflag( "" , "all-raw" , "All input bitcodes are of raw form" ) )
69
69
}
70
+ #[ cfg( not( target_os = "nacl" ) ) ]
71
+ fn optgroups ( ) -> Vec < OptGroup > {
72
+ let mut opts = inner_optgroups ( ) ;
73
+ opts. push ( reqopt ( "" , "cross-path" , "The path to the Pepper SDK" , "" ) ) ;
74
+ opts
75
+ }
76
+ #[ cfg( target_os = "nacl" ) ]
77
+ fn optgroups ( ) -> Vec < OptGroup > {
78
+ let mut opts = inner_optgroups ( ) ;
79
+ // on nacl
80
+ opts. push ( optopt ( "" , "cross-path" , "Ignored" , "" ) ) ;
81
+ opts
82
+ }
83
+
70
84
fn fatal < T : Display > ( msg : T ) -> ! {
71
85
println ! ( "error: {}" , msg) ;
72
86
env:: set_exit_status ( 1 ) ;
@@ -93,6 +107,9 @@ pub fn llvm_warn<T: Display>(msg: T) {
93
107
94
108
pub fn main ( ) {
95
109
let args: Vec < String > = env:: args ( ) . collect ( ) ;
110
+
111
+ let is_host_nacl = host_triple ( ) . ends_with ( "nacl" ) ;
112
+
96
113
let opts = optgroups ( ) ;
97
114
98
115
let matches = match getopts ( args. tail ( ) , & opts[ ..] ) {
@@ -130,10 +147,16 @@ pub fn main() {
130
147
format ! ( "{}-none-nacl-gnu" , get_native_arch( ) )
131
148
}
132
149
} ;
133
- let cross_path = matches. opt_str ( "cross-path" ) . unwrap ( ) ;
134
- let cross_path = env:: current_dir ( )
135
- . unwrap ( )
136
- . join ( & cross_path[ ..] ) ;
150
+
151
+ let cross_path = if !is_host_nacl {
152
+ let cross_path = matches. opt_str ( "cross-path" ) . unwrap ( ) ;
153
+ env:: current_dir ( )
154
+ . unwrap ( )
155
+ . join ( & cross_path[ ..] )
156
+ } else {
157
+ Path :: new ( "/" )
158
+ . to_path_buf ( )
159
+ } ;
137
160
138
161
let all_raw = matches. opt_present ( "all-raw" ) ;
139
162
let mut input: Vec < ( String , bool ) > = matches. free
@@ -225,10 +248,10 @@ pub fn main() {
225
248
}
226
249
}
227
250
228
- // Only initialize the platforms supported by Rust here, because
229
- // using --llvm-root will have multiple platforms that rustllvm
230
- // doesn't actually link to and it's pointless to put target info
231
- // into the registry that Rust cannot generate machine code for.
251
+ // Only initialize the platforms supported by PNaCl && Rust here,
252
+ // because using --llvm-root will have multiple platforms that rustllvm
253
+ // doesn't actually link to and it's pointless to put target info into
254
+ // the registry that Rust cannot generate machine code for.
232
255
llvm:: LLVMInitializeX86TargetInfo ( ) ;
233
256
llvm:: LLVMInitializeX86Target ( ) ;
234
257
llvm:: LLVMInitializeX86TargetMC ( ) ;
@@ -334,45 +357,66 @@ pub fn main() {
334
357
335
358
debug ! ( "linking" ) ;
336
359
337
- let mut toolchain_path = cross_path. clone ( ) ;
338
- toolchain_path. push ( "toolchain" ) ;
339
- toolchain_path. push ( & {
340
- let mut s = pnacl_toolchain_prefix ( ) ;
341
- s. push_str ( "_pnacl" ) ;
342
- s
343
- } ) ;
344
-
345
-
346
- let mut tcp = toolchain_path. clone ( ) ;
347
- tcp. push ( "translator" ) ;
348
- tcp. push ( arch) ;
349
- tcp. push ( "lib" ) ;
350
-
351
- let crtbegin = tcp. clone ( )
352
- . join ( "crtbegin.o" )
353
- . into_os_string ( )
354
- . into_string ( )
355
- . unwrap ( ) ;
356
- let pnacl_irt_shim = tcp. clone ( )
357
- . join ( "libpnacl_irt_shim.a" )
358
- . into_os_string ( )
359
- . into_string ( )
360
- . unwrap ( ) ;
361
- let gcc = tcp. clone ( )
362
- . join ( "libgcc.a" )
363
- . into_os_string ( )
364
- . into_string ( )
365
- . unwrap ( ) ;
366
- let crt_platform = tcp. clone ( )
367
- . join ( "libcrt_platform.a" )
368
- . into_os_string ( )
369
- . into_string ( )
370
- . unwrap ( ) ;
371
- let crtend = tcp. clone ( )
372
- . join ( "crtend.o" )
373
- . into_os_string ( )
374
- . into_string ( )
375
- . unwrap ( ) ;
360
+ static NATIVE_SUPPORT_LIBS : & ' static [ & ' static str ] =
361
+ & [ "crtbegin.o" ,
362
+ "libpnacl_irt_shim.a" ,
363
+ "libgcc.a" ,
364
+ "libcrt_platform.a" ,
365
+ "crtend.o" ] ;
366
+
367
+ #[ cfg( not( target_os = "nacl" ) ) ]
368
+ fn get_native_support_lib_paths < P : AsRef < Path > > ( cross_path : P , arch : & str )
369
+ -> Vec < String >
370
+ {
371
+ let mut toolchain_path = cross_path
372
+ . as_ref ( )
373
+ . join ( "toolchain" )
374
+ . to_path_buf ( ) ;
375
+ toolchain_path. push ( & {
376
+ let mut s = pnacl_toolchain_prefix ( ) ;
377
+ s. push_str ( "_pnacl" ) ;
378
+ s
379
+ } ) ;
380
+
381
+
382
+ let mut tcp = toolchain_path;
383
+ tcp. push ( "translator" ) ;
384
+ tcp. push ( arch) ;
385
+ tcp. push ( "lib" ) ;
386
+
387
+ NATIVE_SUPPORT_LIBS . iter ( )
388
+ . map ( |lib| {
389
+ tcp. clone ( )
390
+ . join ( lib)
391
+ . into_os_string ( )
392
+ . into_string ( )
393
+ . unwrap ( )
394
+ } )
395
+ . collect ( )
396
+ }
397
+ #[ cfg( target_os = "nacl" ) ]
398
+ fn get_native_support_lib_paths < P : AsRef < Path > > ( _: P , arch : & str ) -> Vec < String > {
399
+ let lib_path = Path :: new ( "/lib" )
400
+ . join ( "translator" )
401
+ . join ( arch) ;
402
+ NATIVE_SUPPORT_LIBS . iter ( )
403
+ . map ( |lib| {
404
+ lib_path
405
+ . join ( lib)
406
+ . into_os_string ( )
407
+ . into_string ( )
408
+ . unwrap ( )
409
+ } )
410
+ . collect ( )
411
+ }
412
+
413
+ let libs = get_native_support_lib_paths ( & cross_path, arch) ;
414
+ debug_assert ! ( libs. len( ) == 5 ) ;
415
+ let crtbegin = libs[ 0 ] . clone ( ) ;
416
+ let pnacl_irt_shim = libs[ 1 ] . clone ( ) ;
417
+ let gcc = libs[ 2 ] . clone ( ) ;
418
+ let crt_platform = libs[ 3 ] . clone ( ) ;
419
+ let crtend = libs[ 4 ] . clone ( ) ;
376
420
377
421
let nexe_link_args = vec ! ( "-nostdlib" . to_string( ) ,
378
422
"--no-fix-cortex-a8" . to_string( ) ,
@@ -397,10 +441,34 @@ pub fn main() {
397
441
. chain ( nexe_link_args_suffix. into_iter ( ) )
398
442
. collect ( ) ;
399
443
400
- let mut gold = toolchain_path. clone ( ) ;
401
- gold. push ( "bin" ) ;
402
- gold. push ( "le32-nacl-ld.gold" ) ;
403
- let gold = gold;
444
+ #[ cfg( not( target_os = "nacl" ) ) ]
445
+ fn get_linker < P : AsRef < Path > > ( cross_path : P ) -> PathBuf {
446
+ let mut toolchain_path = cross_path
447
+ . as_ref ( )
448
+ . to_path_buf ( ) ;
449
+ toolchain_path. push ( "toolchain" ) ;
450
+ toolchain_path. push ( & {
451
+ let mut s = pnacl_toolchain_prefix ( ) ;
452
+ s. push_str ( "_pnacl" ) ;
453
+ s
454
+ } ) ;
455
+
456
+ let mut gold = toolchain_path;
457
+ gold. push ( "bin" ) ;
458
+ gold. push ( "le32-nacl-ld.gold" ) ;
459
+ gold
460
+ }
461
+ #[ cfg( target_os = "nacl" ) ]
462
+ fn get_linker < P : AsRef < Path > > ( _: Path ) -> PathBuf {
463
+ use std:: env:: consts:: EXE_SUFFIX ;
464
+ let linker = format ! ( "ld.gold{}" ,
465
+ EXE_SUFFIX ) ;
466
+ Path :: new ( "/bin" )
467
+ . join ( & linker)
468
+ . to_path_buf ( )
469
+ }
470
+
471
+ let gold = get_linker ( & cross_path) ;
404
472
405
473
fn cleanup_objs ( m : & Matches , objs : Vec < String > ) {
406
474
use std:: fs:: remove_file;
0 commit comments