Skip to content

Commit 5f4b174

Browse files
committed
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.
1 parent 30f3860 commit 5f4b174

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
@@ -1492,20 +1492,14 @@ impl Build {
14921492
let dst = dstdir.join(src.file_name().unwrap());
14931493
self.verbose_than(1, &format!("Install {:?} to {:?}", src, dst));
14941494
t!(fs::create_dir_all(dstdir));
1495-
drop(fs::remove_file(&dst));
14961495
{
14971496
if !src.exists() {
14981497
panic!("Error: File \"{}\" not found!", src.display());
14991498
}
1500-
let metadata = t!(src.symlink_metadata());
1501-
if let Err(e) = fs::copy(&src, &dst) {
1502-
panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
1503-
}
1504-
t!(fs::set_permissions(&dst, metadata.permissions()));
1505-
let atime = FileTime::from_last_access_time(&metadata);
1506-
let mtime = FileTime::from_last_modification_time(&metadata);
1507-
t!(filetime::set_file_times(&dst, atime, mtime));
1499+
self.copy(src, &dst);
15081500
}
1501+
// NOTE: when using hard-links, this will also update the permissions on the original file.
1502+
// We never use permissions that are more restrictive than the original, so this shouldn't cause any issues.
15091503
chmod(&dst, perms);
15101504
}
15111505

0 commit comments

Comments
 (0)