Skip to content

Commit 8e1d373

Browse files
committed
Separated llvm docker
1 parent 6794ef1 commit 8e1d373

File tree

3 files changed

+78
-23
lines changed

3 files changed

+78
-23
lines changed

backend/Dockerfile

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,34 @@
1+
ARG LLVM_IMAGE=ghcr.io/ftsrg/cir-demo-llvm:latest
2+
3+
# Allow copying LLVM from the prebuilt llvm image into this image. This way you
4+
# can build the LLVM image locally (tag it with the same name) and then build
5+
# the backend image on your machine without running the costly LLVM build in CI.
6+
FROM ${LLVM_IMAGE} AS llvm
7+
18
FROM node:25-trixie
29

310
WORKDIR /app
411

12+
# Copy LLVM installation from the llvm image
13+
514
RUN wget 'https://github.com/ftsrg/theta/releases/latest/download/Theta.zip' -O /app/Theta.zip \
615
&& unzip /app/Theta.zip \
716
&& rm /app/Theta.zip \
817
&& sed -i 's/export JAVA_VERSION=17/export JAVA_VERSION=21/g' /app/Theta/theta-start.sh
918

1019
# copy package and source
1120
COPY backend /app/backend
21+
COPY --from=llvm /opt/cir /app/backend/bin
1222

1323
WORKDIR /app/backend
1424
RUN npm install --production
1525

1626
ENV DEBIAN_FRONTEND=noninteractive
1727
RUN apt-get update \
1828
&& apt-get install -y --no-install-recommends ca-certificates libstdc++6 \
19-
build-essential cmake ninja-build pkg-config python3 git \
29+
build-essential cmake ninja-build pkg-config python3 git \
2030
openjdk-21-jdk-headless libgomp1 libmpfr-dev \
21-
clang lld
22-
23-
# Build LLVM/ClangIR if backend/bin doesn't exist
24-
# This checks if bin directory exists in the COPY context, and if not, builds LLVM
25-
RUN if [ ! -d /app/backend/bin ]; then \
26-
cd /tmp && \
27-
git clone --depth=1 https://github.com/llvm/clangir.git && \
28-
cmake -S clangir/llvm -B build -GNinja \
29-
-DCLANG_ENABLE_CIR=ON \
30-
-DLLVM_ENABLE_PROJECTS="clang;mlir" \
31-
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
32-
-DLLVM_TARGETS_TO_BUILD=host \
33-
-DCMAKE_CXX_COMPILER=clang++ \
34-
-DCMAKE_C_COMPILER=clang \
35-
-DLLVM_USE_LINKER=lld \
36-
-DBUILD_SHARED_LIBS=ON \
37-
-DCMAKE_INSTALL_PREFIX=/app/backend/bin \
38-
-DLLVM_FORCE_VC_REVISION=$(head -c7 /tmp/clangir/.git/refs/heads/main)-zorn && \
39-
cmake --build build -j$(nproc) && \
40-
cmake --install build && \
41-
cd / && rm -rf /tmp/clangir /tmp/build; \
42-
fi
31+
&& rm -rf /var/lib/apt/lists/*
4332

4433
# Build the xcfa-mapper C++ tool so the backend can call it. We copy the
4534
# source tree and invoke CMake to produce the binary at xcfa-mapper/build/xcfa-mapper

docker/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,33 @@ Usage
2626
Notes
2727
- The generated cert is self-signed; browsers will warn. For production, use a CA-signed certificate.
2828
- The backend credentials file is stored as plaintext JSON for simplicity; for real deployments use docker secrets or a vault.
29+
30+
Building the LLVM base image locally
31+
-----------------------------------
32+
33+
If you want to build the heavy LLVM/ClangIR image locally (so the backend image can reuse it), you can build and tag it locally and optionally push it to GitHub Container Registry (ghcr.io).
34+
35+
1) Build locally and tag as the expected registry name (so backend builds pick it up):
36+
37+
```sh
38+
docker build -f docker/llvm.Dockerfile -t ghcr.io/ftsrg/cir-demo-llvm:latest .
39+
```
40+
41+
2) (Optional) Push to GitHub Container Registry if you want others or CI to pull it:
42+
43+
```sh
44+
# Create a PAT with "read:packages" and "write:packages" and (recommended) repo scope.
45+
echo "${CR_PAT}" | docker login ghcr.io -u YOUR_GITHUB_USERNAME --password-stdin
46+
docker push ghcr.io/ftsrg/cir-demo-llvm:latest
47+
```
48+
49+
After the image is available locally (or in ghcr), building the backend image will copy `/opt/cir` from that llvm image into the backend image. The backend Dockerfile accepts a build-arg `LLVM_IMAGE` so you can override the reference if you used a different tag:
50+
51+
```sh
52+
docker build --build-arg LLVM_IMAGE=ghcr.io/ftsrg/cir-demo-llvm:latest -f backend/Dockerfile -t ghcr.io/ftsrg/cir-demo-backend:latest .
53+
```
54+
55+
Notes:
56+
- Building LLVM is resource- and time-intensive. Building it once locally and pushing it to ghcr is usually faster overall.
57+
- The `docker/llvm.Dockerfile` installs LLVM into `/opt/cir` (this is what the backend copies into its final image).
58+

docker/llvm.Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM debian:trixie-slim
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ENV LC_ALL=C.UTF-8
5+
6+
RUN apt-get update \
7+
&& apt-get install -y --no-install-recommends \
8+
ca-certificates git cmake ninja-build build-essential pkg-config python3 \
9+
clang lld wget curl ca-certificates libstdc++6 libgomp1 libmpfr-dev \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
WORKDIR /tmp
13+
14+
# Clone ClangIR (shallow) and build LLVM with CLANG_ENABLE_CIR
15+
RUN git clone --depth=1 https://github.com/llvm/clangir.git && \
16+
cmake -S clangir/llvm -B build -GNinja \
17+
-DCLANG_ENABLE_CIR=ON \
18+
-DLLVM_ENABLE_PROJECTS="clang;mlir" \
19+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
20+
-DLLVM_TARGETS_TO_BUILD=host \
21+
-DCMAKE_CXX_COMPILER=clang++ \
22+
-DCMAKE_C_COMPILER=clang \
23+
-DLLVM_USE_LINKER=lld \
24+
-DBUILD_SHARED_LIBS=ON \
25+
-DCMAKE_INSTALL_PREFIX=/opt/cir \
26+
-DLLVM_FORCE_VC_REVISION=$(head -c7 clangir/.git/refs/heads/main)-zorn && \
27+
cmake --build build -j$(nproc) && \
28+
cmake --install build && \
29+
rm -rf /tmp/clangir /tmp/build
30+
31+
ENV PATH="/opt/cir/bin:${PATH}"
32+
33+
LABEL org.opencontainers.image.title="cir-demo-llvm" \
34+
org.opencontainers.image.description="Base image with LLVM+Clang built with CLANG_ENABLE_CIR and installed to /opt/cir"
35+
36+
CMD ["/bin/sh","-c","echo 'This image only provides LLVM in /opt/cir' && /bin/sh"]

0 commit comments

Comments
 (0)