build: replace wasm patch with third_party/qemu submodule

The 7.7k-line qemu-wasm patch was really a fork, so vendor it as a submodule
(pinned at the xteink QEMU fork) and build it directly. Removes the
clone/commit-check/patch/reset machinery, the redundant web-dev/patch targets,
and 0002-qemu-wasm.patch. Editing third_party/qemu now recompiles incrementally
via plain `make web`. Native build keeps 0001-xteink-machine.patch.
This commit is contained in:
2026-07-20 18:44:51 -04:00
parent 1a782eef9e
commit bff6405afc
6 changed files with 31 additions and 7928 deletions
+8 -31
View File
@@ -2,13 +2,12 @@
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SRC="${QEMU_WASM_SRC:-$ROOT/_scratch/qemu-wasm-src}"
# QEMU source is the third_party/qemu submodule (fork with the xteink machine +
# wasm32 backend). Edit it in place; builds compile incrementally, no patching.
SRC="${QEMU_WASM_SRC:-$ROOT/third_party/qemu}"
OUT="${WASM_OUT:-$ROOT/dist/wasm}"
[[ "$SRC" = /* ]] || SRC="$ROOT/$SRC"
[[ "$OUT" = /* ]] || OUT="$ROOT/$OUT"
TAG="esp-develop-9.2.2-20260417"
COMMIT="40edccac415693c5130f91c01d84176ae6008566"
QEMU_WASM_COMMIT="0ef7b4e2814b231705d8371dd7997f5b72e70baf"
IMAGE="xteink-qemu-wasm-build"
JOBS="${JOBS:-$(nproc 2>/dev/null || echo 2)}"
@@ -20,35 +19,13 @@ else
ENGINE=docker
fi
# Dev Mode - Build directly out of an already-patched working tree (e.g. _scratch/qemu-fix-src);
# skip clone/commit-check/patch so edits compile incrementally without the patch round-trip.
if [ -n "${QEMU_WASM_DEV:-}" ]; then
cd "$SRC"
else
if [ ! -d "$SRC/.git" ]; then
git clone --depth 1 --branch "$TAG" https://github.com/espressif/qemu "$SRC"
fi
cd "$SRC"
if [ "$(git rev-parse HEAD)" != "$COMMIT" ]; then
echo "QEMU source must be $COMMIT ($TAG)" >&2
exit 1
fi
# Re-apply Patches On Drift - The source tree is a build artifact of the patches; reset and re-apply whenever a patch is newer than the last apply so `make web` never silently rebuilds stale sources.
STAMP=".xteink-patch-stamp"
if [ ! -f hw/display/xteink_x3_eink.c ] || [ ! -f tcg/wasm32.c ] \
|| [ "$ROOT/qemu/patches/0001-xteink-machine.patch" -nt "$STAMP" ] \
|| [ "$ROOT/qemu/patches/0002-qemu-wasm.patch" -nt "$STAMP" ]; then
git reset --hard "$COMMIT"
git clean -fdx -e build
git apply "$ROOT/qemu/patches/0001-xteink-machine.patch"
git apply --whitespace=nowarn "$ROOT/qemu/patches/0002-qemu-wasm.patch"
touch "$STAMP"
fi
if [ ! -f "$SRC/tcg/wasm32.c" ]; then
echo "third_party/qemu submodule not checked out; run: git submodule update --init" >&2
exit 1
fi
cd "$SRC"
printf 'Building Emscripten environment (qemu-wasm %s)\n' "$QEMU_WASM_COMMIT"
printf 'Building Emscripten environment for %s\n' "$SRC"
"$ENGINE" build -t "$IMAGE" -f "$ROOT/qemu/wasm/Dockerfile" "$ROOT/qemu/wasm"
FLAGS="-O3 -Wno-error=unused-command-line-argument -matomics -mbulk-memory -DNDEBUG -DG_DISABLE_ASSERT -D_GNU_SOURCE -sASYNCIFY=1 -pthread -sPROXY_TO_PTHREAD=1 -sFORCE_FILESYSTEM -sALLOW_TABLE_GROWTH -sINITIAL_MEMORY=64MB -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1GB -sSTACK_SIZE=1048576 -sWASM_BIGINT -sMALLOC=mimalloc -sEXPORT_ES6=1 -sASYNCIFY_IMPORTS=ffi_call_js"