@@ -167,15 +167,18 @@ pub mod write {
167
167
use back:: link:: { output_type_assembly, output_type_bitcode} ;
168
168
use back:: link:: { output_type_exe, output_type_llvm_assembly} ;
169
169
use back:: link:: { output_type_object} ;
170
+ use back:: link:: output_type;
170
171
use driver:: session:: Session ;
171
172
use driver:: session;
172
173
use lib:: llvm:: llvm;
173
174
use lib:: llvm:: { False , True , ModuleRef , mk_pass_manager, mk_target_data} ;
174
175
use lib;
175
176
177
+ use core:: prelude:: * ;
176
178
use core:: libc:: { c_char, c_int, c_uint} ;
177
179
use core:: path:: Path ;
178
180
use core:: str;
181
+ use core:: run;
179
182
180
183
pub fn is_object_or_assembly_or_exe ( ot : output_type ) -> bool {
181
184
if ot == output_type_assembly || ot == output_type_object ||
@@ -185,7 +188,8 @@ pub mod write {
185
188
return false ;
186
189
}
187
190
188
- pub fn run_passes ( sess : Session , llmod : ModuleRef , output : & Path ) {
191
+ pub fn run_passes ( sess : Session , llmod : ModuleRef ,
192
+ output_type : output_type , output : & Path ) {
189
193
unsafe {
190
194
let opts = sess. opts ;
191
195
if sess. time_llvm_passes ( ) { llvm:: LLVMRustEnableTimePasses ( ) ; }
@@ -201,7 +205,7 @@ pub mod write {
201
205
202
206
203
207
if opts. save_temps {
204
- match opts . output_type {
208
+ match output_type {
205
209
output_type_bitcode => {
206
210
if opts. optimize != session:: No {
207
211
let filename = output. with_filetype ( "no-opt.bc" ) ;
@@ -262,7 +266,7 @@ pub mod write {
262
266
llvm:: LLVMPassManagerBuilderDispose ( MPMB ) ;
263
267
}
264
268
if !sess. no_verify ( ) { llvm:: LLVMAddVerifierPass ( pm. llpm ) ; }
265
- if is_object_or_assembly_or_exe ( opts . output_type ) || opts. jit {
269
+ if is_object_or_assembly_or_exe ( output_type) || opts. jit {
266
270
let LLVMOptNone = 0 as c_int ; // -O0
267
271
let LLVMOptLess = 1 as c_int ; // -O1
268
272
let LLVMOptDefault = 2 as c_int ; // -O2, -Os
@@ -290,8 +294,8 @@ pub mod write {
290
294
}
291
295
292
296
let mut FileType ;
293
- if opts . output_type == output_type_object ||
294
- opts . output_type == output_type_exe {
297
+ if output_type == output_type_object ||
298
+ output_type == output_type_exe {
295
299
FileType = lib:: llvm:: ObjectFile ;
296
300
} else { FileType = lib:: llvm:: AssemblyFile ; }
297
301
// Write optimized bitcode if --save-temps was on.
@@ -307,7 +311,7 @@ pub mod write {
307
311
pm = mk_pass_manager ( ) ;
308
312
// Save the assembly file if -S is used
309
313
310
- if opts . output_type == output_type_assembly {
314
+ if output_type == output_type_assembly {
311
315
let _: ( ) = str:: as_c_str (
312
316
sess. targ_cfg . target_strs . target_triple ,
313
317
|buf_t| {
@@ -328,8 +332,8 @@ pub mod write {
328
332
329
333
// Save the object file for -c or --save-temps alone
330
334
// This .o is needed when an exe is built
331
- if opts . output_type == output_type_object ||
332
- opts . output_type == output_type_exe {
335
+ if output_type == output_type_object ||
336
+ output_type == output_type_exe {
333
337
let _: ( ) = str:: as_c_str (
334
338
sess. targ_cfg . target_strs . target_triple ,
335
339
|buf_t| {
@@ -375,7 +379,7 @@ pub mod write {
375
379
return ;
376
380
}
377
381
378
- if opts . output_type == output_type_llvm_assembly {
382
+ if output_type == output_type_llvm_assembly {
379
383
// Given options "-S --emit-llvm": output LLVM assembly
380
384
str:: as_c_str ( output. to_str ( ) , |buf_o| {
381
385
llvm:: LLVMRustAddPrintModulePass ( pm. llpm , llmod, buf_o) } ) ;
@@ -391,6 +395,34 @@ pub mod write {
391
395
if sess. time_llvm_passes ( ) { llvm:: LLVMRustPrintPassTimings ( ) ; }
392
396
}
393
397
}
398
+
399
+ pub fn run_ndk( sess : Session , assembly : & Path , object : & Path ) {
400
+ let cc_prog: ~str = match & sess. opts . android_cross_path {
401
+ & Some ( copy path) => {
402
+ fmt ! ( "%s/bin/arm-linux-androideabi-gcc" , path)
403
+ }
404
+ & None => {
405
+ sess. fatal ( ~"need Android NDK path for building \
406
+ ( --android-cross-path) ")
407
+ }
408
+ } ;
409
+ let mut cc_args = ~[ ] ;
410
+ cc_args. push( ~"-c");
411
+ cc_args.push(~" -o") ;
412
+ cc_args. push( object. to_str( ) ) ;
413
+ cc_args. push( assembly. to_str( ) ) ;
414
+
415
+ let prog = run:: program_output( cc_prog, cc_args) ;
416
+
417
+ if prog. status != 0 {
418
+ sess. err( fmt ! ( "building with `%s` failed with code %d" ,
419
+ cc_prog, prog. status) ) ;
420
+ sess. note( fmt ! ( "%s arguments: %s" ,
421
+ cc_prog, str :: connect( cc_args, ~" ")));
422
+ sess.note(prog.err + prog.out);
423
+ sess.abort_if_errors();
424
+ }
425
+ }
394
426
}
395
427
396
428
0 commit comments