Skip to content

Commit 5079272

Browse files
committed
auto merge of #18739 : vhbit/rust/issue-18574, r=alexcrichton
Fixes #18574
2 parents efc9a44 + a722f70 commit 5079272

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/librustc/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) {
734734
let mut all_native_libs = vec![];
735735

736736
for &(cnum, ref path) in crates.iter() {
737-
let name = sess.cstore.get_crate_data(cnum).name.clone();
737+
let ref name = sess.cstore.get_crate_data(cnum).name;
738738
let p = match *path {
739739
Some(ref p) => p.clone(), None => {
740740
sess.err(format!("could not find rlib for: `{}`",

src/librustc_back/archive.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'a> ArchiveBuilder<'a> {
183183
self.archive.slib_suffix.as_slice(),
184184
self.archive.lib_search_paths.as_slice(),
185185
self.archive.handler);
186-
self.add_archive(&location, name, [])
186+
self.add_archive(&location, name, |_| false)
187187
}
188188

189189
/// Adds all of the contents of the rlib at the specified path to this
@@ -193,13 +193,20 @@ impl<'a> ArchiveBuilder<'a> {
193193
/// then the object file also isn't added.
194194
pub fn add_rlib(&mut self, rlib: &Path, name: &str,
195195
lto: bool) -> io::IoResult<()> {
196-
let object = format!("{}.o", name);
197-
let bytecode = format!("{}.bytecode.deflate", name);
198-
let mut ignore = vec!(bytecode.as_slice(), METADATA_FILENAME);
199-
if lto {
200-
ignore.push(object.as_slice());
201-
}
202-
self.add_archive(rlib, name, ignore.as_slice())
196+
// Ignoring obj file starting with the crate name
197+
// as simple comparison is not enough - there
198+
// might be also an extra name suffix
199+
let obj_start = format!("{}", name);
200+
let obj_start = obj_start.as_slice();
201+
// Ignoring all bytecode files, no matter of
202+
// name
203+
let bc_ext = ".bytecode.deflate";
204+
205+
self.add_archive(rlib, name.as_slice(), |fname: &str| {
206+
let skip_obj = lto && fname.starts_with(obj_start)
207+
&& fname.ends_with(".o");
208+
skip_obj || fname.ends_with(bc_ext) || fname == METADATA_FILENAME
209+
})
203210
}
204211

205212
/// Adds an arbitrary file to this archive
@@ -273,7 +280,7 @@ impl<'a> ArchiveBuilder<'a> {
273280
}
274281

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

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

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

0 commit comments

Comments
 (0)