Auto merge of #68623 - Zoxc:lld, r=Mark-Simulacrum
Add an option to use LLD to link the compiler on Windows platforms Based on https://github.com/rust-lang/rust/pull/68609. Using LLD is good way to improve compile times on Windows since `link.exe` is quite slow. The time for `x.py build --stage 1 src/libtest` goes from 0:12:00 to 0:08:29. Compile time for `rustc_driver` goes from 226.34s to 18.5s. `rustc_macros` goes from 28.69s to 7.7s. The size of `rustc_driver` is also reduced from 83.3 MB to 78.7 MB. r? @Mark-Simulacrum
This commit is contained in:
@@ -239,9 +239,10 @@ pub struct Build {
|
||||
hosts: Vec<Interned<String>>,
|
||||
targets: Vec<Interned<String>>,
|
||||
|
||||
// Stage 0 (downloaded) compiler and cargo or their local rust equivalents
|
||||
// Stage 0 (downloaded) compiler, lld and cargo or their local rust equivalents
|
||||
initial_rustc: PathBuf,
|
||||
initial_cargo: PathBuf,
|
||||
initial_lld: PathBuf,
|
||||
|
||||
// Runtime state filled in later on
|
||||
// C/C++ compilers and archiver for all targets
|
||||
@@ -343,9 +344,18 @@ impl Build {
|
||||
// we always try to use git for LLVM builds
|
||||
let in_tree_llvm_info = channel::GitInfo::new(false, &src.join("src/llvm-project"));
|
||||
|
||||
let initial_sysroot = config.initial_rustc.parent().unwrap().parent().unwrap();
|
||||
let initial_lld = initial_sysroot
|
||||
.join("lib")
|
||||
.join("rustlib")
|
||||
.join(config.build)
|
||||
.join("bin")
|
||||
.join("rust-lld");
|
||||
|
||||
let mut build = Build {
|
||||
initial_rustc: config.initial_rustc.clone(),
|
||||
initial_cargo: config.initial_cargo.clone(),
|
||||
initial_lld,
|
||||
local_rebuild: config.local_rebuild,
|
||||
fail_fast: config.cmd.fail_fast(),
|
||||
doc_tests: config.cmd.doc_tests(),
|
||||
@@ -810,7 +820,7 @@ impl Build {
|
||||
}
|
||||
|
||||
/// Returns the path to the linker for the given target if it needs to be overridden.
|
||||
fn linker(&self, target: Interned<String>) -> Option<&Path> {
|
||||
fn linker(&self, target: Interned<String>, can_use_lld: bool) -> Option<&Path> {
|
||||
if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.as_ref())
|
||||
{
|
||||
Some(linker)
|
||||
@@ -819,6 +829,8 @@ impl Build {
|
||||
&& !target.contains("msvc")
|
||||
{
|
||||
Some(self.cc(target))
|
||||
} else if can_use_lld && self.config.use_lld && self.build == target {
|
||||
Some(&self.initial_lld)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user