Skip to content

Commit 052e18e

Browse files
authored
Fix finding LLD on Homebrew when multiple versions are installed. (#8619)
LLVM sadly doesn't provide *ConfigVersion.cmake files for its sub-components, including Clang and LLD. Consequently, attempting to constrain the version to LLVM_PACKAGE_VERSION prevents these find_package calls from succeeding at all. Worse, package maintainers have some "interesting" ideas as to how they should lay out the -dev packages, especially when they want to support multiple parallel versions. These hints take effect at a lower precedence than Halide_LLVM_ROOT or CMAKE_PREFIX_PATH (which are the standard ways of setting up the dependency search), but at a higher precedence than the system-wide fallback locations. In particular, Homebrew split the LLVM and LLD packages as of version 19, so having multiple LLVM versions installed leads to the newest LLD being found without the hint in this commit.
1 parent d0c8406 commit 052e18e

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

.github/workflows/presubmit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
steps:
3434
- uses: actions/checkout@v3
3535
- name: Install clang-tidy
36-
run: brew install llvm@19 ninja lld
36+
run: brew install llvm@19 ninja lld@19
3737
- name: Run clang-tidy
3838
run: ./run-clang-tidy.sh
3939
env:

cmake/FindHalide_LLVM.cmake

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,38 @@ endif ()
2828
option(Halide_LLVM_SHARED_LIBS "Enable to link to shared libLLVM" "${Halide_LLVM_SHARED_LIBS}")
2929

3030
if (LLVM_FOUND)
31-
find_package(Clang HINTS "${LLVM_INSTALL_PREFIX}" "${LLVM_DIR}/../clang" "${LLVM_DIR}/../lib/cmake/clang")
31+
# LLVM sadly doesn't provide *ConfigVersion.cmake files for its
32+
# sub-components, including Clang and LLD. Consequently, attempting to
33+
# constrain the version to LLVM_PACKAGE_VERSION prevents these find_package
34+
# calls from succeeding at all. Worse, package maintainers have some
35+
# "interesting" ideas as to how they should lay out the -dev packages,
36+
# especially when they want to support multiple parallel versions. These
37+
# hints take effect at a lower precedence than Halide_LLVM_ROOT
38+
# or CMAKE_PREFIX_PATH (which are the standard ways of setting up the
39+
# dependency search), but at a higher precedence than the system-wide
40+
# fallback locations.
41+
find_package(
42+
Clang
43+
HINTS
44+
"${LLVM_INSTALL_PREFIX}" # Same root as the LLVM we found
45+
"${LLVM_DIR}/../clang" # LLVM found in $ROOT/lib/cmake/llvm
46+
"${LLVM_DIR}/../lib/cmake/clang" # LLVM found in $ROOT/cmake
47+
)
3248

3349
foreach (comp IN LISTS LLVM_TARGETS_TO_BUILD)
3450
if (comp STREQUAL "WebAssembly")
3551
set(Halide_LLVM_${comp}_FOUND 0)
3652

37-
find_package(LLD HINTS "${LLVM_INSTALL_PREFIX}" "${LLVM_DIR}/../lld" "${LLVM_DIR}/../lib/cmake/lld")
53+
find_package(
54+
LLD HINTS
55+
"${LLVM_INSTALL_PREFIX}"
56+
# Homebrew split the LLVM and LLD packages as of version 19, so
57+
# having multiple LLVM versions installed leads to the newest
58+
# LLD being found without this hint.
59+
"${LLVM_INSTALL_PREFIX}/../lld@${LLVM_VERSION_MAJOR}"
60+
"${LLVM_DIR}/../lld"
61+
"${LLVM_DIR}/../lib/cmake/lld"
62+
)
3863
if (NOT LLD_FOUND)
3964
string(APPEND REASON_FAILURE_MESSAGE
4065
"WebAssembly was not found because liblld is missing. "

0 commit comments

Comments
 (0)