Skip to content

Commit 6f87b75

Browse files
committed
Set llvm configs when building lld
1 parent 4493a0f commit 6f87b75

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/bootstrap/native.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,6 @@ impl Step for Llvm {
345345
cfg.define("LLVM_ENABLE_ZLIB", "OFF");
346346
}
347347

348-
if builder.config.llvm_thin_lto {
349-
cfg.define("LLVM_ENABLE_LTO", "Thin");
350-
if !target.contains("apple") {
351-
cfg.define("LLVM_ENABLE_LLD", "ON");
352-
}
353-
}
354-
355348
// This setting makes the LLVM tools link to the dynamic LLVM library,
356349
// which saves both memory during parallel links and overall disk space
357350
// for the tools. We don't do this on every platform as it doesn't work
@@ -463,15 +456,8 @@ impl Step for Llvm {
463456
cfg.define("LLVM_VERSION_SUFFIX", suffix);
464457
}
465458

466-
if let Some(ref linker) = builder.config.llvm_use_linker {
467-
cfg.define("LLVM_USE_LINKER", linker);
468-
}
469-
470-
if builder.config.llvm_allow_old_toolchain {
471-
cfg.define("LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN", "YES");
472-
}
473-
474459
configure_cmake(builder, target, &mut cfg, true, ldflags);
460+
configure_llvm(builder, target, &mut cfg);
475461

476462
for (key, val) in &builder.config.llvm_build_config {
477463
cfg.define(key, val);
@@ -731,6 +717,25 @@ fn configure_cmake(
731717
}
732718
}
733719

720+
fn configure_llvm(builder: &Builder<'_>, target: TargetSelection, cfg: &mut cmake::Config) {
721+
// ThinLTO is only available when building with LLVM, enabling LLD is required.
722+
// Apple's linker ld64 supports ThinLTO out of the box though, so don't use LLD on Darwin.
723+
if builder.config.llvm_thin_lto {
724+
cfg.define("LLVM_ENABLE_LTO", "Thin");
725+
if !target.contains("apple") {
726+
cfg.define("LLVM_ENABLE_LLD", "ON");
727+
}
728+
}
729+
730+
if let Some(ref linker) = builder.config.llvm_use_linker {
731+
cfg.define("LLVM_USE_LINKER", linker);
732+
}
733+
734+
if builder.config.llvm_allow_old_toolchain {
735+
cfg.define("LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN", "YES");
736+
}
737+
}
738+
734739
// Adapted from https://github.com/alexcrichton/cc-rs/blob/fba7feded71ee4f63cfe885673ead6d7b4f2f454/src/lib.rs#L2347-L2365
735740
fn get_var(var_base: &str, host: &str, target: &str) -> Option<OsString> {
736741
let kind = if host == target { "HOST" } else { "TARGET" };
@@ -794,6 +799,7 @@ impl Step for Lld {
794799
}
795800

796801
configure_cmake(builder, target, &mut cfg, true, ldflags);
802+
configure_llvm(builder, target, &mut cfg);
797803

798804
// This is an awful, awful hack. Discovered when we migrated to using
799805
// clang-cl to compile LLVM/LLD it turns out that LLD, when built out of
@@ -825,10 +831,6 @@ impl Step for Lld {
825831
.define("LLVM_CONFIG_PATH", llvm_config_shim)
826832
.define("LLVM_INCLUDE_TESTS", "OFF");
827833

828-
if builder.config.llvm_allow_old_toolchain {
829-
cfg.define("LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN", "YES");
830-
}
831-
832834
// While we're using this horrible workaround to shim the execution of
833835
// llvm-config, let's just pile on more. I can't seem to figure out how
834836
// to build LLD as a standalone project and also cross-compile it at the

0 commit comments

Comments
 (0)