Auto merge of #98098 - bjorn3:archive_refactor, r=michaelwoerister
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. This is simpler and makes it easier to swap out the archive writer in https://github.com/rust-lang/rust/pull/97485.
This commit is contained in:
commit
dc80ca78b6
5 changed files with 61 additions and 192 deletions
|
@ -42,17 +42,15 @@ pub(super) fn find_library(
|
|||
}
|
||||
|
||||
pub trait ArchiveBuilder<'a> {
|
||||
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self;
|
||||
fn new(sess: &'a Session, output: &Path) -> Self;
|
||||
|
||||
fn add_file(&mut self, path: &Path);
|
||||
fn remove_file(&mut self, name: &str);
|
||||
fn src_files(&mut self) -> Vec<String>;
|
||||
|
||||
fn add_archive<F>(&mut self, archive: &Path, skip: F) -> io::Result<()>
|
||||
where
|
||||
F: FnMut(&str) -> bool + 'static;
|
||||
|
||||
fn build(self);
|
||||
fn build(self) -> bool;
|
||||
|
||||
fn inject_dll_import_lib(
|
||||
&mut self,
|
||||
|
|
|
@ -270,7 +270,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
let lib_search_paths = archive_search_paths(sess);
|
||||
|
||||
let mut ab = <B as ArchiveBuilder>::new(sess, out_filename, None);
|
||||
let mut ab = <B as ArchiveBuilder>::new(sess, out_filename);
|
||||
|
||||
let trailing_metadata = match flavor {
|
||||
RlibFlavor::Normal => {
|
||||
|
@ -2466,17 +2466,19 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
|||
let name = &name[3..name.len() - 5]; // chop off lib/.rlib
|
||||
|
||||
sess.prof.generic_activity_with_arg("link_altering_rlib", name).run(|| {
|
||||
let mut archive = <B as ArchiveBuilder>::new(sess, &dst, Some(cratepath));
|
||||
let canonical_name = name.replace('-', "_");
|
||||
let upstream_rust_objects_already_included =
|
||||
are_upstream_rust_objects_already_included(sess);
|
||||
let is_builtins = sess.target.no_builtins
|
||||
|| !codegen_results.crate_info.is_no_builtins.contains(&cnum);
|
||||
|
||||
let mut any_objects = false;
|
||||
for f in archive.src_files() {
|
||||
let mut archive = <B as ArchiveBuilder>::new(sess, &dst);
|
||||
if let Err(e) = archive.add_archive(cratepath, move |f| {
|
||||
if f == METADATA_FILENAME {
|
||||
archive.remove_file(&f);
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
|
||||
let canonical = f.replace('-', "_");
|
||||
let canonical_name = name.replace('-', "_");
|
||||
|
||||
let is_rust_object =
|
||||
canonical.starts_with(&canonical_name) && looks_like_rust_object_file(&f);
|
||||
|
@ -2490,23 +2492,20 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
|||
// file, then we don't need the object file as it's part of the
|
||||
// LTO module. Note that `#![no_builtins]` is excluded from LTO,
|
||||
// though, so we let that object file slide.
|
||||
let skip_because_lto = are_upstream_rust_objects_already_included(sess)
|
||||
&& is_rust_object
|
||||
&& (sess.target.no_builtins
|
||||
|| !codegen_results.crate_info.is_no_builtins.contains(&cnum));
|
||||
let skip_because_lto =
|
||||
upstream_rust_objects_already_included && is_rust_object && is_builtins;
|
||||
|
||||
if skip_because_cfg_say_so || skip_because_lto {
|
||||
archive.remove_file(&f);
|
||||
} else {
|
||||
any_objects = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if !any_objects {
|
||||
return;
|
||||
false
|
||||
}) {
|
||||
sess.fatal(&format!("failed to build archive from rlib: {}", e));
|
||||
}
|
||||
if archive.build() {
|
||||
link_upstream(&dst);
|
||||
}
|
||||
archive.build();
|
||||
link_upstream(&dst);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue