1
Fork 0

Remove src_files and remove_file

They only apply to the main source archive and their role can be
fulfilled through the skip argument of add_archive too.
This commit is contained in:
bjorn3 2022-06-14 15:11:14 +00:00
parent 70e084aa21
commit 43929a8a75
5 changed files with 14 additions and 73 deletions

View file

@ -45,8 +45,6 @@ pub trait ArchiveBuilder<'a> {
fn new(sess: &'a Session, output: &Path, input: Option<&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

View file

@ -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, None);
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,20 +2492,16 @@ 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));
}
archive.build();
link_upstream(&dst);