@@ -23,7 +23,7 @@ use crate::core::config::{Config, TargetSelection};
2323use crate :: utils:: build_stamp:: { BuildStamp , generate_smart_stamp_hash} ;
2424use crate :: utils:: exec:: command;
2525use crate :: utils:: helpers:: {
26- self , exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
26+ self , exe, get_clang_cl_resource_dir, libdir , t, unhashed_basename, up_to_date,
2727} ;
2828use crate :: { CLang , GitRepo , Kind , trace} ;
2929
@@ -561,7 +561,6 @@ impl Step for Llvm {
561561 }
562562 } ;
563563
564- // FIXME(ZuseZ4): Do we need that for Enzyme too?
565564 // When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
566565 // libLLVM.dylib will be built. However, llvm-config will still look
567566 // for a versioned path like libLLVM-14.dylib. Manually create a symbolic
@@ -1159,7 +1158,7 @@ impl Step for Enzyme {
11591158 let llvm_version_major = llvm:: get_llvm_version_major ( builder, & host_llvm_config) ;
11601159 let lib_ext = std:: env:: consts:: DLL_EXTENSION ;
11611160 let libenzyme = format ! ( "libEnzyme-{llvm_version_major}" ) ;
1162- let build_dir = out_dir. join ( "lib" ) ;
1161+ let build_dir = out_dir. join ( libdir ( target ) ) ;
11631162 let dylib = build_dir. join ( & libenzyme) . with_extension ( lib_ext) ;
11641163
11651164 trace ! ( "checking build stamp to see if we need to rebuild enzyme artifacts" ) ;
@@ -1197,7 +1196,15 @@ impl Step for Enzyme {
11971196 // hard to spot more relevant issues.
11981197 let mut cflags = CcFlags :: default ( ) ;
11991198 cflags. push_all ( "-Wno-deprecated" ) ;
1200- configure_cmake ( builder, target, & mut cfg, true , LdFlags :: default ( ) , cflags, & [ ] ) ;
1199+
1200+ // ThinLTO is only available when building with LLVM, enabling LLD is required.
1201+ // Apple's linker ld64 supports ThinLTO out of the box though, so don't use LLD on Darwin.
1202+ let mut ldflags = LdFlags :: default ( ) ;
1203+ if builder. config . llvm_thin_lto && !target. contains ( "apple" ) {
1204+ ldflags. push_all ( "-fuse-ld=lld" ) ;
1205+ }
1206+
1207+ configure_cmake ( builder, target, & mut cfg, true , ldflags, cflags, & [ ] ) ;
12011208
12021209 // Re-use the same flags as llvm to control the level of debug information
12031210 // generated by Enzyme.
0 commit comments