Skip to content

Commit 3eb3620

Browse files
other strategy to update clang/ more changes for version
1 parent 594c418 commit 3eb3620

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

.github/workflows/buildandtest.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,21 @@ jobs:
5252
cache-dependency-path: yarn.lock
5353
- name: Install Dependencies
5454
run: yarn install
55-
- name: Setup clang-format
56-
run: sudo apt install clang-21 lldb-21 lld-21
55+
56+
# Default of ubuntu and apt packages are too old compared to macos packages.
57+
# This is required for using a newer version of clang-format.
58+
- name: Install LLVM 20
59+
run: |
60+
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" 20
61+
sudo apt-get install -y clang-20 clang-format-20 lld-20 lldb-20
62+
63+
- name: Set Clang 20 as default
64+
run: |
65+
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-20 200
66+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-20 200
67+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-20 200
68+
clang --version
69+
clang-format --version
5770
5871
- name: Lint
5972
run: yarn lint

scripts/clang-format.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,41 @@ set -eo pipefail
44

55
echo "💡 If you get 'spawn Unknown system error -86', try running this script manually:"
66
echo " ./scripts/clang-format.sh $1"
7-
echo ""
7+
echo "💡 It is also recommended to use clang-version v20 or v21."
88

99
# Prioritize finding clang-format executable from brew since the run-s may introduce X86/ARM64 mismatch.
1010
CLANG_FORMAT_PATH=""
1111
if [ -f "/opt/homebrew/bin/clang-format" ]; then
1212
CLANG_FORMAT_PATH="/opt/homebrew/bin/clang-format"
13-
elif [ -f "/usr/local/bin/clang-format" ]; then
14-
CLANG_FORMAT_PATH="/usr/local/bin/clang-format"
1513
else
16-
CLANG_FORMAT_PATH=$(which clang-format 2>/dev/null)
14+
CLANG_FORMAT_PATH=$(which clang-format 2>/dev/null || true)
1715
fi
1816

1917
if [ -z "$CLANG_FORMAT_PATH" ]; then
2018
echo "❌ clang-format is not installed or not found in PATH"
2119
echo ""
2220
echo "To install clang-format:"
23-
echo " • macOS: brew install clang-format"
24-
echo " • Linux: install package clang-format or clang-tools-extra"
25-
echo ""
21+
echo " * macOS: brew install clang-format"
22+
echo " * Ubuntu: install package clang-format or clang-tools-extra"
23+
echo " * Arch: pacman -S clang llvm llvm-libs"
24+
exit 1
25+
fi
26+
27+
CLANG_VERSION="$("$CLANG_FORMAT_PATH" --version 2>/dev/null)"
28+
CLANG_MAJOR_VERSION="$(printf '%s' "$CLANG_VERSION" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1 | cut -d. -f1)"
29+
30+
echo "clang-format version: $CLANG_VERSION, MAJOR: $CLANG_MAJOR_VERSION"
31+
32+
if ! printf '%s' "$CLANG_MAJOR_VERSION" | grep -qE '^[0-9]+$'; then
33+
echo "❌ Could not parse clang-format version from: $CLANG_VERSION"
2634
exit 1
2735
fi
2836

29-
echo "clang-format version: $($CLANG_FORMAT_PATH --version)"
37+
REQUIRED_MAJOR=20
38+
if [ "$CLANG_MAJOR_VERSION" -lt "$REQUIRED_MAJOR" ]; then
39+
echo "❌ clang-format major version $CLANG_MAJOR_VERSION is lower than required $REQUIRED_MAJOR"
40+
exit 1
41+
fi
3042

3143
# Check if an argument is provided
3244
if [ $# -eq 0 ]; then

0 commit comments

Comments
 (0)