# syntax=docker/dockerfile:1 # WebAssembly build environment (Emscripten), producing openra3.js/.wasm plus the # `index.html` page and `openra3.worker.js` bootstrap. The engine runs on a plain # Web Worker (WebGL2 and WebGPU backends), with lazy on-demand assets. # # The emsdk image ships CMake 3.28, whose experimental `import std` support is # too old for the project, so an upstream CMake is layered on top. FROM emscripten/emsdk:6.0.10 AS dev ENV DEBIAN_FRONTEND=noninteractive ARG APT_MIRROR="" RUN if [ -n "$APT_MIRROR" ]; then \ sed -i -e "s|http://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g" \ -e "s|http://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" \ -e "s|http://ports.ubuntu.com/ubuntu-ports|${APT_MIRROR}|g" \ /etc/apt/sources.list /etc/apt/sources.list.d/*.sources 2>/dev/null || true; \ fi RUN --mount=type=cache,target=/var/lib/apt,sharing=locked \ --mount=type=cache,target=/var/cache/apt,sharing=locked \ for attempt in 1 2 3 4 5; do \ apt-get -o Acquire::Retries=5 update && break; \ echo "apt-get update failed (attempt $attempt), retrying"; \ sleep 5; \ done \ && apt-get -o Acquire::Retries=5 install -y --no-install-recommends \ ca-certificates \ curl \ ninja-build \ && rm -rf /var/lib/apt/lists/* # Upstream CMake, because the emsdk image's 3.28 cannot build the project. ARG CMAKE_VERSION=4.2.3 RUN mkdir -p /opt/cmake \ && curl -fL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz" \ | tar -xz -C /opt/cmake --strip-components=1 ENV PATH="/opt/cmake/bin:${PATH}" # Pre-fetch the emdawnwebgpu port into the image. The WebGPU backend needs # , and CMake's module dependency scanner does not process # `--use-port`, so a warm cache is required before the project is configured. RUN . /emsdk/emsdk_env.sh \ && printf '#include \nint main(){}\n' > /tmp/wgpu_port.cpp \ && em++ -c /tmp/wgpu_port.cpp -o /tmp/wgpu_port.o --use-port=emdawnwebgpu \ && rm -f /tmp/wgpu_port.cpp /tmp/wgpu_port.o WORKDIR /work COPY . . RUN cmake -S . -B build/wasm -G Ninja \ -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/emscripten-wasm.cmake \ -DCMAKE_BUILD_TYPE=Release \ && cmake --build build/wasm -j