Skip to content

Link LLVM dynamically on aarch64-apple-darwin dist#154839

Closed
sgasho wants to merge 4 commits into
rust-lang:mainfrom
sgasho:issue-154408-macos-ci-llvm-versioned-dylib
Closed

Link LLVM dynamically on aarch64-apple-darwin dist#154839
sgasho wants to merge 4 commits into
rust-lang:mainfrom
sgasho:issue-154408-macos-ci-llvm-versioned-dylib

Conversation

@sgasho

@sgasho sgasho commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

retry after: #154485

create a symlink from libLLVM-.....dylib to libLLVM.dylib in dist.rs

@rustbot rustbot added A-CI Area: Our Github Actions CI A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Apr 5, 2026
@bjorn3

bjorn3 commented Apr 5, 2026

Copy link
Copy Markdown
Member

It looks like we are actually forcing the unversioned name to be used at another place:

// On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib
// instead of libLLVM-11-rust-....dylib, as on linux. It's not entirely
// clear why this is the case, though. llvm-config will emit the versioned
// paths and we don't want those in the sysroot (as we're expecting
// unversioned paths).
if target.contains("apple-darwin") && builder.llvm_link_shared() {
let src_libdir = builder.llvm_out(target).join("lib");
let llvm_dylib_path = src_libdir.join("libLLVM.dylib");
if llvm_dylib_path.exists() {
builder.install(&llvm_dylib_path, dst_libdir, FileType::NativeLibrary);
}
!builder.config.dry_run()
Would removing that instead work?

@sgasho

sgasho commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Yes, I checked that removing it produces libLLVM.dylib and libLLVM-.dylib, and ./x build did not fail. So it seems it worked.
However, ZuseZ4 and I discussed that we should prepare both versioned and unversioned libLLVM by COPYING first, not symlink.

Two biggest reasons are

  1. Multiple people said that copying libLLVM with the versioned name worked: ./x build failed with llvm-config: error: libLLVM-22-rust-1.96.0-nightly.dylib is missing #154408 (comment)
  2. Nokel81 said that symlink did not work for him: ./x build failed with llvm-config: error: libLLVM-22-rust-1.96.0-nightly.dylib is missing #154408 (comment)

for 2, ln -s command that Nokel81 posted on the comment has a typo in the extension part. But we have no idea whether the symlink itself actually failed or whether the command was just pasted incorrectly. It's possible that my method for verifying symlinks is incorrect.

So, we get to land copying PR first, then this symlink later on.

@bjorn3

bjorn3 commented Apr 8, 2026

Copy link
Copy Markdown
Member

So, we get to land copying PR first, then this symlink later on.

With my suggestion there wouldn't be any symlink either, right? It would just be removing the special case for macOS such that everything is handled the same way as it is handled on Linux.

@sgasho

sgasho commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

mmm...symlink has been created. I think I'm misunderstanding something.

Is something wrong with the image below? like, I'm looking at a wrong directory, or....

Would removing that instead work?

Am I misunderstanding this, or verification steps have some mistakes(#154986 (comment))

スクリーンショット 2026-04-09 0 23 30

@sgasho

sgasho commented Apr 12, 2026

Copy link
Copy Markdown
Contributor Author

Ah, a linker script has been created as on Linux when I ran ./x dist rustc. But it seems that macos(ld64) does not recognize linker scripts so I think it's a bit weird to place a file which does not work fine on the platform

@ZuseZ4

ZuseZ4 commented Apr 17, 2026

Copy link
Copy Markdown
Member

Upstream LLVM was also looking into the default name for macos: https://github.com/llvm/llvm-project/
pull/189004 and llvm/llvm-project#188963

**LLVM_VERSIONED_DYLIB_NAME_ON_DARWIN**:BOOL
  Defaults to ``ON``. If set to ``ON``, Darwin shared libraries built through
  LLVM's CMake helpers use versioned dylib filenames and install names, matching
  the behavior on other Unix platforms more closely. If set to ``OFF``, Darwin
  keeps the legacy unversioned dylib install name, for compatibility with
  existing consumers that expect ``@rpath/libLLVM.dylib``.

It seems like that got rid of the extra handling on the llvm side, so we could subsequently drop it as well. The next release is 3 months out. Maybe we could backport it in two steps, first having it disabled, and then (as part of this PR) enabling it? I'd at least try to avoid first spending time on one solution here, and then having to update it again in 3 months, as each change has the risk of breaking users.

@madsmtm madsmtm added O-macos Operating system: macOS O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) labels Apr 21, 2026
@rust-bors

rust-bors Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #157205) made this pull request unmergeable. Please resolve the merge conflicts.

@sgasho sgasho closed this Jun 1, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CI Area: Our Github Actions CI A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-testsuite Area: The testsuite used to check the correctness of rustc O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-macos Operating system: macOS T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants