1+ # Stage 1: FFI Builder
2+ # ============================================================================
3+ #
4+ # Compiles all Zig FFI layers (core + all cartridges) in ReleaseFast mode,
5+ # then compiles the V adapter binary against those FFI libs — fully
6+ # self-contained, no local pre-build required.
7+ =======
18# SPDX-License-Identifier: PMPL-1.0-or-later
29# Bundle of Joy Server Container Image
310#
4- # Multi-stage build: Zig FFI compilation + V adapter binary (both built
11+ # Multi-stage build: Zig FFI compilation + Zig adapter binary (both built
512# inside Stage 1 — no local pre-build required).
613#
714# Build with Podman:
1926# ============================================================================
2027#
2128# Compiles all Zig FFI layers (core + all cartridges) in ReleaseFast mode,
29+ # then compiles the Zig adapter binary against those FFI libs — fully
30+ # self-contained, no local pre-build required.============================================================================
31+ # Stage 1: FFI Builder
32+ # ============================================================================
33+ #
34+ # Compiles all Zig FFI layers (core + all cartridges) in ReleaseFast mode,
2235# then compiles the V adapter binary against those FFI libs — fully
2336# self-contained, no local pre-build required.
2437
2538FROM cgr.dev/chainguard/wolfi-base:latest AS builder
2639
27- # Install Zig toolchain, C toolchain, Git (needed to bootstrap V compiler),
28- # and sqlite dev headers (linked by some cartridge FFIs).
29- RUN apk add --no-cache build-base zig sqlite-dev git
40+ # Install Zig toolchain, C toolchain, and sqlite dev headers (linked by some cartridge FFIs).
41+ RUN apk add --no-cache build-base zig sqlite-dev
3042
3143WORKDIR /build
3244
@@ -46,20 +58,19 @@ RUN for ffi_dir in /build/cartridges/*/ffi; do \
4658 fi; \
4759 done
4860
49- # Build V compiler from source (no Wolfi package available).
50- # V is installed to /opt/vlang so vlib stays co-located with the binary
51- # (V resolves VROOT relative to the real executable path).
52- RUN git clone --depth 1 https://github.com/vlang/v /opt/vlang && \
53- cd /opt/vlang && make && \
54- ln -sf /opt/vlang/v /usr/local/bin/v
55-
56- # Compile V adapter binary, linking against all Zig FFI shared libs.
61+ # Compile Zig adapter binary, linking against all Zig FFI shared libs.
5762RUN LFLAGS="-L/build/ffi/zig/zig-out/lib" && \
5863 for d in /build/cartridges/*/ffi/zig-out/lib; do \
5964 [ -d "$d" ] && LFLAGS="${LFLAGS} -L${d}" ; \
6065 done && \
61- v -cc gcc -cflags "${LFLAGS} -Wl,--allow-multiple-definition -no-pie" \
62- -o /build/adapter/v/boj-server /build/adapter/v/src/
66+ zig build-exe -O ReleaseFast -lc \
67+ -fno-omit-frame-pointer \
68+ -fPIE -pie \
69+ --name boj-server \
70+ --pkg-begin boj_adapter /build/adapter/zig/src \
71+ -I/build/ffi/zig/zig-out/include \
72+ ${LFLAGS} \
73+ -o /build/adapter/zig/boj-server
6374
6475# ============================================================================
6576# Stage 2: Runtime
@@ -90,8 +101,8 @@ RUN addgroup -S appuser && adduser -S appuser -G appuser
90101
91102WORKDIR /app
92103
93- # Copy V adapter binary compiled in Stage 1
94- COPY --from=builder /build/adapter/v /boj-server /app/boj-server
104+ # Copy Zig adapter binary compiled in Stage 1
105+ COPY --from=builder /build/adapter/zig /boj-server /app/boj-server
95106RUN chmod +x /app/boj-server
96107
97108# Copy core FFI libraries from builder stage
0 commit comments