# y5_compositor — Arch Linux build/run image.
# Installs the build deps, clones the committed tree from the local git repo (bind-mounted
# at /repo — no COPY of the live workspace), and compiles the winit binary.
# Arch is rolling, so its packaged rust is current enough for edition 2024. The base image is
# pinned to a dated snapshot (no :latest), but `pacman -Syu` below still syncs the CURRENT
# packages from the mirror — Arch can't really be version-frozen. Bump this tag periodically;
# Arch prunes old dated tags, so a stale pin will eventually fail to pull.
# NOTE: the official archlinux image is x86_64-only (no arm64) — this distro has no aarch64 leg.
FROM archlinux:base-20260628.0.549485 AS deps

RUN --mount=type=cache,target=/var/cache/pacman/pkg \
    pacman -Syu --noconfirm --needed \
        base-devel git clang pkgconf protobuf rust pam \
        libdisplay-info libinput seatd libxkbcommon pixman systemd \
        wayland wayland-protocols \
        mesa libglvnd vulkan-icd-loader ffmpeg \
        dbus libpulse \
        nodejs npm \
        webkit2gtk-4.1 libsoup3 gtk3 librsvg libayatana-appindicator \
        libxcb xcb-util-cursor \
        foot ttf-dejavu

# --- build stage: clone the local repo + compile winit ----------------------------------
FROM deps AS build
ARG PROFILE=debug
# BUNDLE=1 -> build the full install bundle (every shipped component) via prepare.sh, stashed at
# /out (package.tar.gz + SHA256SUMS) — the multiarch-publish CD path. Unset (default) -> the
# dev-loop path: just the nested winit binary at /usr/local/bin/y5_compositor.
# NOTE (Arch): the Tauri devtool pulls libappindicator-sys (via tray-icon, a DEFAULT tauri
# feature — the app itself declares no tray), which links appindicator at build time. The old
# libappindicator-gtk3 is AUR-only, but the official `libayatana-appindicator` (extra repo,
# installed above) ships ayatana-appindicator3-0.1.pc which satisfies the probe — no AUR needed.
ARG BUNDLE=
# Optional release-number stamp written to repo-root VERSION before building so the compositor
# bakes it in at compile time (parity with docs.yml). Empty -> committed VERSION.
ARG VERSION=
WORKDIR /working.directory
# Compile into the host-mounted cache (image.sh: -v <.cache>/<distro>:/y5-target) so a changed
# clone rebuilds incrementally — the compiled dependency graph persists between builds.
ENV Y5_TARGET_DIR=/y5-target
# Skip the workspace lint here: node is present (for the devtool build) so build.sh would run it,
# but ci.yml lints authoritatively — a packaged-node hiccup must not fail a binary build.
ENV Y5_SKIP_LINT=1

# /repo is bind-mounted at build time from the prepared self-contained clone
# (image.sh passes `-v <DIST_SRC>:/repo:ro`). Clone it into the image (offline; no network).
RUN git clone /repo /working.directory

# Stamp the release number (when provided) so the compositor bakes it in at compile time.
RUN if [ -n "$VERSION" ]; then printf '%s\n' "$VERSION" > VERSION; fi

# Two build modes (see BUNDLE): the full install bundle (prepare.sh builds compositor, devtool,
# polkit, MX daemon, xwayland, settings, installer), or the dev-loop winit binary for run.sh.
RUN if [ -n "$BUNDLE" ]; then \
        compositor.installer/prepare.sh --out=/out; \
    else \
        BIN="$(environment/build.sh winit ${PROFILE})" \
        && install -Dm755 "$BIN" /usr/local/bin/y5_compositor; \
    fi
