Skip to content

Commit 87fd70c

Browse files
committed
Auto merge of #96803 - jyn514:faster-assemble, r=Mark-Simulacrum
Make "Assemble stage1 compiler" orders of magnitude faster This used to take upwards of 5 seconds for me locally. I found that the culprit was copying the downloaded LLVM shared object: ``` [22:28:03] Install "/home/jnelson/rust-lang/rust/build/x86_64-unknown-linux-gnu/ci-llvm/lib/libLLVM-14-rust-1.62.0-nightly.so" to "/home/jnelson/rust-lang/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libLLVM-14-rust-1.62.0-nightly.so" [22:28:09] c Sysroot { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu(x86_64-unknown-linux-gnu) } } ``` It turned out that `install()` used full copies unconditionally. Change it to try using a hard-link before falling back to copying.
2 parents 362010d + 5f4b174 commit 87fd70c

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/bootstrap/lib.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1497,20 +1497,14 @@ impl Build {
14971497
let dst = dstdir.join(src.file_name().unwrap());
14981498
self.verbose_than(1, &format!("Install {:?} to {:?}", src, dst));
14991499
t!(fs::create_dir_all(dstdir));
1500-
drop(fs::remove_file(&dst));
15011500
{
15021501
if !src.exists() {
15031502
panic!("Error: File \"{}\" not found!", src.display());
15041503
}
1505-
let metadata = t!(src.symlink_metadata());
1506-
if let Err(e) = fs::copy(&src, &dst) {
1507-
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
1508-
}
1509-
t!(fs::set_permissions(&dst, metadata.permissions()));
1510-
let atime = FileTime::from_last_access_time(&metadata);
1511-
let mtime = FileTime::from_last_modification_time(&metadata);
1512-
t!(filetime::set_file_times(&dst, atime, mtime));
1504+
self.copy(src, &dst);
15131505
}
1506+
// NOTE: when using hard-links, this will also update the permissions on the original file.
1507+
// We never use permissions that are more restrictive than the original, so this shouldn't cause any issues.
15141508
chmod(&dst, perms);
15151509
}
15161510

0 commit comments

Comments
 (0)