Skip to content

Commit 7ff0df5

Browse files
committed
Fix "Remove src_files and remove_file"
1 parent 43929a8 commit 7ff0df5

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

compiler/rustc_codegen_cranelift/src/archive.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
9292
Ok(())
9393
}
9494

95-
fn build(mut self) {
95+
fn build(mut self) -> bool {
9696
enum BuilderKind {
9797
Bsd(ar::Builder<File>),
9898
Gnu(ar::GnuBuilder<File>),
@@ -191,6 +191,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
191191
)
192192
};
193193

194+
let any_members = !entries.is_empty();
195+
194196
// Add all files
195197
for (entry_name, data) in entries.into_iter() {
196198
let header = ar::Header::new(entry_name, data.len() as u64);
@@ -216,6 +218,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
216218
self.sess.fatal(&format!("Ranlib exited with code {:?}", status.code()));
217219
}
218220
}
221+
222+
any_members
219223
}
220224

221225
fn inject_dll_import_lib(

compiler/rustc_codegen_gcc/src/archive.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
100100
Ok(())
101101
}
102102

103-
fn build(mut self) {
103+
fn build(mut self) -> bool {
104104
use std::process::Command;
105105

106106
fn add_file_using_ar(archive: &Path, file: &Path) {
@@ -133,6 +133,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
133133
BuilderKind::Bsd(ar::Builder::new(File::create(&self.config.dst).unwrap()))
134134
};
135135

136+
let any_members = !self.entries.is_empty();
137+
136138
// Add all files
137139
for (entry_name, entry) in self.entries.into_iter() {
138140
match entry {
@@ -193,6 +195,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
193195
if !status.success() {
194196
self.config.sess.fatal(&format!("Ranlib exited with code {:?}", status.code()));
195197
}
198+
199+
any_members
196200
}
197201

198202
fn inject_dll_import_lib(&mut self, _lib_name: &str, _dll_imports: &[DllImport], _tmpdir: &MaybeTempDir) {

compiler/rustc_codegen_llvm/src/back/archive.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
9797

9898
/// Combine the provided files, rlibs, and native libraries into a single
9999
/// `Archive`.
100-
fn build(mut self) {
100+
fn build(mut self) -> bool {
101101
let kind = self.llvm_archive_kind().unwrap_or_else(|kind| {
102102
self.sess.fatal(&format!("Don't know how to build archive of type: {}", kind))
103103
});
104104

105-
if let Err(e) = self.build_with_llvm(kind) {
106-
self.sess.fatal(&format!("failed to build archive: {}", e));
105+
match self.build_with_llvm(kind) {
106+
Ok(any_members) => any_members,
107+
Err(e) => self.sess.fatal(&format!("failed to build archive: {}", e)),
107108
}
108109
}
109110

@@ -270,7 +271,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
270271
kind.parse().map_err(|_| kind)
271272
}
272273

273-
fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
274+
fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<bool> {
274275
let mut additions = mem::take(&mut self.additions);
275276
let mut strings = Vec::new();
276277
let mut members = Vec::new();
@@ -353,7 +354,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
353354
};
354355
Err(io::Error::new(io::ErrorKind::Other, msg))
355356
} else {
356-
Ok(())
357+
Ok(!members.is_empty())
357358
};
358359
for member in members {
359360
llvm::LLVMRustArchiveMemberFree(member);

compiler/rustc_codegen_ssa/src/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub trait ArchiveBuilder<'a> {
5050
where
5151
F: FnMut(&str) -> bool + 'static;
5252

53-
fn build(self);
53+
fn build(self) -> bool;
5454

5555
fn inject_dll_import_lib(
5656
&mut self,

compiler/rustc_codegen_ssa/src/back/link.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2503,8 +2503,9 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
25032503
}) {
25042504
sess.fatal(&format!("failed to build archive from rlib: {}", e));
25052505
}
2506-
archive.build();
2507-
link_upstream(&dst);
2506+
if archive.build() {
2507+
link_upstream(&dst);
2508+
}
25082509
});
25092510
}
25102511

0 commit comments

Comments
 (0)