Skip to content

Commit f0eef62

Browse files
authored
Merge pull request #57 from redis/enable-lto-redisearch
Enable LTO for RediSearch module when Redis is builed with modules
2 parents 995632b + 8920c19 commit f0eef62

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ runs:
8383
# Source gcc-toolset environment (version depends on distro)
8484
if [ -f /etc/profile.d/gcc-toolset-15.sh ]; then
8585
source /etc/profile.d/gcc-toolset-15.sh
86-
# Fallback for Rocky Linux 8/9
86+
elif [ -f /etc/profile.d/gcc-toolset-14.sh ]; then
87+
source /etc/profile.d/gcc-toolset-14.sh
8788
elif [ -f /etc/profile.d/gcc-toolset-13.sh ]; then
8889
source /etc/profile.d/gcc-toolset-13.sh
8990
fi
@@ -92,8 +93,15 @@ runs:
9293
export DISABLE_WERRORS=yes
9394
export BUILD_TLS=yes
9495
export USE_SYSTEMD=yes
95-
# Override RediSearch's new LTO=1 default; toolchain support TBD.
96-
export LTO=0
96+
# Enable RediSearch LTO only where our LLVM toolchain is installed.
97+
# Rocky 8 and 9 lacks a compatible libstdc++ runtime for the prebuilt LLVM
98+
# binaries so it has no /opt/llvm; Rocky 10 does.
99+
if [ -x /opt/llvm/bin/clang ]; then
100+
export LTO=1
101+
export PATH=/opt/llvm/bin:$PATH
102+
else
103+
export LTO=0
104+
fi
97105
98106
if [ "${{ steps.version.outputs.VERSION }}" = "unstable" ]; then
99107
# 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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
 (0)