Skip to content

Commit 2978f9a

Browse files
Enable RediSearch LTO on Rocky Linux 10
RediSearch enables LTO by default in unstable and requires a clang whose LLVM major matches rustc's (currently LLVM 21 from rustc 1.94). The LLVM project does not publish a dnf repository for RHEL/Rocky, so we install the official LLVM 21 tarball into /opt/llvm and add it to PATH. Restricted to Rocky 10. The upstream LLVM 21 binaries require GLIBCXX_3.4.30+ which is only available on Rocky 10's system libstdc++; Rocky 8 and 9 ship 3.4.25 and 3.4.28 respectively. Making LTO work there would require bundling a newer libstdc++ alongside the produced redisearch.so on every customer machine, which is out of scope for now. Rocky 8/9 continue to build with LTO=0. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 995632b commit 2978f9a

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

.github/actions/build-package/action.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ runs:
9292
export DISABLE_WERRORS=yes
9393
export BUILD_TLS=yes
9494
export USE_SYSTEMD=yes
95-
# Override RediSearch's new LTO=1 default; toolchain support TBD.
96-
export LTO=0
95+
# Enable RediSearch LTO only where LLVM 21 is available (Rocky 10).
96+
# Rocky 8/9 lack libstdc++ with GLIBCXX_3.4.30+ that upstream LLVM 21
97+
# binaries require, so keep LTO=0 there.
98+
if [ -x /opt/llvm/bin/clang-21 ]; then
99+
export LTO=1
100+
export PATH=/opt/llvm/bin:$PATH
101+
else
102+
export LTO=0
103+
fi
97104
98105
if [ "${{ steps.version.outputs.VERSION }}" = "unstable" ]; then
99106
# Clone Redis unstable branch instead of downloading release tarball

dockerfiles/Dockerfile.rockylinux10

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ RUN echo '[goreleaser]\nname=GoReleaser\nbaseurl=https://repo.goreleaser.com/yum
4242
COPY install/install_cmake.sh /tmp/
4343
RUN bash /tmp/install_cmake.sh
4444

45+
# Install LLVM 21 for RediSearch LTO (Rocky 10 only; see install_llvm.sh).
46+
COPY install/install_llvm.sh /tmp/
47+
RUN bash /tmp/install_llvm.sh
48+
4549
# Set environment
46-
ENV PATH="/usr/local/bin:/opt/venv/bin:${PATH}"
50+
ENV PATH="/opt/llvm/bin:/usr/local/bin:/opt/venv/bin:${PATH}"
4751
WORKDIR /build
4852

4953
# Default command

install/install_llvm.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# Install upstream LLVM 21 toolchain for RediSearch's LTO build (rustc 1.94
3+
# ships LLVM 21, and RediSearch requires the C compiler's LLVM major to match).
4+
# LLVM has no dnf repo for RHEL/Rocky, so we fetch the official tarball.
5+
#
6+
# Only intended for Rocky Linux 10: its system libstdc++ already provides
7+
# GLIBCXX_3.4.32, so the prebuilt LLVM binaries (which need 3.4.30+) load as-is.
8+
# Rocky 8/9 ship older libstdc++ and would need additional bundling work, so
9+
# LTO stays disabled there for now.
10+
11+
set -euo pipefail
12+
13+
LLVM_VERSION="${LLVM_VERSION:-21.1.8}"
14+
MAJOR="${LLVM_VERSION%%.*}"
15+
16+
case "$(uname -m)" in
17+
x86_64) asset="LLVM-${LLVM_VERSION}-Linux-X64.tar.xz" ;;
18+
aarch64) asset="LLVM-${LLVM_VERSION}-Linux-ARM64.tar.xz" ;;
19+
*) echo "Unsupported arch: $(uname -m)" >&2; exit 1 ;;
20+
esac
21+
22+
install_root="/opt/llvm-${LLVM_VERSION}"
23+
mkdir -p "$install_root"
24+
curl -fsSL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/${asset}" \
25+
| tar -xJ -C "$install_root" --strip-components=1
26+
ln -sfn "$install_root" /opt/llvm
27+
28+
# RediSearch's build scripts look up clang-${MAJOR}, lld-${MAJOR}, etc. on PATH;
29+
# the upstream tarball ships unsuffixed names only, so alias them.
30+
for tool in clang clang++ clang-cpp lld ld.lld ld64.lld lld-link llc opt \
31+
llvm-ar llvm-nm llvm-ranlib llvm-strip llvm-objcopy llvm-objdump \
32+
llvm-readelf llvm-config; do
33+
src="/opt/llvm/bin/${tool}"
34+
dst="/opt/llvm/bin/${tool}-${MAJOR}"
35+
[ -e "$src" ] && [ ! -e "$dst" ] && ln -sfn "$src" "$dst"
36+
done
37+
38+
echo 'export PATH=/opt/llvm/bin:$PATH' > /etc/profile.d/llvm.sh
39+
40+
/opt/llvm/bin/clang-${MAJOR} --version
41+
/opt/llvm/bin/ld.lld-${MAJOR} --version

0 commit comments

Comments
 (0)