From bfba6ef328bbba327cae8918e795c11b89217672 Mon Sep 17 00:00:00 2001 From: John Kåre Alsaker Date: Tue, 28 Jan 2020 19:21:22 +0100 Subject: Add an option to use LLD to link the compiler on Windows platforms --- src/bootstrap/builder.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/bootstrap/builder.rs') diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index d9c894aa9c6..008af975c33 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -694,7 +694,7 @@ impl<'a> Builder<'a> { cmd.env_remove("MAKEFLAGS"); cmd.env_remove("MFLAGS"); - if let Some(linker) = self.linker(compiler.host) { + if let Some(linker) = self.linker(compiler.host, true) { cmd.env("RUSTC_TARGET_LINKER", linker); } cmd @@ -949,10 +949,30 @@ impl<'a> Builder<'a> { } } - if let Some(host_linker) = self.linker(compiler.host) { + // FIXME: Don't use LLD if we're compiling libstd, since it fails to link it. + let can_use_lld = mode != Mode::Std; + + // FIXME: The beta compiler doesn't pick the `lld-link` flavor for `*-pc-windows-msvc` + // Remove `RUSTC_HOST_LINKER_FLAVOR` when this is fixed + let lld_linker_flavor = |linker: &Path, target: Interned| { + compiler.stage == 0 + && linker.file_name() == Some(OsStr::new("rust-lld")) + && target.contains("pc-windows-msvc") + }; + + if let Some(host_linker) = self.linker(compiler.host, can_use_lld) { + if lld_linker_flavor(host_linker, compiler.host) { + cargo.env("RUSTC_HOST_LINKER_FLAVOR", "lld-link"); + } + cargo.env("RUSTC_HOST_LINKER", host_linker); } - if let Some(target_linker) = self.linker(target) { + + if let Some(target_linker) = self.linker(target, can_use_lld) { + if lld_linker_flavor(target_linker, target) { + rustflags.arg("-Clinker-flavor=lld-link"); + } + let target = crate::envify(&target); cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker); } -- cgit 1.4.1-3-g733a5