@@ -345,13 +345,6 @@ impl Step for Llvm {
345
345
cfg. define ( "LLVM_ENABLE_ZLIB" , "OFF" ) ;
346
346
}
347
347
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
-
355
348
// This setting makes the LLVM tools link to the dynamic LLVM library,
356
349
// which saves both memory during parallel links and overall disk space
357
350
// for the tools. We don't do this on every platform as it doesn't work
@@ -463,15 +456,8 @@ impl Step for Llvm {
463
456
cfg. define ( "LLVM_VERSION_SUFFIX" , suffix) ;
464
457
}
465
458
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
-
474
459
configure_cmake ( builder, target, & mut cfg, true , ldflags) ;
460
+ configure_llvm ( builder, target, & mut cfg) ;
475
461
476
462
for ( key, val) in & builder. config . llvm_build_config {
477
463
cfg. define ( key, val) ;
@@ -731,6 +717,25 @@ fn configure_cmake(
731
717
}
732
718
}
733
719
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
+
734
739
// Adapted from https://github.com/alexcrichton/cc-rs/blob/fba7feded71ee4f63cfe885673ead6d7b4f2f454/src/lib.rs#L2347-L2365
735
740
fn get_var ( var_base : & str , host : & str , target : & str ) -> Option < OsString > {
736
741
let kind = if host == target { "HOST" } else { "TARGET" } ;
@@ -794,6 +799,7 @@ impl Step for Lld {
794
799
}
795
800
796
801
configure_cmake ( builder, target, & mut cfg, true , ldflags) ;
802
+ configure_llvm ( builder, target, & mut cfg) ;
797
803
798
804
// This is an awful, awful hack. Discovered when we migrated to using
799
805
// clang-cl to compile LLVM/LLD it turns out that LLD, when built out of
@@ -825,10 +831,6 @@ impl Step for Lld {
825
831
. define ( "LLVM_CONFIG_PATH" , llvm_config_shim)
826
832
. define ( "LLVM_INCLUDE_TESTS" , "OFF" ) ;
827
833
828
- if builder. config . llvm_allow_old_toolchain {
829
- cfg. define ( "LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN" , "YES" ) ;
830
- }
831
-
832
834
// While we're using this horrible workaround to shim the execution of
833
835
// llvm-config, let's just pile on more. I can't seem to figure out how
834
836
// to build LLD as a standalone project and also cross-compile it at the
0 commit comments