# Build Ground
FROM archlinux:latest AS ground-build

RUN pacman-key --init && \
    pacman-key --populate archlinux && \
    pacman -Syu --noconfirm base-devel git

RUN pacman -Syu --noconfirm base-devel git

RUN git clone --depth 1 https://chookspace.com/ground/ground /src/ground

WORKDIR /src/ground
RUN make

# Build Solstice
FROM archlinux:latest AS solstice-build

RUN pacman-key --init && \
    pacman-key --populate archlinux && \
    pacman -Syu --noconfirm base-devel git

RUN pacman -Syu --noconfirm base-devel git uthash

COPY --from=ground-build /src/ground/build/lib/libgroundvm.a ./libs/
COPY --from=ground-build /src/ground/include/     ./libs/include/

RUN git clone --depth 1 https://chookspace.com/solstice/solstice /src/solstice

WORKDIR /src/solstice
RUN make static GROUND_STATIC=/libs/libgroundvm.a GROUND_INCLUDE=/libs/include

# ── Stage 3: Output ────────────────────────────────────────────────
FROM archlinux:latest AS final
COPY --from=solstice-build /src/solstice/solstice /usr/local/bin/solstice
