Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions run-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,33 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

##

# We standardize a common LLVM/Clang version for this script.
# Note that this is totally independent of the version of LLVM that you
# are using to build Halide itself. If you don't have the right version
# installed, you can usually install what you need easily via:
#
# sudo apt-get install llvm-X clang-X libclang-X-dev clang-tidy-X
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-X
#
# On macOS:
#
# brew install llvm@X
# export CLANG_TIDY_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@X
#
# Where X matches the EXPECTED_VERSION below.

EXPECTED_VERSION=21

##

usage() { echo -e "Usage: $0 [-c]" 1>&2; exit 1; }

if [ "$(uname)" == "Darwin" ]; then
_DEFAULT_LLVM_LOCATION="/opt/homebrew/opt/llvm@$EXPECTED_VERSION"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you add support for MacPorts. I recently discovered macports. They are actually enabling people with older macbooks to continue working. I have a 2015 MacBook Pro, and recent LLVM versions through Homebrew are like a day worth of compiling from source. MacPorts maintains builds for older OSes, and installation is much leaner and cleaner.

else
_DEFAULT_LLVM_LOCATION="/usr/lib/llvm-$EXPECTED_VERSION"
fi

# Fix the formatting in-place
MODE_FLAGS=(-i --sort-includes)

Expand Down Expand Up @@ -43,22 +64,13 @@ if [[ "${MODE_FLAGS[*]}" =~ "-i" ]]; then
fi
fi

# We are currently standardized on using LLVM/Clang19 for this script.
# Note that this is totally independent of the version of LLVM that you
# are using to build Halide itself. If you don't have LLVM19 installed,
# you can usually install what you need easily via:
#
# sudo apt-get install llvm-19 clang-19 libclang-19-dev clang-tidy-19
# export CLANG_FORMAT_LLVM_INSTALL_DIR=/usr/lib/llvm-19
#
# On macOS:
#
# brew install llvm@19
# export CLANG_FORMAT_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@19

if [ -z "$CLANG_FORMAT_LLVM_INSTALL_DIR" ]; then
echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
exit 1
if [ -d "${_DEFAULT_LLVM_LOCATION}" ]; then
CLANG_FORMAT_LLVM_INSTALL_DIR="${_DEFAULT_LLVM_LOCATION}"
else
echo "CLANG_FORMAT_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
exit 1
fi
fi

echo "CLANG_FORMAT_LLVM_INSTALL_DIR=${CLANG_FORMAT_LLVM_INSTALL_DIR}"
Expand Down
54 changes: 34 additions & 20 deletions run-clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ set -e

ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

##

# We standardize a common LLVM/Clang version for this script.
# Note that this is totally independent of the version of LLVM that you
# are using to build Halide itself. If you don't have the right version
# installed, you can usually install what you need easily via:
#
# sudo apt-get install llvm-X clang-X libclang-X-dev clang-tidy-X
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-X
#
# On macOS:
#
# brew install llvm@X
# export CLANG_TIDY_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@X
#
# Where X matches the EXPECTED_VERSION below.

EXPECTED_VERSION=21

##

usage() { echo "Usage: $0 [-j MAX_PROCESS_COUNT] [-f]" 1>&2; exit 1; }

get_thread_count () {
Expand All @@ -13,8 +34,10 @@ get_thread_count () {

if [ "$(uname)" == "Darwin" ]; then
patch_file () { sed -i '' -E "$@"; }
_DEFAULT_LLVM_LOCATION="/opt/homebrew/opt/llvm@$EXPECTED_VERSION"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MacPorts? 🥺

else
patch_file () { sed -i -E "$@"; }
_DEFAULT_LLVM_LOCATION="/usr/lib/llvm-$EXPECTED_VERSION"
fi

J=$(get_thread_count)
Expand All @@ -41,32 +64,22 @@ if [ -n "${FIX}" ]; then
echo "Operating in -fix mode!"
fi

# We are currently standardized on using LLVM/Clang 21 for this script.
# Note that this is totally independent of the version of LLVM that you
# are using to build Halide itself. If you don't have LLVM21 installed,
# you can usually install what you need easily via:
#
# sudo apt-get install llvm-21 clang-21 libclang-21-dev clang-tidy-21
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-21
#
# On macOS:
#
# brew install llvm@21
# export CLANG_TIDY_LLVM_INSTALL_DIR=/opt/homebrew/opt/llvm@21

if [ -z "$CLANG_TIDY_LLVM_INSTALL_DIR" ]; then
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
exit
if [ -d "${_DEFAULT_LLVM_LOCATION}" ]; then
CLANG_TIDY_LLVM_INSTALL_DIR="${_DEFAULT_LLVM_LOCATION}"
else
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script."
exit
fi
fi

echo "CLANG_TIDY_LLVM_INSTALL_DIR = ${CLANG_TIDY_LLVM_INSTALL_DIR}"

VERSION=$("${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/clang-tidy" --version)
if [[ ${VERSION} =~ .*version\ 21.* ]]
then
echo "clang-tidy version 21 found."
if [[ ${VERSION} =~ .*version\ $EXPECTED_VERSION.* ]]; then
echo "clang-tidy version $EXPECTED_VERSION found."
else
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM 21 install!"
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM $EXPECTED_VERSION install!"
exit 1
fi

Expand Down Expand Up @@ -94,10 +107,11 @@ if [[ $(${CC} --version) =~ .*Homebrew.* ]]; then
SDKROOT="$(xcrun --show-sdk-path)"
# TOOLCHAINROOT="$(xcrun --show-toolchain-path)"
TOOLCHAINROOT="$(cd "$(dirname "$(xcrun --find clang)")"/../.. && pwd)"
RCDIR="$(xcrun clang -print-resource-dir)"
cat > "${CLANG_TIDY_BUILD_DIR}/toolchain.cmake" << EOF
set(CMAKE_SYSROOT "${SDKROOT}")
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES
"${TOOLCHAINROOT}/usr/lib/clang/17/include"
"${RCDIR}/include"
"${SDKROOT}/usr/include"
"${TOOLCHAINROOT}/usr/include"
"${SDKROOT}/System/Library/Frameworks"
Expand Down
Loading