# Build only the clang-format tool out of LLVM/Clang, as a statically linked # binary installed as /usr/bin/clang-format-22 (coexists with the distro clang). # The git-clang-format / clang-format-diff helper scripts go into the # python-dependent -tools subpackage. %global maj_ver 22 Name: clang-format-%{maj_ver} Version: 22.1.7 Release: 2%{?dist} Summary: Standalone, statically linked clang-format from LLVM %{maj_ver} License: Apache-2.0 WITH LLVM-exception URL: https://github.com/llvm/llvm-project # Since LLVM 22 upstream no longer publishes per-project source tarballs # (llvm-/clang-/cmake-*.src.tar.xz); only the monolithic tree is released. Source0: %{url}/releases/download/llvmorg-%{version}/llvm-project-%{version}.src.tar.xz # A fully static binary carries no shared-library symbols, so there is no # debuginfo to extract and no .so to ldconfig. %define debug_package %{nil} BuildRequires: cmake >= 3.20.0 BuildRequires: ninja-build BuildRequires: gcc BuildRequires: gcc-c++ BuildRequires: make BuildRequires: python3 BuildRequires: xz # needed to link -static BuildRequires: glibc-static BuildRequires: libstdc++-static %description clang-format reformats C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# source according to a configurable style. This package provides the clang-format tool from LLVM/Clang %{version} as a self-contained statically linked executable, installed under %{_libdir}/llvm%{maj_ver} with a versioned clang-format-%{maj_ver} symlink in %{_bindir}. The python-based helper scripts live in the %{name}-tools subpackage. %package tools Summary: git-clang-format and clang-format helper scripts for LLVM %{maj_ver} Requires: %{name} = %{version}-%{release} # git-clang-format needs git at runtime Recommends: git-core %description tools git-clang-format-%{maj_ver}, clang-format-diff-%{maj_ver} and the editor integration scripts (vim, emacs, sublime) for clang-format-%{maj_ver}. Unlike the statically linked binary, these need python3 at runtime. %prep rm -rf llvm-project build tar -xf %{SOURCE0} mv llvm-project-%{version}.src llvm-project %build # CMAKE_SKIP_RPATH: cmake --install would otherwise try to rewrite the build # RPATH to $ORIGIN/../lib, which fails on a fully static binary (no ELF # dynamic section). cmake -G Ninja -S llvm-project/llvm -B build \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=%{_libdir}/llvm%{maj_ver} \ -DCMAKE_SKIP_RPATH=ON \ -DLLVM_ENABLE_PROJECTS=clang \ -DLLVM_TARGETS_TO_BUILD=X86 \ -DLLVM_APPEND_VC_REV=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DLLVM_BUILD_LLVM_DYLIB=OFF \ -DLLVM_LINK_LLVM_DYLIB=OFF \ -DLLVM_ENABLE_PIC=OFF \ -DLLVM_BUILD_TOOLS=OFF \ -DLLVM_INCLUDE_TESTS=OFF \ -DLLVM_INCLUDE_EXAMPLES=OFF \ -DLLVM_INCLUDE_BENCHMARKS=OFF \ -DLLVM_ENABLE_ZLIB=OFF \ -DLLVM_ENABLE_ZSTD=OFF \ -DLLVM_ENABLE_LIBXML2=OFF \ -DLLVM_ENABLE_LIBEDIT=OFF \ -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ -DCLANG_ENABLE_ARCMT=OFF \ -DCMAKE_EXE_LINKER_FLAGS="-static -static-libgcc -static-libstdc++" cmake --build build --target clang-format %install # Patch the helper scripts to invoke the versioned binary by default since # this package puts no unversioned clang-format on PATH. scripts=llvm-project/clang/tools/clang-format sed -i "s/\([\"']\)clang-format\1/\1clang-format-%{maj_ver}\1/g" \ $scripts/git-clang-format $scripts/clang-format-diff.py \ $scripts/clang-format.py $scripts/clang-format-sublime.py $scripts/clang-format.el # Upstream install rules cover the binary and all helper scripts. DESTDIR=%{buildroot} cmake --install build --component clang-format --strip # Versioned entry points, coexisting with the distro clang. mkdir -p %{buildroot}%{_bindir} ln -s ../%{_lib}/llvm%{maj_ver}/bin/clang-format %{buildroot}%{_bindir}/clang-format-%{maj_ver} ln -s ../%{_lib}/llvm%{maj_ver}/bin/git-clang-format %{buildroot}%{_bindir}/git-clang-format-%{maj_ver} ln -s ../%{_lib}/llvm%{maj_ver}/share/clang/clang-format-diff.py %{buildroot}%{_bindir}/clang-format-diff-%{maj_ver} %check # Confirm the produced binary is actually static and runs. file %{buildroot}%{_libdir}/llvm%{maj_ver}/bin/clang-format %{buildroot}%{_bindir}/clang-format-%{maj_ver} --version # Confirm the patched scripts still parse and run. %{buildroot}%{_bindir}/clang-format-diff-%{maj_ver} --help >/dev/null python3 -m py_compile llvm-project/clang/tools/clang-format/git-clang-format %files %license llvm-project/llvm/LICENSE.TXT %{_bindir}/clang-format-%{maj_ver} %dir %{_libdir}/llvm%{maj_ver} %dir %{_libdir}/llvm%{maj_ver}/bin %{_libdir}/llvm%{maj_ver}/bin/clang-format %files tools %license llvm-project/llvm/LICENSE.TXT %{_bindir}/clang-format-diff-%{maj_ver} %{_bindir}/git-clang-format-%{maj_ver} %{_libdir}/llvm%{maj_ver}/bin/git-clang-format %{_libdir}/llvm%{maj_ver}/share/ %changelog * Sat Aug 08 2026 Yuki Yamaura 22.1.7-2 - Install the upstream clang-format component (binary, git-clang-format, clang-format-diff.py, editor scripts) under %%{_libdir}/llvm22 via cmake --install - Add versioned symlinks clang-format-22, git-clang-format-22 and clang-format-diff-22 in /usr/bin - Split the python-dependent scripts into the -tools subpackage * Sat Jun 06 2026 Yuki Yamaura 22.1.7-1 - Initial package: standalone static clang-format from LLVM 22.1.7