Skip to content

Proper static lib packaging #18739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) {
let mut all_native_libs = vec![];

for &(cnum, ref path) in crates.iter() {
let name = sess.cstore.get_crate_data(cnum).name.clone();
let ref name = sess.cstore.get_crate_data(cnum).name;
let p = match *path {
Some(ref p) => p.clone(), None => {
sess.err(format!("could not find rlib for: `{}`",
Expand Down
27 changes: 17 additions & 10 deletions src/librustc_back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<'a> ArchiveBuilder<'a> {
self.archive.slib_suffix.as_slice(),
self.archive.lib_search_paths.as_slice(),
self.archive.handler);
self.add_archive(&location, name, [])
self.add_archive(&location, name, |_| false)
}

/// Adds all of the contents of the rlib at the specified path to this
Expand All @@ -193,13 +193,20 @@ impl<'a> ArchiveBuilder<'a> {
/// then the object file also isn't added.
pub fn add_rlib(&mut self, rlib: &Path, name: &str,
lto: bool) -> io::IoResult<()> {
let object = format!("{}.o", name);
let bytecode = format!("{}.bytecode.deflate", name);
let mut ignore = vec!(bytecode.as_slice(), METADATA_FILENAME);
if lto {
ignore.push(object.as_slice());
}
self.add_archive(rlib, name, ignore.as_slice())
// Ignoring obj file starting with the crate name
// as simple comparison is not enough - there
// might be also an extra name suffix
let obj_start = format!("{}", name);
let obj_start = obj_start.as_slice();
// Ignoring all bytecode files, no matter of
// name
let bc_ext = ".bytecode.deflate";

self.add_archive(rlib, name.as_slice(), |fname: &str| {
let skip_obj = lto && fname.starts_with(obj_start)
&& fname.ends_with(".o");
skip_obj || fname.ends_with(bc_ext) || fname == METADATA_FILENAME
})
}

/// Adds an arbitrary file to this archive
Expand Down Expand Up @@ -273,7 +280,7 @@ impl<'a> ArchiveBuilder<'a> {
}

fn add_archive(&mut self, archive: &Path, name: &str,
skip: &[&str]) -> io::IoResult<()> {
skip: |&str| -> bool) -> io::IoResult<()> {
let loc = TempDir::new("rsar").unwrap();

// First, extract the contents of the archive to a temporary directory.
Expand All @@ -295,7 +302,7 @@ impl<'a> ArchiveBuilder<'a> {
let files = try!(fs::readdir(loc.path()));
for file in files.iter() {
let filename = file.filename_str().unwrap();
if skip.iter().any(|s| *s == filename) { continue }
if skip(filename) { continue }
if filename.contains(".SYMDEF") { continue }

let filename = format!("r-{}-{}", name, filename);
Expand Down