@@ -22,7 +22,7 @@ use std::str;
2222
2323use libc;
2424use llvm:: archive_ro:: { ArchiveRO , Child } ;
25- use llvm;
25+ use llvm:: { self , ArchiveKind } ;
2626use rustc:: metadata:: loader:: METADATA_FILENAME ;
2727use rustc:: session:: Session ;
2828use rustc_back:: tempdir:: TempDir ;
@@ -208,28 +208,34 @@ impl<'a> ArchiveBuilder<'a> {
208208 /// Combine the provided files, rlibs, and native libraries into a single
209209 /// `Archive`.
210210 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 ( ) ,
215214 } ;
216215 if let Err ( e) = res {
217216 self . config . sess . fatal ( & format ! ( "failed to build archive: {}" , e) ) ;
218217 }
219218 }
220219
221- pub fn using_llvm ( & self ) -> bool {
220+ pub fn llvm_archive_kind ( & self ) -> Option < ArchiveKind > {
222221 if unsafe { llvm:: LLVMVersionMinor ( ) < 7 } {
223- return false
222+ return None
224223 }
225224
226225 // Currently LLVM only supports writing archives in the 'gnu' format.
227226 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 ,
230232 }
231233 }
232234
235+ pub fn using_llvm ( & self ) -> bool {
236+ self . llvm_archive_kind ( ) . is_some ( )
237+ }
238+
233239 fn build_with_ar_cmd ( & mut self ) -> io:: Result < ( ) > {
234240 let removals = mem:: replace ( & mut self . removals , Vec :: new ( ) ) ;
235241 let additions = mem:: replace ( & mut self . additions , Vec :: new ( ) ) ;
@@ -425,7 +431,7 @@ impl<'a> ArchiveBuilder<'a> {
425431 }
426432 }
427433
428- fn build_with_llvm ( & mut self ) -> io:: Result < ( ) > {
434+ fn build_with_llvm ( & mut self , kind : ArchiveKind ) -> io:: Result < ( ) > {
429435 let mut archives = Vec :: new ( ) ;
430436 let mut strings = Vec :: new ( ) ;
431437 let mut members = Vec :: new ( ) ;
@@ -482,7 +488,8 @@ impl<'a> ArchiveBuilder<'a> {
482488 let r = llvm:: LLVMRustWriteArchive ( dst. as_ptr ( ) ,
483489 members. len ( ) as libc:: size_t ,
484490 members. as_ptr ( ) ,
485- self . should_update_symbols ) ;
491+ self . should_update_symbols ,
492+ kind) ;
486493 let ret = if r != 0 {
487494 let err = llvm:: LLVMRustGetLastError ( ) ;
488495 let msg = if err. is_null ( ) {
0 commit comments