# Build environment for Scramjet (onlineproxy branch). Everything the build needs, at fixed
# versions, so the same source always gives the same files and nothing has to be installed
# on the machine itself. Used by build.sh in this folder.
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
      ca-certificates curl git build-essential pkg-config libssl-dev xz-utils \
    && rm -rf /var/lib/apt/lists/*

# Rust: the rewriter asks for "nightly"; pinned to the nightly of the base commit's day.
ENV RUSTUP_HOME=/opt/rustup CARGO_HOME=/opt/cargo PATH=/opt/cargo/bin:$PATH
ARG RUST_NIGHTLY=nightly-2026-07-29
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${RUST_NIGHTLY} \
    && rustup component add rust-src --toolchain ${RUST_NIGHTLY} \
    && rustup target add wasm32-unknown-unknown --toolchain ${RUST_NIGHTLY} \
    && ln -s /opt/rustup/toolchains/${RUST_NIGHTLY}-x86_64-unknown-linux-gnu /opt/rustup/toolchains/nightly-x86_64-unknown-linux-gnu

# The exact wasm-bindgen the rewriter's Cargo.lock uses, and wasm-snip from the fork it needs.
RUN cargo +${RUST_NIGHTLY} install wasm-bindgen-cli --version 0.2.105 --locked \
    && cargo +${RUST_NIGHTLY} install --git https://github.com/r58Playz/wasm-snip --locked \
    && rm -rf /opt/cargo/registry /opt/cargo/git

# binaryen (wasm-opt), from its release.
ARG BINARYEN=version_124
RUN curl -sSfL https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN}/binaryen-${BINARYEN}-x86_64-linux.tar.gz \
      | tar -xz -C /opt && ln -s /opt/binaryen-${BINARYEN}/bin/wasm-opt /usr/local/bin/wasm-opt

# Node with pnpm (the version the repository names).
ARG NODE=24.14.1
ENV PATH=/opt/node-v${NODE}-linux-x64/bin:$PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN curl -sSfL https://nodejs.org/dist/v${NODE}/node-v${NODE}-linux-x64.tar.xz | tar -xJ -C /opt \
    && corepack enable && corepack prepare pnpm@10.12.1 --activate && pnpm --version

WORKDIR /src
