Skip to content

Commit cde9cf0

Browse files
committed
Auto merge of rust-lang#151063 - sgasho:aarch64-dist-enzyme, r=ZuseZ4
Link LLVM dynamically on aarch64-apple-darwin Follow-up to rust-lang#152768. * Link LLVM dynamically on MacOS * Fix a macOS LLVM dylib name mismatch
2 parents 9df8317 + e7c268f commit cde9cf0

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

compiler/rustc_llvm/build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,16 @@ fn main() {
402402
continue;
403403
}
404404

405+
// On apple-darwin, llvm-config reports the versioned shared library name such as LLVM-22-..., but
406+
// the distributed toolchain ships libLLVM.dylib. Normalize the link name here.
407+
let name =
408+
if target.contains("apple-darwin") && llvm_kind == "dylib" && name.starts_with("LLVM-")
409+
{
410+
"LLVM"
411+
} else {
412+
name
413+
};
414+
405415
let kind = if name.starts_with("LLVM") {
406416
llvm_kind
407417
} else if is_static {

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ pub fn walk_native_lib_search_dirs<R>(
6262
f(&sess.target_tlib_path.dir.join("self-contained"), false)?;
6363
}
6464

65+
let has_shared_llvm_apple_darwin =
66+
sess.target.is_like_darwin && sess.target_tlib_path.dir.join("libLLVM.dylib").exists();
67+
6568
// Toolchains for some targets may ship `libunwind.a`, but place it into the main sysroot
6669
// library directory instead of the self-contained directories.
6770
// Sanitizer libraries have the same issue and are also linked by name on Apple targets.
6871
// The targets here should be in sync with `copy_third_party_objects` in bootstrap.
69-
// Finally there is shared LLVM library, which unlike compiler libraries, is linked by the name,
70-
// therefore requiring the search path for the linker.
72+
// On Apple targets, shared LLVM is linked by name, so when `libLLVM.dylib` is
73+
// present in the target libdir, add that directory to the linker search path.
7174
// FIXME: implement `-Clink-self-contained=+/-unwind,+/-sanitizers`, move the shipped libunwind
7275
// and sanitizers to self-contained directory, and stop adding this search path.
7376
// FIXME: On AIX this also has the side-effect of making the list of library search paths
@@ -77,7 +80,8 @@ pub fn walk_native_lib_search_dirs<R>(
7780
|| sess.target.os == Os::Linux
7881
|| sess.target.os == Os::Fuchsia
7982
|| sess.target.is_like_aix
80-
|| sess.target.is_like_darwin && !sess.sanitizers().is_empty()
83+
|| sess.target.is_like_darwin
84+
&& (!sess.sanitizers().is_empty() || has_shared_llvm_apple_darwin)
8185
|| sess.target.os == Os::Windows
8286
&& sess.target.env == Env::Gnu
8387
&& sess.target.cfg_abi == CfgAbi::Llvm

src/ci/github-actions/jobs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ auto:
518518
--enable-sanitizers
519519
--enable-profiler
520520
--set rust.jemalloc
521+
--set llvm.link-shared=true
521522
--set rust.lto=thin
522523
--set rust.codegen-units=1
523524
# Aarch64 tooling only needs to support macOS 11.0 and up as nothing else

0 commit comments

Comments
 (0)