- fn add_native_library(&mut self, name: rustc_span::symbol::Symbol, verbatim: bool) {
- let location = find_library(name, verbatim, &self.lib_search_paths, self.sess);
- self.add_archive(location.clone(), |_| false).unwrap_or_else(|e| {
- panic!("failed to add native library {}: {}", location.to_string_lossy(), e);
- });
- }
-
- fn add_rlib(
- &mut self,
- rlib: &Path,
- name: &str,
- lto: bool,
- skip_objects: bool,
- ) -> std::io::Result<()> {
- let obj_start = name.to_owned();
-
- self.add_archive(rlib.to_owned(), move |fname: &str| {
- // Ignore metadata files, no matter the name.
- if fname == METADATA_FILENAME {
- return true;
- }
-
- // Don't include Rust objects if LTO is enabled
- if lto && fname.starts_with(&obj_start) && fname.ends_with(".o") {
- return true;
- }
+ fn add_archive<F>(&mut self, archive_path: &Path, mut skip: F) -> std::io::Result<()>
+ where
+ F: FnMut(&str) -> bool + 'static,
+ {
+ let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?);
+ let archive_index = self.src_archives.len();