|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Install LLVM 21 for RediSearch's cross-language (C/Rust) LTO build. |
| 3 | +# LLVM has no dnf repo, so we use the official upstream tarball. |
| 4 | +# |
| 5 | +# Rocky 10 only: ships libstdc++ with GLIBCXX_3.4.32 which satisfies the |
| 6 | +# GLIBCXX_3.4.30+ requirement of the prebuilt LLVM 21 binaries. |
| 7 | +# Rocky 8 and Rocky 9 are not supported (incompatible libstdc++ at runtime). |
| 8 | + |
| 9 | +set -euo pipefail |
| 10 | + |
| 11 | +LLVM_VERSION="${LLVM_VERSION:-21.1.8}" |
| 12 | +MAJOR="${LLVM_VERSION%%.*}" |
| 13 | + |
| 14 | +case "$(uname -m)" in |
| 15 | + x86_64) asset="LLVM-${LLVM_VERSION}-Linux-X64.tar.xz" ;; |
| 16 | + aarch64) asset="LLVM-${LLVM_VERSION}-Linux-ARM64.tar.xz" ;; |
| 17 | + *) echo "Unsupported arch: $(uname -m)" >&2; exit 1 ;; |
| 18 | +esac |
| 19 | + |
| 20 | +install_root="/opt/llvm-${LLVM_VERSION}" |
| 21 | +mkdir -p "$install_root" |
| 22 | +curl -fsSL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/${asset}" \ |
| 23 | + | tar -xJ -C "$install_root" --strip-components=1 |
| 24 | +ln -sfn "$install_root" /opt/llvm |
| 25 | + |
| 26 | +# RediSearch's build scripts look up clang-${MAJOR}, lld-${MAJOR}, etc. on PATH; |
| 27 | +# the upstream tarball ships unsuffixed names only, so alias them. |
| 28 | +for tool in clang clang++ clang-cpp lld ld.lld ld64.lld lld-link llc opt \ |
| 29 | + llvm-ar llvm-nm llvm-ranlib llvm-strip llvm-objcopy llvm-objdump \ |
| 30 | + llvm-readelf llvm-config; do |
| 31 | + src="/opt/llvm/bin/${tool}" |
| 32 | + dst="/opt/llvm/bin/${tool}-${MAJOR}" |
| 33 | + [ -e "$src" ] && [ ! -e "$dst" ] && ln -sfn "$src" "$dst" |
| 34 | +done |
| 35 | + |
| 36 | +echo 'export PATH=/opt/llvm/bin:$PATH' > /etc/profile.d/llvm.sh |
| 37 | + |
| 38 | +/opt/llvm/bin/clang-${MAJOR} --version |
| 39 | +/opt/llvm/bin/ld.lld-${MAJOR} --version |
0 commit comments