# y5_compositor — Debian 11 (bullseye) build/run image.
# Installs the build deps, then clones the prepared self-contained source (bind-mounted at
# /repo via image.sh's `-v`) and compiles the winit binary.
#
# NOTE: bullseye (2021) is the oldest target here. Some newer devel libs may be missing from
# its repos (e.g. libdisplay-info-dev landed after bullseye) — apt may fail on those. That's a
# legitimate portability finding; adjust the package list / enable bullseye-backports as needed.
#
# Debian's packaged rustc is far too old for edition 2024 (needs >= 1.85), so rust comes from
# rustup; everything else is from apt.
FROM debian:11 AS deps

ENV DEBIAN_FRONTEND=noninteractive
RUN --mount=type=cache,target=/var/cache/apt \
    --mount=type=cache,target=/var/lib/apt \
    apt-get update && apt-get install -y --no-install-recommends \
        build-essential clang libclang-dev pkg-config git curl ca-certificates \
        protobuf-compiler libprotobuf-dev libpam0g-dev \
        libdisplay-info-dev libinput-dev libseat-dev libxkbcommon-dev libpixman-1-dev \
        libsystemd-dev libudev-dev libwayland-dev wayland-protocols \
        libegl-dev libgles-dev libgl-dev libgbm-dev libglvnd-dev libvulkan-dev libdrm-dev \
        libavcodec-dev libavformat-dev libavutil-dev libavfilter-dev libavdevice-dev \
        libswscale-dev libswresample-dev \
        libdbus-1-dev libpulse-dev \
        foot fonts-dejavu-core

# Rust toolchain (stable, edition-2024-capable) via rustup, installed system-wide.
ENV RUSTUP_HOME=/usr/local/rustup \
    CARGO_HOME=/usr/local/cargo \
    PATH=/usr/local/cargo/bin:$PATH
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
        | sh -s -- -y --no-modify-path --profile minimal --default-toolchain stable

# --- build stage: clone the prepared source + compile winit -----------------------------
FROM deps AS build
ARG PROFILE=debug
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

# /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

RUN BIN="$(environment/build.sh winit ${PROFILE})" \
    && install -Dm755 "$BIN" /usr/local/bin/y5_compositor
