File PKGBUILD of Package clang21

pkgname=clang21
pkgver=21.1.3
pkgrel=1
pkgdesc="C language family frontend for LLVM 21"
arch=('x86_64')
url="https://clang.llvm.org/"
license=('Apache-2.0 WITH LLVM-exception')
depends=('llvm21-libs' 'gcc' 'compiler-rt21')
makedepends=('llvm21' 'cmake' 'ninja' 'python' 'mold')
optdepends=(
  'openmp: OpenMP support in clang with -fopenmp'
  'python: for scan-view and git-clang-format'
  'llvm21: referenced by some clang headers'
)
source=(llvm-project.tar)
b2sums=('SKIP')

# Utilizing LLVM_DISTRIBUTION_COMPONENTS to avoid
# installing static libraries; inspired by Gentoo
_get_distribution_components() {
  local target
  ninja -t targets | grep -Po 'install-\K.*(?=-stripped:)' | while read -r target; do
    case $target in
    clang-libraries | distribution)
      continue
      ;;
    clang | clangd | clang-*) ;;
    clang* | findAllSymbols)
      continue
      ;;
    esac
    echo $target
  done
}

prepare() {
  mkdir llvm-project/clang/build
}

build() {
  cd llvm-project/clang/build

  local cmake_args=(
    CMAKE_BUILD_TYPE=Release
    CMAKE_INSTALL_PREFIX=/usr/lib/llvm21
    CMAKE_PREFIX_PATH=/usr/lib/llvm21
    CMAKE_BUILD_WITH_INSTALL_RPATH=ON
    CLANG_DEFAULT_PIE_ON_LINUX=ON
    CLANG_LINK_CLANG_DYLIB=ON
    CLANG_BUILD_TOOLS=OFF
    ENABLE_LINKER_BUILD_ID=ON
    LLVM_CONFIG=/usr/lib/llvm21/bin/llvm-config
    LLVM_ENABLE_RTTI=OFF
    LLVM_INCLUDE_DOCS=OFF
    LLVM_INCLUDE_TESTS=OFF
    LLVM_LINK_LLVM_DYLIB=ON

    CMAKE_C_FLAGS="-O3 -march=znver3 -pipe"
    CMAKE_CXX_FLAGS="-O3 -march=znver3 -pipe"
    LLVM_USE_LINKER=mold
  )

  cmake .. -GNinja "${cmake_args[@]/#/-D}"
  local distribution_components=$(_get_distribution_components | paste -sd\;)
  test -n "$distribution_components"
  cmake_args+=(LLVM_DISTRIBUTION_COMPONENTS="$distribution_components")

  cmake .. -GNinja "${cmake_args[@]/#/-D}"
  ninja
}

package() {
  cd llvm-project/clang/build

  DESTDIR="$pkgdir" ninja install-distribution
  install -Dm644 ../LICENSE.TXT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

# vim:set ts=2 sw=2 et:
openSUSE Build Service is sponsored by