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:
@@ -0,0 +1,4 @@
|
|||||||
|
[submodule "third_party/qemu"]
|
||||||
|
path = third_party/qemu
|
||||||
|
url = git@ssh.gitea.va.reichard.io:evan/qemu-xteink.git
|
||||||
|
branch = main
|
||||||
@@ -5,15 +5,13 @@ FIRMWARE_DIR ?= $(FIRMWARE_REPO)/.pio/build/default
|
|||||||
SD_SRC ?= $(FIRMWARE_REPO)/sdcard
|
SD_SRC ?= $(FIRMWARE_REPO)/sdcard
|
||||||
QEMU_SRC ?= _scratch/qemu-src
|
QEMU_SRC ?= _scratch/qemu-src
|
||||||
QEMU_BIN = $(QEMU_SRC)/build/qemu-system-riscv32
|
QEMU_BIN = $(QEMU_SRC)/build/qemu-system-riscv32
|
||||||
QEMU_WASM_SRC ?= _scratch/qemu-wasm-src
|
# QEMU source for the wasm build is the third_party/qemu submodule. Edit it in
|
||||||
# Working tree for the fast dev loop: edit here, `make web-dev` compiles it incrementally.
|
# place; `make web` recompiles only what changed, no patch round-trip.
|
||||||
DEV_SRC ?= _scratch/qemu-fix-src
|
QEMU_WASM_SRC ?= third_party/qemu
|
||||||
# Commit the 0002 patch is diffed against when running `make patch`.
|
|
||||||
PATCH_BASE ?= 610f8c69bc91dcb4ba81de1b7d2e74cc2adfb31e
|
|
||||||
WASM_OUT ?= dist/wasm
|
WASM_OUT ?= dist/wasm
|
||||||
VARIANT ?= x3
|
VARIANT ?= x3
|
||||||
|
|
||||||
.PHONY: firmware sdimage qemu qemu-wasm qemu-wasm-dev web web-dev web-test patch run run-upstream chip clean
|
.PHONY: firmware sdimage qemu qemu-wasm web web-test run run-upstream chip clean
|
||||||
|
|
||||||
firmware:
|
firmware:
|
||||||
esptool --chip esp32c3 merge-bin -o flash.bin \
|
esptool --chip esp32c3 merge-bin -o flash.bin \
|
||||||
@@ -33,23 +31,11 @@ qemu:
|
|||||||
qemu-wasm:
|
qemu-wasm:
|
||||||
QEMU_WASM_SRC=$(QEMU_WASM_SRC) WASM_OUT=$(WASM_OUT) scripts/build-qemu-wasm.sh
|
QEMU_WASM_SRC=$(QEMU_WASM_SRC) WASM_OUT=$(WASM_OUT) scripts/build-qemu-wasm.sh
|
||||||
|
|
||||||
# Incremental build straight from $(DEV_SRC); no patch reset, so edits compile fast.
|
|
||||||
qemu-wasm-dev:
|
|
||||||
QEMU_WASM_DEV=1 QEMU_WASM_SRC=$(DEV_SRC) WASM_OUT=$(WASM_OUT) scripts/build-qemu-wasm.sh
|
|
||||||
|
|
||||||
# Regenerate the wasm patch from $(DEV_SRC) once the dev tree is where you want it.
|
|
||||||
patch:
|
|
||||||
cd $(DEV_SRC) && git diff --binary $(PATCH_BASE) > $(CURDIR)/qemu/patches/0002-qemu-wasm.patch
|
|
||||||
|
|
||||||
# Serve over HTTPS by default so headless/LAN access is cross-origin isolated. Override with WEB_TLS=.
|
# Serve over HTTPS by default so headless/LAN access is cross-origin isolated. Override with WEB_TLS=.
|
||||||
WEB_TLS ?= --tls
|
WEB_TLS ?= --tls
|
||||||
web: qemu-wasm
|
web: qemu-wasm
|
||||||
python3 scripts/serve-web.py $(WEB_TLS)
|
python3 scripts/serve-web.py $(WEB_TLS)
|
||||||
|
|
||||||
# Fast iteration: incremental compile from $(DEV_SRC), then serve. Run `make patch` before committing.
|
|
||||||
web-dev: qemu-wasm-dev
|
|
||||||
python3 scripts/serve-web.py $(WEB_TLS)
|
|
||||||
|
|
||||||
web-test:
|
web-test:
|
||||||
node scripts/test-web.mjs
|
node scripts/test-web.mjs
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,15 @@ Point at a firmware build with `make firmware FIRMWARE_DIR=/path/to/.pio/build/g
|
|||||||
|
|
||||||
## WebAssembly build
|
## WebAssembly build
|
||||||
|
|
||||||
Podman or Docker is required. The build is limited to `riscv32-softmmu` and the
|
Podman or Docker is required. The QEMU source is the `third_party/qemu`
|
||||||
X3/X4 device graph; networking, audio, virtfs, tools, docs, and unrelated boards
|
submodule, so initialize it first:
|
||||||
are disabled.
|
|
||||||
|
```sh
|
||||||
|
git submodule update --init third_party/qemu
|
||||||
|
```
|
||||||
|
|
||||||
|
The build is limited to `riscv32-softmmu` and the X3/X4 device graph;
|
||||||
|
networking, audio, virtfs, tools, docs, and unrelated boards are disabled.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make qemu-wasm
|
make qemu-wasm
|
||||||
@@ -67,9 +73,11 @@ browser JS heap where supported. X4 remains a white display stub.
|
|||||||
and its device models (I²C fingerprints, ADC, GPIO, SPI2, X3 UC8253, X4 panel
|
and its device models (I²C fingerprints, ADC, GPIO, SPI2, X3 UC8253, X4 panel
|
||||||
stub, SD-over-SPI fix), applied onto the pinned espressif/qemu commit by
|
stub, SD-over-SPI fix), applied onto the pinned espressif/qemu commit by
|
||||||
`scripts/build-qemu.sh`.
|
`scripts/build-qemu.sh`.
|
||||||
- `qemu/patches/0002-qemu-wasm.patch` and `qemu/wasm/Dockerfile` — the pinned
|
- `third_party/qemu` — submodule of the [xteink QEMU fork](git@ssh.gitea.va.reichard.io:evan/qemu-xteink.git)
|
||||||
qemu-wasm host backend port and minimal Emscripten dependency environment,
|
(espressif/qemu + the machine models + the wasm32 TCG backend), built for the
|
||||||
built by `scripts/build-qemu-wasm.sh`.
|
browser by `scripts/build-qemu-wasm.sh`. Edit it in place; `make web`
|
||||||
|
recompiles incrementally. `qemu/wasm/Dockerfile` is the pinned Emscripten
|
||||||
|
dependency environment.
|
||||||
- `flake.nix` — the espressif-qemu *release* binary as the fast generic baseline
|
- `flake.nix` — the espressif-qemu *release* binary as the fast generic baseline
|
||||||
(`nix run .#run-upstream -- flash.bin`), plus a devShell with QEMU's full build
|
(`nix run .#run-upstream -- flash.bin`), plus a devShell with QEMU's full build
|
||||||
environment. `Makefile` — `qemu`, `firmware`, `sdimage`, `run`, `chip`.
|
environment. `Makefile` — `qemu`, `firmware`, `sdimage`, `run`, `chip`.
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,13 +2,12 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
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}"
|
OUT="${WASM_OUT:-$ROOT/dist/wasm}"
|
||||||
[[ "$SRC" = /* ]] || SRC="$ROOT/$SRC"
|
[[ "$SRC" = /* ]] || SRC="$ROOT/$SRC"
|
||||||
[[ "$OUT" = /* ]] || OUT="$ROOT/$OUT"
|
[[ "$OUT" = /* ]] || OUT="$ROOT/$OUT"
|
||||||
TAG="esp-develop-9.2.2-20260417"
|
|
||||||
COMMIT="40edccac415693c5130f91c01d84176ae6008566"
|
|
||||||
QEMU_WASM_COMMIT="0ef7b4e2814b231705d8371dd7997f5b72e70baf"
|
|
||||||
IMAGE="xteink-qemu-wasm-build"
|
IMAGE="xteink-qemu-wasm-build"
|
||||||
JOBS="${JOBS:-$(nproc 2>/dev/null || echo 2)}"
|
JOBS="${JOBS:-$(nproc 2>/dev/null || echo 2)}"
|
||||||
|
|
||||||
@@ -20,35 +19,13 @@ else
|
|||||||
ENGINE=docker
|
ENGINE=docker
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Dev Mode - Build directly out of an already-patched working tree (e.g. _scratch/qemu-fix-src);
|
if [ ! -f "$SRC/tcg/wasm32.c" ]; then
|
||||||
# skip clone/commit-check/patch so edits compile incrementally without the patch round-trip.
|
echo "third_party/qemu submodule not checked out; run: git submodule update --init" >&2
|
||||||
if [ -n "${QEMU_WASM_DEV:-}" ]; then
|
exit 1
|
||||||
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
|
|
||||||
fi
|
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"
|
"$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"
|
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"
|
||||||
|
|||||||
+1
Submodule third_party/qemu added at 13b9231f6e
Reference in New Issue
Block a user