@@ -13,6 +13,7 @@ struct ArchiveConfig<'a> {
13
13
dst : PathBuf ,
14
14
lib_search_paths : Vec < PathBuf > ,
15
15
use_gnu_style_archive : bool ,
16
+ no_builtin_ranlib : bool ,
16
17
}
17
18
18
19
#[ derive( Debug ) ]
@@ -41,6 +42,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
41
42
dst : output. to_path_buf ( ) ,
42
43
lib_search_paths : archive_search_paths ( sess) ,
43
44
use_gnu_style_archive : sess. target . target . options . archive_format == "gnu" ,
45
+ no_builtin_ranlib : sess. target . target . options . is_like_osx ,
44
46
} ;
45
47
46
48
let ( src_archives, entries) = if let Some ( input) = input {
@@ -173,22 +175,24 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
173
175
}
174
176
} ;
175
177
176
- match object:: File :: parse ( & data) {
177
- Ok ( object) => {
178
- symbol_table. insert ( entry_name. as_bytes ( ) . to_vec ( ) , object. symbols ( ) . filter_map ( |( _index, symbol) | {
179
- if symbol. is_undefined ( ) || symbol. is_local ( ) || symbol. kind ( ) != SymbolKind :: Data && symbol. kind ( ) != SymbolKind :: Text && symbol. kind ( ) != SymbolKind :: Tls {
180
- None
178
+ if !self . config . no_builtin_ranlib {
179
+ match object:: File :: parse ( & data) {
180
+ Ok ( object) => {
181
+ symbol_table. insert ( entry_name. as_bytes ( ) . to_vec ( ) , object. symbols ( ) . filter_map ( |( _index, symbol) | {
182
+ if symbol. is_undefined ( ) || symbol. is_local ( ) || symbol. kind ( ) != SymbolKind :: Data && symbol. kind ( ) != SymbolKind :: Text && symbol. kind ( ) != SymbolKind :: Tls {
183
+ None
184
+ } else {
185
+ symbol. name ( ) . map ( |name| name. as_bytes ( ) . to_vec ( ) )
186
+ }
187
+ } ) . collect :: < Vec < _ > > ( ) ) ;
188
+ }
189
+ Err ( err) => {
190
+ let err = err. to_string ( ) ;
191
+ if err == "Unknown file magic" {
192
+ // Not an object file; skip it.
181
193
} else {
182
- symbol . name ( ) . map ( |name| name . as_bytes ( ) . to_vec ( ) )
194
+ self . config . sess . fatal ( & format ! ( "Error parsing `{}` during archive creation: {}" , entry_name , err ) ) ;
183
195
}
184
- } ) . collect :: < Vec < _ > > ( ) ) ;
185
- }
186
- Err ( err) => {
187
- let err = err. to_string ( ) ;
188
- if err == "Unknown file magic" {
189
- // Not an object file; skip it.
190
- } else {
191
- self . config . sess . fatal ( & format ! ( "Error parsing `{}` during archive creation: {}" , entry_name, err) ) ;
192
196
}
193
197
}
194
198
}
@@ -225,6 +229,23 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
225
229
. unwrap ( ) ,
226
230
}
227
231
}
232
+
233
+ // Finalize archive
234
+ std:: mem:: drop ( builder) ;
235
+
236
+ if self . config . no_builtin_ranlib {
237
+ let ranlib = crate :: toolchain:: get_toolchain_binary ( self . config . sess , "ranlib" ) ;
238
+
239
+ // Run ranlib to be able to link the archive
240
+ let status = std:: process:: Command :: new ( ranlib)
241
+ . arg ( self . config . dst )
242
+ . status ( )
243
+ . expect ( "Couldn't run ranlib" ) ;
244
+
245
+ if !status. success ( ) {
246
+ self . config . sess . fatal ( & format ! ( "Ranlib exited with code {:?}" , status. code( ) ) ) ;
247
+ }
248
+ }
228
249
}
229
250
}
230
251
0 commit comments