Skip to content

Commit 00bd733

Browse files
committed
Don't run ranlib when there are no object files in an archive
Fixes #869
1 parent ac14f8d commit 00bd733

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/archive.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
174174
BuilderKind::Bsd(ar::Builder::new(File::create(&self.config.dst).unwrap()))
175175
};
176176

177+
let has_any_object_files = self.entries.iter().any(|(name, _)| name.ends_with(".o"));
178+
177179
// Add all files
178180
for (entry_name, entry) in self.entries.into_iter() {
179181
match entry {
@@ -220,14 +222,16 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
220222
// Finalize archive
221223
std::mem::drop(builder);
222224

223-
// Run ranlib to be able to link the archive
224-
let status = std::process::Command::new("ranlib")
225-
.arg(self.config.dst)
226-
.status()
227-
.expect("Couldn't run ranlib");
225+
if has_any_object_files {
226+
// Run ranlib to be able to link the archive
227+
let status = std::process::Command::new("ranlib")
228+
.arg(self.config.dst)
229+
.status()
230+
.expect("Couldn't run ranlib");
228231

229-
if !status.success() {
230-
self.config.sess.fatal(&format!("Ranlib exited with code {:?}", status.code()));
232+
if !status.success() {
233+
self.config.sess.fatal(&format!("Ranlib exited with code {:?}", status.code()));
234+
}
231235
}
232236
}
233237
}

0 commit comments

Comments
 (0)