44
55ROOT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
66
7+ # #
8+
9+ # We standardize a common LLVM/Clang version for this script.
10+ # Note that this is totally independent of the version of LLVM that you
11+ # are using to build Halide itself. If you don't have the right version
12+ # installed, you can usually install what you need easily via:
13+ #
14+ # sudo apt-get install llvm-X clang-X libclang-X-dev clang-tidy-X
15+ # export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-X
16+ #
17+ # On macOS:
18+ #
19+ # brew install llvm@X
20+ # export CLANG_TIDY_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@X
21+ #
22+ # Where X matches the EXPECTED_VERSION below.
23+
24+ EXPECTED_VERSION=21
25+
26+ # #
27+
728usage () { echo " Usage: $0 [-j MAX_PROCESS_COUNT] [-f]" 1>&2 ; exit 1; }
829
930get_thread_count () {
@@ -13,8 +34,10 @@ get_thread_count () {
1334
1435if [ " $( uname) " == " Darwin" ]; then
1536 patch_file () { sed -i ' ' -E " $@ " ; }
37+ _DEFAULT_LLVM_LOCATION=" /opt/homebrew/opt/llvm@$EXPECTED_VERSION "
1638else
1739 patch_file () { sed -i -E " $@ " ; }
40+ _DEFAULT_LLVM_LOCATION=" /usr/lib/llvm-$EXPECTED_VERSION "
1841fi
1942
2043J=$( get_thread_count)
@@ -41,32 +64,22 @@ if [ -n "${FIX}" ]; then
4164 echo " Operating in -fix mode!"
4265fi
4366
44- # We are currently standardized on using LLVM/Clang 21 for this script.
45- # Note that this is totally independent of the version of LLVM that you
46- # are using to build Halide itself. If you don't have LLVM21 installed,
47- # you can usually install what you need easily via:
48- #
49- # sudo apt-get install llvm-21 clang-21 libclang-21-dev clang-tidy-21
50- # export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-21
51- #
52- # On macOS:
53- #
54- # brew install llvm@21
55- # export CLANG_TIDY_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@21
56-
5767if [ -z " $CLANG_TIDY_LLVM_INSTALL_DIR " ]; then
58- echo " CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
59- exit
68+ if [ -d " ${_DEFAULT_LLVM_LOCATION} " ]; then
69+ CLANG_TIDY_LLVM_INSTALL_DIR=" ${_DEFAULT_LLVM_LOCATION} "
70+ else
71+ echo " CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
72+ exit
73+ fi
6074fi
6175
6276echo " CLANG_TIDY_LLVM_INSTALL_DIR = ${CLANG_TIDY_LLVM_INSTALL_DIR} "
6377
6478VERSION=$( " ${CLANG_TIDY_LLVM_INSTALL_DIR} /bin/clang-tidy" --version)
65- if [[ ${VERSION} =~ .* version\ 21.* ]]
66- then
67- echo " clang-tidy version 21 found."
79+ if [[ ${VERSION} =~ .* version\ $EXPECTED_VERSION .* ]]; then
80+ echo " clang-tidy version $EXPECTED_VERSION found."
6881else
69- echo " CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM 21 install!"
82+ echo " CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM $EXPECTED_VERSION install!"
7083 exit 1
7184fi
7285
@@ -94,10 +107,11 @@ if [[ $(${CC} --version) =~ .*Homebrew.* ]]; then
94107 SDKROOT=" $( xcrun --show-sdk-path) "
95108 # TOOLCHAINROOT="$(xcrun --show-toolchain-path)"
96109 TOOLCHAINROOT=" $( cd " $( dirname " $( xcrun --find clang) " ) " /../.. && pwd) "
110+ RCDIR=" $( xcrun clang -print-resource-dir) "
97111 cat > " ${CLANG_TIDY_BUILD_DIR} /toolchain.cmake" << EOF
98112set(CMAKE_SYSROOT "${SDKROOT} ")
99113set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES
100- "${TOOLCHAINROOT} /usr/lib/clang/17 /include"
114+ "${RCDIR} /include"
101115 "${SDKROOT} /usr/include"
102116 "${TOOLCHAINROOT} /usr/include"
103117 "${SDKROOT} /System/Library/Frameworks"
0 commit comments