Skip to content

Commit deab104

Browse files
committed
feat: switch release runner to ubuntu-22.04 and build LLVM with FFI disabled
1 parent 7eb71c6 commit deab104

File tree

3 files changed

+177
-43
lines changed

3 files changed

+177
-43
lines changed

.github/workflows/base-image.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build Base Image
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- Dockerfile
8+
- .github/workflows/base-image.yml
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v3
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Login to GHCR
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Docker metadata
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ghcr.io/swananan/ghostscope-build
38+
tags: |
39+
type=raw,value=ubuntu20.04-llvm18.1.8
40+
type=sha
41+
42+
- name: Build and push
43+
uses: docker/build-push-action@v6
44+
with:
45+
context: .
46+
file: Dockerfile
47+
push: true
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}
50+
platforms: linux/amd64
51+
cache-from: type=gha
52+
cache-to: type=gha,mode=max
53+

.github/workflows/release.yml

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,57 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-22.04
1212

1313
steps:
1414
- uses: actions/checkout@v4
1515

16-
- name: Install LLVM 18 and dependencies
16+
- name: Select base image (GHCR or local fallback)
1717
run: |
18-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
19-
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-18 main"
20-
sudo apt-get update
21-
sudo apt-get install -y \
22-
llvm-18 llvm-18-dev llvm-18-runtime \
23-
clang-18 libclang-18-dev \
24-
libpolly-18-dev \
25-
libzstd-dev zlib1g-dev libtinfo-dev libxml2-dev
26-
27-
- name: Install Rust
28-
uses: dtolnay/rust-toolchain@stable
29-
30-
- name: Set LLVM environment
18+
set -euo pipefail
19+
IMAGE="ghcr.io/swananan/ghostscope-build:ubuntu20.04-llvm18.1.8"
20+
if docker pull "$IMAGE" >/dev/null 2>&1; then
21+
echo "Using GHCR base image: $IMAGE"
22+
echo "BASE_IMAGE=$IMAGE" >> "$GITHUB_ENV"
23+
echo "BASE_IMAGE_FROM=ghcr" >> "$GITHUB_ENV"
24+
else
25+
echo "GHCR image not found; will build local image."
26+
echo "BASE_IMAGE=ghostscope-build" >> "$GITHUB_ENV"
27+
echo "BASE_IMAGE_FROM=local" >> "$GITHUB_ENV"
28+
fi
29+
30+
- name: Build container image (Ubuntu 20.04)
31+
if: ${{ env.BASE_IMAGE_FROM == 'local' }}
32+
run: docker build -t ghostscope-build -f Dockerfile .
33+
34+
- name: Verify LLVM in container (no libffi)
3135
run: |
32-
echo "LLVM_SYS_181_PREFIX=/usr/lib/llvm-18" >> $GITHUB_ENV
33-
echo "/usr/lib/llvm-18/bin" >> $GITHUB_PATH
36+
docker run --rm \
37+
-v "${{ github.workspace }}:/workspace" \
38+
-w /workspace \
39+
"${BASE_IMAGE}" bash -lc '
40+
echo "llvm-config version:" && llvm-config --version && \
41+
echo "Checking libLLVM for libffi dependency (should be none)..." && \
42+
(ldd "$(llvm-config --libdir)"/libLLVM* | grep -i ffi && exit 1 || echo "OK: no libffi referenced")
43+
'
3444
35-
- name: Verify LLVM installation
45+
- name: Build release inside container
3646
run: |
37-
llvm-config-18 --version
38-
llvm-config-18 --prefix
47+
docker run --rm \
48+
-v "${{ github.workspace }}:/workspace" \
49+
-w /workspace \
50+
"${BASE_IMAGE}" \
51+
bash -lc 'export LLVM_SYS_181_PREFIX=/opt/llvm-18; export LLVM_CONFIG_PATH=/opt/llvm-18/bin/llvm-config; export RUSTFLAGS="-C link-arg=-Wl,--as-needed"; rustup show; llvm-config --version; echo "llvm-config system-libs:"; llvm-config --system-libs; cargo clean; cargo build --release'
3952
40-
- name: Build release
41-
run: cargo build --release
53+
- name: glibc version in container
54+
run: |
55+
docker run --rm -w /workspace \
56+
-v "${{ github.workspace }}:/workspace" \
57+
"${BASE_IMAGE}" bash -lc 'ldd --version | head -1'
4258
4359
- name: Check glibc dependency
4460
run: |
45-
echo "=== glibc version on build system ==="
46-
ldd --version | head -1
47-
echo "=== Required glibc versions ==="
61+
echo "=== Required glibc versions (from binary) ==="
4862
objdump -T ./target/release/ghostscope | grep GLIBC | sed 's/.*GLIBC_\([.0-9]*\).*/\1/g' | sort -Vu
4963
echo "=== Binary info ==="
5064
file ./target/release/ghostscope

Dockerfile

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,102 @@ FROM ubuntu:20.04
33
# Avoid interactive prompts during package installation
44
ENV DEBIAN_FRONTEND=noninteractive
55

6-
# Install build dependencies
6+
# Base build/runtime dependencies
77
RUN apt-get update && apt-get install -y \
8-
wget \
8+
ca-certificates \
99
curl \
10+
wget \
1011
git \
12+
xz-utils \
13+
tar \
14+
pkg-config \
1115
build-essential \
12-
software-properties-common \
13-
gnupg \
14-
lsb-release \
16+
ninja-build \
17+
python3 \
18+
libzstd-dev zlib1g-dev libxml2-dev libffi-dev \
1519
&& rm -rf /var/lib/apt/lists/*
1620

17-
# Install LLVM 18
18-
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
19-
&& add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-18 main" \
20-
&& apt-get update \
21-
&& apt-get install -y \
22-
llvm-18 llvm-18-dev llvm-18-runtime \
23-
clang-18 libclang-18-dev \
24-
libpolly-18-dev \
25-
libzstd-dev zlib1g-dev libtinfo-dev libxml2-dev \
26-
&& rm -rf /var/lib/apt/lists/*
21+
# Install a modern CMake (>=3.20) from official binary tarball to avoid slow APT mirrors
22+
ARG CMAKE_VER=3.29.6
23+
RUN set -eux; \
24+
url1="https://cmake.org/files/v${CMAKE_VER%.*}/cmake-${CMAKE_VER}-linux-x86_64.tar.gz"; \
25+
url2="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-linux-x86_64.tar.gz"; \
26+
echo "Downloading CMake ${CMAKE_VER}..."; \
27+
( \
28+
curl -fL --retry 5 --retry-delay 3 --retry-all-errors -o /tmp/cmake.tar.gz "$url1" \
29+
|| wget -O /tmp/cmake.tar.gz --tries=5 --waitretry=3 --retry-connrefused "$url1" \
30+
|| curl -fL --retry 5 --retry-delay 3 --retry-all-errors -o /tmp/cmake.tar.gz "$url2" \
31+
|| wget -O /tmp/cmake.tar.gz --tries=5 --waitretry=3 --retry-connrefused "$url2" \
32+
); \
33+
tar -C /opt -xzf /tmp/cmake.tar.gz; \
34+
cmake_dir=$(tar -tzf /tmp/cmake.tar.gz | head -1 | cut -f1 -d'/'); \
35+
mv "/opt/${cmake_dir}" /opt/cmake; \
36+
ln -s /opt/cmake/bin/* /usr/local/bin/; \
37+
cmake --version; \
38+
rm -f /tmp/cmake.tar.gz
39+
40+
# Build and install LLVM 18.1.x from source with FFI disabled
41+
# This removes the runtime dependency on libffi while keeping needed targets.
42+
ARG LLVM_VER=18.1.8
43+
RUN set -eux; \
44+
base_url="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VER}"; \
45+
tar_xz="llvm-project-${LLVM_VER}.src.tar.xz"; \
46+
alt_url="https://codeload.github.com/llvm/llvm-project/tar.xz/refs/tags/llvmorg-${LLVM_VER}"; \
47+
echo "Downloading LLVM ${LLVM_VER} source tarball..."; \
48+
( \
49+
curl -fL --retry 5 --retry-delay 3 --retry-all-errors -o /tmp/llvm.tar.xz "$base_url/$tar_xz" \
50+
|| wget -O /tmp/llvm.tar.xz --tries=5 --waitretry=3 --retry-connrefused "$base_url/$tar_xz" \
51+
|| curl -fL --retry 5 --retry-delay 3 --retry-all-errors -o /tmp/llvm.tar.xz "$alt_url" \
52+
|| wget -O /tmp/llvm.tar.xz --tries=5 --waitretry=3 --retry-connrefused "$alt_url" \
53+
); \
54+
test -s /tmp/llvm.tar.xz; \
55+
mkdir -p /tmp/llvm && tar -C /tmp/llvm --strip-components=1 -xf /tmp/llvm.tar.xz; \
56+
cmake -G Ninja -S /tmp/llvm/llvm -B /tmp/llvm-build \
57+
-DCMAKE_BUILD_TYPE=Release \
58+
-DLLVM_ENABLE_PROJECTS=clang \
59+
-DLLVM_TARGETS_TO_BUILD="BPF;X86" \
60+
-DLLVM_BUILD_LLVM_DYLIB=ON \
61+
-DLLVM_LINK_LLVM_DYLIB=ON \
62+
-DLLVM_ENABLE_FFI=OFF \
63+
-DLLVM_ENABLE_TERMINFO=OFF \
64+
-DLLVM_ENABLE_ZLIB=ON \
65+
-DLLVM_ENABLE_ZSTD=ON \
66+
-DCMAKE_INSTALL_PREFIX=/opt/llvm-18; \
67+
ninja -C /tmp/llvm-build install; \
68+
# Wrap llvm-config to filter out any stray -lffi from system-libs output
69+
if [ -x /opt/llvm-18/bin/llvm-config ]; then \
70+
mv /opt/llvm-18/bin/llvm-config /opt/llvm-18/bin/llvm-config.real; \
71+
cat > /opt/llvm-18/bin/llvm-config <<'WRAP' ; \
72+
#!/bin/sh
73+
REAL="/opt/llvm-18/bin/llvm-config.real"
74+
# Capture stdout+stderr and original exit status
75+
OUT="$($REAL "$@" 2>&1)"; RC=$?
76+
if [ $RC -ne 0 ]; then
77+
printf '%s\n' "$OUT" >&2
78+
exit $RC
79+
fi
80+
# Filter only library flag queries; pass-through otherwise
81+
case " $* " in
82+
*" --system-libs "*|*" --libs "*|*" --ldflags "*)
83+
printf '%s\n' "$OUT" | sed -E 's/(^|[[:space:]])-lffi([[:space:]]|$)/\1\2/g'
84+
;;
85+
*)
86+
printf '%s\n' "$OUT"
87+
;;
88+
esac
89+
exit 0
90+
WRAP
91+
chmod +x /opt/llvm-18/bin/llvm-config; \
92+
fi; \
93+
rm -rf /tmp/llvm /tmp/llvm-build /tmp/llvm.tar.xz
2794

2895
# Install Rust (version specified in rust-toolchain.toml will be used)
2996
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
3097
ENV PATH="/root/.cargo/bin:$PATH"
3198

32-
# Set LLVM environment variable
33-
ENV LLVM_SYS_181_PREFIX=/usr/lib/llvm-18
34-
ENV PATH="/usr/lib/llvm-18/bin:$PATH"
99+
# Expose LLVM to llvm-sys/inkwell
100+
ENV LLVM_SYS_181_PREFIX=/opt/llvm-18
101+
ENV PATH="/opt/llvm-18/bin:$PATH"
35102

36103
# Set working directory
37104
WORKDIR /workspace

0 commit comments

Comments
 (0)