@@ -22,7 +22,7 @@ use std::str;
22
22
23
23
use libc;
24
24
use llvm:: archive_ro:: { ArchiveRO , Child } ;
25
- use llvm;
25
+ use llvm:: { self , ArchiveKind } ;
26
26
use rustc:: metadata:: loader:: METADATA_FILENAME ;
27
27
use rustc:: session:: Session ;
28
28
use rustc_back:: tempdir:: TempDir ;
@@ -208,28 +208,34 @@ impl<'a> ArchiveBuilder<'a> {
208
208
/// Combine the provided files, rlibs, and native libraries into a single
209
209
/// `Archive`.
210
210
pub fn build ( & mut self ) {
211
- let res = if self . using_llvm ( ) {
212
- self . build_with_llvm ( )
213
- } else {
214
- self . build_with_ar_cmd ( )
211
+ let res = match self . llvm_archive_kind ( ) {
212
+ Some ( kind) => self . build_with_llvm ( kind) ,
213
+ None => self . build_with_ar_cmd ( ) ,
215
214
} ;
216
215
if let Err ( e) = res {
217
216
self . config . sess . fatal ( & format ! ( "failed to build archive: {}" , e) ) ;
218
217
}
219
218
}
220
219
221
- pub fn using_llvm ( & self ) -> bool {
220
+ pub fn llvm_archive_kind ( & self ) -> Option < ArchiveKind > {
222
221
if unsafe { llvm:: LLVMVersionMinor ( ) < 7 } {
223
- return false
222
+ return None
224
223
}
225
224
226
225
// Currently LLVM only supports writing archives in the 'gnu' format.
227
226
match & self . config . sess . target . target . options . archive_format [ ..] {
228
- "gnu" => true ,
229
- _ => false ,
227
+ "gnu" => Some ( ArchiveKind :: K_GNU ) ,
228
+ "mips64" => Some ( ArchiveKind :: K_MIPS64 ) ,
229
+ "bsd" => Some ( ArchiveKind :: K_BSD ) ,
230
+ "coff" => Some ( ArchiveKind :: K_COFF ) ,
231
+ _ => None ,
230
232
}
231
233
}
232
234
235
+ pub fn using_llvm ( & self ) -> bool {
236
+ self . llvm_archive_kind ( ) . is_some ( )
237
+ }
238
+
233
239
fn build_with_ar_cmd ( & mut self ) -> io:: Result < ( ) > {
234
240
let removals = mem:: replace ( & mut self . removals , Vec :: new ( ) ) ;
235
241
let additions = mem:: replace ( & mut self . additions , Vec :: new ( ) ) ;
@@ -425,7 +431,7 @@ impl<'a> ArchiveBuilder<'a> {
425
431
}
426
432
}
427
433
428
- fn build_with_llvm ( & mut self ) -> io:: Result < ( ) > {
434
+ fn build_with_llvm ( & mut self , kind : ArchiveKind ) -> io:: Result < ( ) > {
429
435
let mut archives = Vec :: new ( ) ;
430
436
let mut strings = Vec :: new ( ) ;
431
437
let mut members = Vec :: new ( ) ;
@@ -482,7 +488,8 @@ impl<'a> ArchiveBuilder<'a> {
482
488
let r = llvm:: LLVMRustWriteArchive ( dst. as_ptr ( ) ,
483
489
members. len ( ) as libc:: size_t ,
484
490
members. as_ptr ( ) ,
485
- self . should_update_symbols ) ;
491
+ self . should_update_symbols ,
492
+ kind) ;
486
493
let ret = if r != 0 {
487
494
let err = llvm:: LLVMRustGetLastError ( ) ;
488
495
let msg = if err. is_null ( ) {
0 commit comments