Skip to content

Commit d7a5af6

Browse files
committed
Disable builtin ranlib on macOS
1 parent 80b6f47 commit d7a5af6

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

src/archive.rs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct ArchiveConfig<'a> {
1313
dst: PathBuf,
1414
lib_search_paths: Vec<PathBuf>,
1515
use_gnu_style_archive: bool,
16+
no_builtin_ranlib: bool,
1617
}
1718

1819
#[derive(Debug)]
@@ -41,6 +42,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
4142
dst: output.to_path_buf(),
4243
lib_search_paths: archive_search_paths(sess),
4344
use_gnu_style_archive: sess.target.target.options.archive_format == "gnu",
45+
no_builtin_ranlib: sess.target.target.options.is_like_osx,
4446
};
4547

4648
let (src_archives, entries) = if let Some(input) = input {
@@ -173,22 +175,24 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
173175
}
174176
};
175177

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.
181193
} 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));
183195
}
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));
192196
}
193197
}
194198
}
@@ -225,6 +229,23 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
225229
.unwrap(),
226230
}
227231
}
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+
}
228249
}
229250
}
230251

0 commit comments

Comments
 (0)