From cf6a8feb2674b87778b24e3507d8feb49360afaf Mon Sep 17 00:00:00 2001 From: sgasho Date: Thu, 12 Feb 2026 23:23:31 +0900 Subject: [PATCH 1/6] use unversioned LLVM dylib name on macOS --- compiler/rustc_llvm/build.rs | 8 ++++++++ src/ci/github-actions/jobs.yml | 1 + 2 files changed, 9 insertions(+) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 38c16fb1cd6d5..cf50e866b22cc 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -402,6 +402,14 @@ fn main() { continue; } + let name = + if target.contains("apple-darwin") && llvm_kind == "dylib" && name.starts_with("LLVM-") + { + "LLVM" + } else { + name + }; + let kind = if name.starts_with("LLVM") { llvm_kind } else if is_static { diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 0687d142a3504..51d1b9caf343b 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -512,6 +512,7 @@ auto: --enable-full-tools --enable-sanitizers --enable-profiler + --set llvm.enzyme=true --set rust.jemalloc --set rust.lto=thin --set rust.codegen-units=1 From 566705420941c8344970cba42437aead9a0044d5 Mon Sep 17 00:00:00 2001 From: sgasho Date: Tue, 10 Mar 2026 00:16:08 +0900 Subject: [PATCH 2/6] dist enzyme on macos --- src/ci/github-actions/jobs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 51d1b9caf343b..9d37e0b23d5ce 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -504,7 +504,7 @@ auto: - name: dist-aarch64-apple env: SCRIPT: >- - ./x.py dist bootstrap + ./x.py dist bootstrap enzyme --include-default-paths --host=aarch64-apple-darwin --target=aarch64-apple-darwin @@ -512,8 +512,8 @@ auto: --enable-full-tools --enable-sanitizers --enable-profiler - --set llvm.enzyme=true --set rust.jemalloc + --set llvm.link-shared=true --set rust.lto=thin --set rust.codegen-units=1 # Aarch64 tooling only needs to support macOS 11.0 and up as nothing else From b483e2f6d7c08dc8615d9ce39e411031ae349e2a Mon Sep 17 00:00:00 2001 From: sgasho Date: Wed, 11 Mar 2026 00:17:20 +0900 Subject: [PATCH 3/6] tell LLVM location for Enzyme build --- src/bootstrap/src/core/build_steps/llvm.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 0c607cb6ba6f3..864b5edb4cf3e 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -1213,6 +1213,11 @@ impl Step for Enzyme { ldflags.push_all("-fuse-ld=lld"); } + if target.contains("apple-darwin") && builder.llvm_link_shared() { + let llvm_libdir = builder.llvm_out(target).join("lib"); + ldflags.push_all(format!("-L{}", llvm_libdir.display())); + } + configure_cmake(builder, target, &mut cfg, true, ldflags, cflags, &[]); // Re-use the same flags as llvm to control the level of debug information From 6eb69e129f84354d3a35b07f8a8d09f1d1b7088d Mon Sep 17 00:00:00 2001 From: sgasho Date: Thu, 12 Mar 2026 00:08:07 +0900 Subject: [PATCH 4/6] fix indent --- src/ci/github-actions/jobs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 9d37e0b23d5ce..c06c85513856b 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -513,7 +513,7 @@ auto: --enable-sanitizers --enable-profiler --set rust.jemalloc - --set llvm.link-shared=true + --set llvm.link-shared=true --set rust.lto=thin --set rust.codegen-units=1 # Aarch64 tooling only needs to support macOS 11.0 and up as nothing else From d91e4038389792de355793f8b99384a33af7ef3a Mon Sep 17 00:00:00 2001 From: sgasho Date: Thu, 12 Mar 2026 23:57:55 +0900 Subject: [PATCH 5/6] Let's see if it still works when we revert "tell LLVM location for Enzyme build" This reverts commit b483e2f6d7c08dc8615d9ce39e411031ae349e2a. --- src/bootstrap/src/core/build_steps/llvm.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 864b5edb4cf3e..0c607cb6ba6f3 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -1213,11 +1213,6 @@ impl Step for Enzyme { ldflags.push_all("-fuse-ld=lld"); } - if target.contains("apple-darwin") && builder.llvm_link_shared() { - let llvm_libdir = builder.llvm_out(target).join("lib"); - ldflags.push_all(format!("-L{}", llvm_libdir.display())); - } - configure_cmake(builder, target, &mut cfg, true, ldflags, cflags, &[]); // Re-use the same flags as llvm to control the level of debug information From 5ffae10fda60abd076a0f78f74781e42b36b5911 Mon Sep 17 00:00:00 2001 From: sgasho Date: Sun, 15 Mar 2026 14:19:07 +0900 Subject: [PATCH 6/6] rustc_metadata: add shared LLVM search path for macOS rustc_private builds --- compiler/rustc_metadata/src/native_libs.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 52b11615c76f0..98c32590f690b 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -57,6 +57,9 @@ pub fn walk_native_lib_search_dirs( f(&sess.target_tlib_path.dir.join("self-contained"), false)?; } + let has_shared_llvm_apple_darwin = + sess.target.is_like_darwin && sess.target_tlib_path.dir.join("libLLVM.dylib").exists(); + // Toolchains for some targets may ship `libunwind.a`, but place it into the main sysroot // library directory instead of the self-contained directories. // Sanitizer libraries have the same issue and are also linked by name on Apple targets. @@ -72,7 +75,8 @@ pub fn walk_native_lib_search_dirs( || sess.target.os == Os::Linux || sess.target.os == Os::Fuchsia || sess.target.is_like_aix - || sess.target.is_like_darwin && !sess.sanitizers().is_empty() + || sess.target.is_like_darwin + && (!sess.sanitizers().is_empty() || has_shared_llvm_apple_darwin) || sess.target.os == Os::Windows && sess.target.env == Env::Gnu && sess.target.abi == Abi::Llvm