Skip to content

Commit e3ec58d

Browse files
froydnjglandium
authored andcommitted
upgrade ar crate so we can do less copying when trimming rlibs
The current trimming of rlibs in the dist-sccache case looks like: 1. Find the `rust.metadata.bin` file in the rlib (archive). 2. Read its data. 3. Create a new archive that will only contain said file. 4. Copy the data into the new archive. We can do better than this, by doing the following: 1. Find the `rust.metadata.bin` file in the rlib (archive). 2. Create a new archive that will only contain said file. 3. Copy the data from the original rlib directly into the new archive. We thus save a copy. All that being said, it looks like recent versions of Rust don't actually output `rust.metadata.bin` files into rlibs...unless we ought to be only taking the `lib.rmeta` file that lives inside the archive. But that would be a separate fix. (It's also great that we're seemingly copying the rmeta file twice, once because it lives in the rlib and once because it lives on disk as a separate file...)
1 parent 68c94c9 commit e3ec58d

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

Cargo.lock

+2-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ required-features = ["dist-server"]
2323

2424
[dependencies]
2525
anyhow = "1.0"
26-
ar = { version = "0.6", optional = true }
26+
ar = { version = "0.8", optional = true }
2727
atty = "0.2.6"
2828
base64 = "0.11.0"
2929
bincode = "1"

src/compiler/rust.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1873,12 +1873,11 @@ impl pkg::InputsPackager for RustInputsPackager {
18731873
if entry.header().identifier() != b"rust.metadata.bin" {
18741874
continue;
18751875
}
1876-
let mut metadata = vec![];
1877-
io::copy(&mut entry, &mut metadata)?;
18781876
let mut metadata_ar = vec![];
18791877
{
18801878
let mut ar_builder = ar::Builder::new(&mut metadata_ar);
1881-
ar_builder.append(entry.header(), metadata.as_slice())?
1879+
let header = entry.header().clone();
1880+
ar_builder.append(&header, &mut entry)?
18821881
}
18831882
file_header.set_size(metadata_ar.len() as u64);
18841883
file_header.set_cksum();

0 commit comments

Comments
 (0)