Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 18c6fe5

Browse files
committed
Remove the source archive functionality of ArchiveWriter
We now build archives through strictly additive means rather than taking an existing archive and potentially substracting parts.
1 parent 7ff0df5 commit 18c6fe5

File tree

5 files changed

+11
-82
lines changed

5 files changed

+11
-82
lines changed

compiler/rustc_codegen_cranelift/src/archive.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,16 @@ pub(crate) struct ArArchiveBuilder<'a> {
3030
}
3131

3232
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
33-
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
34-
let (src_archives, entries) = if let Some(input) = input {
35-
let read_cache = ReadCache::new(File::open(input).unwrap());
36-
let archive = ArchiveFile::parse(&read_cache).unwrap();
37-
let mut entries = Vec::new();
38-
39-
for entry in archive.members() {
40-
let entry = entry.unwrap();
41-
entries.push((
42-
entry.name().to_vec(),
43-
ArchiveEntry::FromArchive { archive_index: 0, file_range: entry.file_range() },
44-
));
45-
}
46-
47-
(vec![read_cache.into_inner()], entries)
48-
} else {
49-
(vec![], Vec::new())
50-
};
51-
33+
fn new(sess: &'a Session, output: &Path) -> Self {
5234
ArArchiveBuilder {
5335
sess,
5436
dst: output.to_path_buf(),
5537
use_gnu_style_archive: sess.target.archive_format == "gnu",
5638
// FIXME fix builtin ranlib on macOS
5739
no_builtin_ranlib: sess.target.is_like_osx,
5840

59-
src_archives,
60-
entries,
41+
src_archives: vec![],
42+
entries: vec![],
6143
}
6244
}
6345

compiler/rustc_codegen_gcc/src/archive.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct ArArchiveBuilder<'a> {
3232
}
3333

3434
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
35-
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
35+
fn new(sess: &'a Session, output: &Path) -> Self {
3636
let config = ArchiveConfig {
3737
sess,
3838
dst: output.to_path_buf(),
@@ -41,32 +41,10 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
4141
use_gnu_style_archive: sess.target.options.archive_format == "gnu",
4242
};
4343

44-
let (src_archives, entries) = if let Some(input) = input {
45-
let mut archive = ar::Archive::new(File::open(input).unwrap());
46-
let mut entries = Vec::new();
47-
48-
let mut i = 0;
49-
while let Some(entry) = archive.next_entry() {
50-
let entry = entry.unwrap();
51-
entries.push((
52-
String::from_utf8(entry.header().identifier().to_vec()).unwrap(),
53-
ArchiveEntry::FromArchive {
54-
archive_index: 0,
55-
entry_index: i,
56-
},
57-
));
58-
i += 1;
59-
}
60-
61-
(vec![(input.to_owned(), archive)], entries)
62-
} else {
63-
(vec![], Vec::new())
64-
};
65-
6644
ArArchiveBuilder {
6745
config,
68-
src_archives,
69-
entries,
46+
src_archives: vec![],
47+
entries: vec![],
7048
}
7149
}
7250

compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ use rustc_session::Session;
2020
pub struct LlvmArchiveBuilder<'a> {
2121
sess: &'a Session,
2222
dst: PathBuf,
23-
src: Option<PathBuf>,
2423
additions: Vec<Addition>,
25-
src_archive: Option<Option<ArchiveRO>>,
2624
}
2725

2826
enum Addition {
@@ -59,14 +57,8 @@ fn llvm_machine_type(cpu: &str) -> LLVMMachineType {
5957
impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
6058
/// Creates a new static archive, ready for modifying the archive specified
6159
/// by `config`.
62-
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> LlvmArchiveBuilder<'a> {
63-
LlvmArchiveBuilder {
64-
sess,
65-
dst: output.to_path_buf(),
66-
src: input.map(|p| p.to_path_buf()),
67-
additions: Vec::new(),
68-
src_archive: None,
69-
}
60+
fn new(sess: &'a Session, output: &Path) -> LlvmArchiveBuilder<'a> {
61+
LlvmArchiveBuilder { sess, dst: output.to_path_buf(), additions: Vec::new() }
7062
}
7163

7264
fn add_archive<F>(&mut self, archive: &Path, skip: F) -> io::Result<()>
@@ -257,15 +249,6 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
257249
}
258250

259251
impl<'a> LlvmArchiveBuilder<'a> {
260-
fn src_archive(&mut self) -> Option<&ArchiveRO> {
261-
if let Some(ref a) = self.src_archive {
262-
return a.as_ref();
263-
}
264-
let src = self.src.as_ref()?;
265-
self.src_archive = Some(ArchiveRO::open(src).ok());
266-
self.src_archive.as_ref().unwrap().as_ref()
267-
}
268-
269252
fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
270253
let kind = &*self.sess.target.archive_format;
271254
kind.parse().map_err(|_| kind)
@@ -279,20 +262,6 @@ impl<'a> LlvmArchiveBuilder<'a> {
279262
let dst = CString::new(self.dst.to_str().unwrap())?;
280263

281264
unsafe {
282-
if let Some(archive) = self.src_archive() {
283-
for child in archive.iter() {
284-
let child = child.map_err(string_to_io_error)?;
285-
let Some(child_name) = child.name() else { continue };
286-
287-
let name = CString::new(child_name)?;
288-
members.push(llvm::LLVMRustArchiveMemberNew(
289-
ptr::null(),
290-
name.as_ptr(),
291-
Some(child.raw),
292-
));
293-
strings.push(name);
294-
}
295-
}
296265
for addition in &mut additions {
297266
match addition {
298267
Addition::File { path, name_in_archive } => {

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(super) fn find_library(
4242
}
4343

4444
pub trait ArchiveBuilder<'a> {
45-
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self;
45+
fn new(sess: &'a Session, output: &Path) -> Self;
4646

4747
fn add_file(&mut self, path: &Path);
4848

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
270270

271271
let lib_search_paths = archive_search_paths(sess);
272272

273-
let mut ab = <B as ArchiveBuilder>::new(sess, out_filename, None);
273+
let mut ab = <B as ArchiveBuilder>::new(sess, out_filename);
274274

275275
let trailing_metadata = match flavor {
276276
RlibFlavor::Normal => {
@@ -2472,7 +2472,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
24722472
let is_builtins = sess.target.no_builtins
24732473
|| !codegen_results.crate_info.is_no_builtins.contains(&cnum);
24742474

2475-
let mut archive = <B as ArchiveBuilder>::new(sess, &dst, None);
2475+
let mut archive = <B as ArchiveBuilder>::new(sess, &dst);
24762476
if let Err(e) = archive.add_archive(cratepath, move |f| {
24772477
if f == METADATA_FILENAME {
24782478
return true;

0 commit comments

Comments
 (0)