Skip to content

Commit

Permalink
Split s out of the ar invocation (#570)
Browse files Browse the repository at this point in the history
This commit splits out the `s` command from the `ar` invocation to
happen as part of a separate step after the archive is fully assembled.
Turns out #569 has an issue on Linux where `qs` implies `r` (??), so to
get the append-only behavior of `q` we need to omit the `s`.

Closes #568 (for real this time?)
  • Loading branch information
alexcrichton authored Nov 20, 2020
1 parent 3c1e2f4 commit 801a87b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cc"
version = "1.0.64"
version = "1.0.65"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT/Apache-2.0"
repository = "https://github.com/alexcrichton/cc-rs"
Expand Down
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1777,17 +1777,20 @@ impl Build {
// Delete the destination if it exists as we want to
// create on the first iteration instead of appending.
let _ = fs::remove_file(&dst);
let target = self.get_target()?;

// Add objects to the archive in limited-length batches. This helps keep
// the length of the command line within a reasonable length to avoid
// blowing system limits on limiting platforms like Windows.
let objs: Vec<_> = objs
.iter()
.map(|o| o.dst.clone())
.chain(self.objects.clone())
.collect();

for chunk in objs.chunks(100) {
self.assemble_progressive(dst, chunk)?;
}

let target = self.get_target()?;
if target.contains("msvc") {
// The Rust compiler will look for libfoo.a and foo.lib, but the
// MSVC linker will also be passed foo.lib, so be sure that both
Expand All @@ -1807,6 +1810,12 @@ impl Build {
));
}
};
} else {
// Non-msvc targets (those using `ar`) need a separate step to add
// the symbol table to archives since our construction command of
// `cq` doesn't add it for us.
let (mut ar, cmd) = self.get_ar()?;
run(ar.arg("s").arg(dst), &cmd)?;
}

Ok(())
Expand Down Expand Up @@ -1859,7 +1868,7 @@ impl Build {
for flag in self.ar_flags.iter() {
ar.arg(flag);
}
run(ar.arg("cqs").arg(dst).args(objs), &cmd)?;
run(ar.arg("cq").arg(dst).args(objs), &cmd)?;
}

Ok(())
Expand Down

0 comments on commit 801a87b

Please sign in to comment.