feat: track emscripten Docker build infrastructure

Add Dockerfile, build-depends.sh, clone-deps.sh, and .dockerignore
for building a native arm64 emscripten Docker image. Add the
docker-build-emscripten DinD wrapper script.

The ext/ directory (pre-cloned deps, ~413MB) is gitignored.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Mike LiuandClaude Opus 4.6 committed 2026-03-03 21:09:38 +00:00
1 parent 9a3c289c3d
commit ebae3076f4
5 files changed
+212

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
# Exclude .git dirs from deps to reduce context size
ext/*/.git
ext/icu/icu4j
ext/icu/tools
ext/icu/testdata
ext/icu/docs
ext/icu/.github
+42
View File
@@ -0,0 +1,42 @@
FROM fedora:42
# Install build dependencies
RUN dnf update -y && dnf install -y \
autoconf \
automake \
bzip2-devel \
ccache \
cmake \
git \
json-devel \
libicu-devel \
libtool \
libzip-devel \
ninja-build \
pkg-config \
python3 \
zip \
&& dnf clean all
# Install Emscripten SDK
WORKDIR /
RUN git clone https://github.com/emscripten-core/emsdk.git
WORKDIR /emsdk/
RUN ./emsdk install 5.0.0
RUN ./emsdk activate 5.0.0
ENV PATH="/emsdk:/emsdk/upstream/emscripten:/emsdk/node/22.16.0_64bit/bin:${PATH}"
# Copy nlohmann headers where the build expects them
RUN cp -r /usr/include/nlohmann /emsdk/upstream/emscripten/cache/sysroot/include/
# Copy pre-cloned dependency sources and build script
WORKDIR /ext/
COPY ext/ /ext/
COPY build-depends.sh /ext/
RUN bash build-depends.sh
ENV SPEEXDSP_ROOT=/ext/speexdsp
ENV ICU_ROOT=/ext/icu/icu4c/source
ENV LIBZIP_ROOT=/ext/libzip/build
SHELL ["/bin/bash", "-c"]
+54
View File
@@ -0,0 +1,54 @@
#!/bin/bash
set -euo pipefail
START_DIR=/ext
cd $START_DIR
# Sources are expected to be pre-populated via COPY in the Dockerfile.
# Run clone-deps.sh locally first to populate docker/emscripten/ext/.
cd speexdsp
emmake ./autogen.sh
emmake ./configure --enable-shared --disable-neon
emmake make -j$(nproc)
cd $START_DIR
cd icu/icu4c/source
ac_cv_namespace_ok=yes icu_cv_host_frag=mh-linux emmake ./configure \
--enable-release \
--enable-shared \
--disable-icu-config \
--disable-extras \
--disable-icuio \
--disable-layoutex \
--disable-tools \
--disable-tests \
--disable-samples
emmake make -j$(nproc)
cd $START_DIR
cd zlib
mkdir -p build/
cd build/
emcmake cmake ../
emmake make zlib -j$(nproc)
emmake make install
ZLIB_ROOT=$(pwd)
cd $START_DIR
cd libzip
mkdir -p build/
cd build/
emcmake cmake ../ -DZLIB_INCLUDE_DIR="$ZLIB_ROOT" -DZLIB_LIBRARY="$ZLIB_ROOT/libz.a"
emmake make zip -j$(nproc)
emmake make install
cd $START_DIR
cd zstd
mkdir -p build/build/
cd build/build/
emcmake cmake ../cmake/ -DZSTD_BUILD_STATIC=ON -DZSTD_BUILD_SHARED=OFF -DZSTD_BUILD_PROGRAMS=OFF
emmake make -j$(nproc)
emmake make install
cd $START_DIR
+31
View File
@@ -0,0 +1,31 @@
#!/bin/bash
# Pre-clone dependency sources for the Docker build.
# Run this once before building the Docker image.
# Sources are cached in docker/emscripten/ext/ and COPYed into the image.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
EXT_DIR="$SCRIPT_DIR/ext"
mkdir -p "$EXT_DIR"
cd "$EXT_DIR"
clone_if_missing() {
local name="$1"
local url="$2"
local branch="$3"
if [ ! -d "$name" ]; then
echo "Cloning $name ($branch)..."
git clone "$url" --depth 1 --branch "$branch" "$name"
else
echo "Already have $name, skipping"
fi
}
clone_if_missing speexdsp https://gitlab.xiph.org/xiph/speexdsp.git SpeexDSP-1.2.1
clone_if_missing icu https://github.com/unicode-org/icu.git release-77-1
clone_if_missing libzip https://github.com/nih-at/libzip.git v1.11.4
clone_if_missing zlib https://github.com/madler/zlib.git v1.3.1
clone_if_missing zstd https://github.com/facebook/zstd.git v1.5.7
echo "All dependencies cloned to $EXT_DIR"
+78
View File
@@ -0,0 +1,78 @@
#!/bin/bash
# Build OpenRCT2 for Emscripten/WASM using the Docker build image.
#
# Handles Docker-in-Docker (DinD) environments where host bind mounts
# don't work because the Docker daemon doesn't see the container's
# filesystem. Uses a named volume + docker cp as a robust workaround.
#
# Usage: scripts/docker-build-emscripten [--rebuild-image]
#
# Options:
# --rebuild-image Force rebuild the Docker image (otherwise uses cache)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
IMAGE_NAME="openrct2-emscripten-local"
CONTAINER_NAME="orct2-wasm-build"
VOLUME_NAME="orct2-wasm-src"
# --- Parse args ---
REBUILD_IMAGE=false
for arg in "$@"; do
case $arg in
--rebuild-image) REBUILD_IMAGE=true ;;
*) echo "Unknown option: $arg"; exit 1 ;;
esac
done
# --- Build image if needed ---
if [ "$REBUILD_IMAGE" = true ] || ! docker image inspect "$IMAGE_NAME" >/dev/null 2>&1; then
echo "==> Building Docker image ($IMAGE_NAME) for $(uname -m)..."
docker build -t "$IMAGE_NAME" "$REPO_DIR/docker/emscripten/"
else
echo "==> Using cached Docker image ($IMAGE_NAME)"
fi
# --- Clean up any previous run ---
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
docker volume rm "$VOLUME_NAME" 2>/dev/null || true
# --- Create volume and container ---
echo "==> Creating build volume and container..."
docker volume create "$VOLUME_NAME" >/dev/null
docker create --name "$CONTAINER_NAME" \
-v "$VOLUME_NAME":/src \
"$IMAGE_NAME" \
bash -c "cd /src && . scripts/setenv && build-emscripten"
# --- Sync source into volume ---
echo "==> Syncing source into volume (this may take a moment)..."
# Use tar to efficiently copy, respecting .gitignore-like patterns
cd "$REPO_DIR"
# Exclude build artifacts, .git, and large irrelevant dirs
tar cf - \
--exclude='./build' \
--exclude='./build_native' \
--exclude='./.git' \
--exclude='./node_modules' \
--exclude='./.claude' \
. | docker cp - "$CONTAINER_NAME":/src/
# --- Build ---
echo "==> Starting WASM build..."
docker start -a "$CONTAINER_NAME"
# --- Copy output back ---
echo "==> Copying build output..."
mkdir -p "$REPO_DIR/build/www"
docker cp "$CONTAINER_NAME":/src/build/www/. "$REPO_DIR/build/www/"
# --- Clean up ---
echo "==> Cleaning up..."
docker rm -f "$CONTAINER_NAME" >/dev/null
docker volume rm "$VOLUME_NAME" >/dev/null
echo "==> Build complete! Output in build/www/"
echo " Serve with: python3 scripts/serve-emscripten.py"