use std::fs::File;
use std::path::{Path, PathBuf};
-use rustc_codegen_ssa::back::archive::{find_library, ArchiveBuilder};
-use rustc_codegen_ssa::METADATA_FILENAME;
+use rustc_codegen_ssa::back::archive::ArchiveBuilder;
use rustc_session::Session;
use object::{Object, ObjectSymbol, SymbolKind};
pub(crate) struct ArArchiveBuilder<'a> {
sess: &'a Session,
dst: PathBuf,
- lib_search_paths: Vec<PathBuf>,
use_gnu_style_archive: bool,
no_builtin_ranlib: bool,
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
- use rustc_codegen_ssa::back::link::archive_search_paths;
-
let (src_archives, entries) = if let Some(input) = input {
let mut archive = ar::Archive::new(File::open(input).unwrap());
let mut entries = Vec::new();
ArArchiveBuilder {
sess,
dst: output.to_path_buf(),
- lib_search_paths: archive_search_paths(sess),
use_gnu_style_archive: sess.target.archive_format == "gnu",
// FIXME fix builtin ranlib on macOS
no_builtin_ranlib: sess.target.is_like_osx,
));
}
- 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();
- // Otherwise if this is *not* a rust object and we're skipping
- // objects then skip this file
- if skip_objects && (!fname.starts_with(&obj_start) || !fname.ends_with(".o")) {
- return true;
+ let mut i = 0;
+ while let Some(entry) = archive.next_entry() {
+ let entry = entry?;
+ let file_name = String::from_utf8(entry.header().identifier().to_vec())
+ .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?;
+ if !skip(&file_name) {
+ self.entries
+ .push((file_name, ArchiveEntry::FromArchive { archive_index, entry_index: i }));
}
+ i += 1;
+ }
- // ok, don't skip this
- false
- })
+ self.src_archives.push((archive_path.to_owned(), archive));
+ Ok(())
}
fn update_symbols(&mut self) {}
bug!("injecting dll imports is not supported");
}
}
-
-impl<'a> ArArchiveBuilder<'a> {
- fn add_archive<F>(&mut self, archive_path: PathBuf, 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();
-
- let mut i = 0;
- while let Some(entry) = archive.next_entry() {
- let entry = entry?;
- let file_name = String::from_utf8(entry.header().identifier().to_vec())
- .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?;
- if !skip(&file_name) {
- self.entries
- .push((file_name, ArchiveEntry::FromArchive { archive_index, entry_index: i }));
- }
- i += 1;
- }
-
- self.src_archives.push((archive_path, archive));
- Ok(())
- }
-}