Files
mayhem-firmware/tools/fetch-clang-format.sh
T
gullradriel 95eafeb812 fix clang format workflow, update hackrf submodule, fix subghzd compilation warning, remove flashsize.h (#2992)
* trying to fix clang format workflow
* try without docker repo, classic apt install
* find what installed clang format 18 version is
* removed auto generated flashsize
* comment on flashsize.h
* modified to use repo owned clang-format binaries
* code format for windows hosts
* add clang-format binaries for linux x86_64/arm64, macos-arm64, windows x86_64
* add helper script to download specific llvm clang-format version
* add helper to download missing libraries (use docker)
* use custom clang-format
* fix ui_subghzd.cpp:85:29: warning: narrowing conversion of 'this->ui::SubGhzDRecentEntryDetailView::cnt' from 'uint32_t' {aka 'long unsigned int'} to 'uint16_t' {aka 'short unsigned int'} [-Wnarrowing]
* remove auto generated file
* Update tools/clang-format.sh
* removed fallback
* updated hackrf submodule
2026-02-15 21:29:26 +00:00

74 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
VER="18.1.8"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DEST="$ROOT/tools/clang-format-bin/$VER"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
base="https://github.com/llvm/llvm-project/releases/download/llvmorg-${VER}"
# Archives you said you want to support
LINUX_X86="clang+llvm-${VER}-x86_64-linux-gnu-ubuntu-18.04.tar.xz"
LINUX_A64="clang+llvm-${VER}-aarch64-linux-gnu.tar.xz"
MAC_A64="clang+llvm-${VER}-arm64-apple-macos11.tar.xz"
WIN_X86="clang+llvm-${VER}-x86_64-pc-windows-msvc.tar.xz"
mkdir -p \
"$DEST/linux-x86_64" \
"$DEST/linux-arm64" \
"$DEST/macos-arm64" \
"$DEST/windows-x86_64"
fetch_and_extract() {
local archive="$1"
local outpath="$2"
local inner="$3"
echo "Downloading $archive"
curl -fsSL "$base/$archive" -o "$TMP/$archive"
echo "Extracting $inner"
tar -xf "$TMP/$archive" -C "$TMP"
# The tarball extracts into a single top-level directory; find it
local topdir
topdir="$(find "$TMP" -maxdepth 1 -type d -name "clang+llvm-${VER}-*" | head -n 1)"
if [[ -z "${topdir:-}" ]]; then
echo "Could not locate extracted directory for $archive" >&2
exit 4
fi
if [[ ! -f "$topdir/$inner" ]]; then
echo "Missing expected file inside archive: $inner" >&2
exit 5
fi
cp "$topdir/$inner" "$outpath"
rm -rf "$topdir"
}
# Linux x86_64 -> clang-format
fetch_and_extract "$LINUX_X86" "$DEST/linux-x86_64/clang-format" "bin/clang-format"
chmod +x "$DEST/linux-x86_64/clang-format"
# Linux arm64 -> clang-format
fetch_and_extract "$LINUX_A64" "$DEST/linux-arm64/clang-format" "bin/clang-format"
chmod +x "$DEST/linux-arm64/clang-format"
# macOS arm64 -> clang-format
fetch_and_extract "$MAC_A64" "$DEST/macos-arm64/clang-format" "bin/clang-format"
chmod +x "$DEST/macos-arm64/clang-format"
# Windows x86_64 -> clang-format.exe
fetch_and_extract "$WIN_X86" "$DEST/windows-x86_64/clang-format.exe" "bin/clang-format.exe"
echo
echo "Done. Installed pinned clang-format binaries under:"
echo " $DEST"
echo
echo "Verify:"
"$ROOT/tools/clang-format" --version || true