diff options
| author | bors <bors@rust-lang.org> | 2022-06-21 16:24:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-21 16:24:56 +0000 |
| commit | dc80ca78b6ec2b6bba02560470347433bcd0bb3c (patch) | |
| tree | fdb55256f83f00febe26d6d345a3c5811fc2fc81 /compiler/rustc_codegen_ssa/src/back | |
| parent | 72fd41a8b4d3488c97df3c3c75ddd9951aa3c73f (diff) | |
| parent | 7643f82e012c29603374fbdc4cd8c2ce3b600c82 (diff) | |
| download | rust-dc80ca78b6ec2b6bba02560470347433bcd0bb3c.tar.gz rust-dc80ca78b6ec2b6bba02560470347433bcd0bb3c.zip | |
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.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/back')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/archive.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 39 |
2 files changed, 21 insertions, 24 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index a2f74b94214..553486ae8ec 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -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, diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 39c7a408fb5..edf49b8c80e 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -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 mut any_objects = false; - for f in archive.src_files() { + 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 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); }); } |
