FROM debian:trixie

ARG BUTLER_URL="https://github.com/andreas-jonsson/butler-bin/raw/main/butler-linux-amd64.zip"
#ARG BUTLER_URL="https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default"

RUN apt update \
	&& apt install -y build-essential bash git curl wget python3 python3-requests coffeescript 7zip unzip \
	&& rm -rf /var/lib/apt/lists/*

WORKDIR /opt

# Pre-clone 8088 and V20 test repos for fast CI caching via git sparse-checkout.
# The fetch.py script will pull updates and extract .MOO files at build time.
RUN mkdir -p /opt/testdata-cache && \
	git clone --depth 1 --filter=blob:none --sparse \
		https://codeberg.org/virtualxt/8088 /opt/testdata-cache/8088 && \
	git -C /opt/testdata-cache/8088 sparse-checkout set v2 v2_binary && \
	git clone --depth 1 --filter=blob:none --sparse \
		https://codeberg.org/virtualxt/v20 /opt/testdata-cache/v20 && \
	git -C /opt/testdata-cache/v20 sparse-checkout set v1_native v1_native_binary

RUN curl -L -o butler.zip ${BUTLER_URL} && unzip butler.zip -d /opt/butler && rm butler.zip

RUN git clone https://github.com/emscripten-core/emsdk \
	&& /opt/emsdk/emsdk install 3.1.74 && /opt/emsdk/emsdk activate 3.1.74

# ARM GNU Toolchain (aarch64-none-elf bare-metal for x86_64 Linux)
ARG ARM_TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-elf.tar.xz"
RUN curl -L -o arm-toolchain.tar.xz ${ARM_TOOLCHAIN_URL} \
	&& tar -xf arm-toolchain.tar.xz -C /opt \
	&& rm arm-toolchain.tar.xz

# Circle library for Raspberry Pi bare-metal
RUN git clone https://codeberg.org/virtualxt/circle /opt/circle

WORKDIR /

ENV PATH="/opt/arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-elf/bin:/opt/butler:/opt/emsdk:${PATH}"
