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