Build native QEMU from the third_party/qemu submodule

Native and wasm now share one source tree, so the xteink machine and SD
fixes never diverge. scripts/build-qemu.sh configures a dedicated
build-native/ dir (ucontext coroutine backend; the fork defaults to the
wasm fiber backend) that never clobbers the Emscripten build/ config.
Retires the separate _scratch/qemu-src patch-based native build.
This commit is contained in:
2026-07-21 08:34:57 -04:00
parent b22934fe0d
commit b959776068
3 changed files with 30 additions and 35 deletions
+5 -4
View File
@@ -3,10 +3,11 @@
FIRMWARE_REPO ?= ../crosspoint-reader FIRMWARE_REPO ?= ../crosspoint-reader
FIRMWARE_DIR ?= $(FIRMWARE_REPO)/.pio/build/default FIRMWARE_DIR ?= $(FIRMWARE_REPO)/.pio/build/default
SD_SRC ?= $(FIRMWARE_REPO)/sdcard SD_SRC ?= $(FIRMWARE_REPO)/sdcard
QEMU_SRC ?= _scratch/qemu-src # Native and wasm builds share the third_party/qemu submodule; edit it in place
QEMU_BIN = $(QEMU_SRC)/build/qemu-system-riscv32 # and both recompile incrementally. Native output lives in build-native so it
# QEMU source for the wasm build is the third_party/qemu submodule. Edit it in # never clobbers the Emscripten build/ config.
# place; `make web` recompiles only what changed, no patch round-trip. QEMU_SRC ?= third_party/qemu
QEMU_BIN = $(QEMU_SRC)/build-native/qemu-system-riscv32
QEMU_WASM_SRC ?= third_party/qemu QEMU_WASM_SRC ?= third_party/qemu
WASM_OUT ?= dist/wasm WASM_OUT ?= dist/wasm
VARIANT ?= x3 VARIANT ?= x3
+24 -30
View File
@@ -2,38 +2,32 @@
set -euo pipefail set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)" ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SRC="${QEMU_SRC:-$ROOT/_scratch/qemu-src}" # Native build shares the third_party/qemu submodule with the wasm build so the
TAG="esp-develop-9.2.2-20260417" # xteink machine and device fixes never diverge. A dedicated build-native dir
COMMIT="40edccac415693c5130f91c01d84176ae6008566" # keeps the native meson config from clobbering the Emscripten build/ config.
PATCH="$ROOT/qemu/patches/0001-xteink-machine.patch" SRC="${QEMU_SRC:-$ROOT/third_party/qemu}"
JOBS="${JOBS:-2}" [[ "$SRC" = /* ]] || SRC="$ROOT/$SRC"
BUILD="$SRC/build-native"
JOBS="${JOBS:-$(nproc 2>/dev/null || echo 2)}"
if [ ! -d "$SRC/.git" ]; then if [ ! -f "$SRC/tcg/wasm32.c" ]; then
git clone --depth 1 --branch "$TAG" https://github.com/espressif/qemu "$SRC" echo "third_party/qemu submodule not checked out; run: git submodule update --init" >&2
exit 1
fi fi
cd "$SRC" if [ ! -f "$BUILD/build.ninja" ]; then
if [ "$(git rev-parse HEAD)" != "$COMMIT" ]; then mkdir -p "$BUILD"
echo "QEMU source must be $COMMIT ($TAG)" >&2 cd "$BUILD"
exit 1 "$SRC/configure" \
--target-list=riscv32-softmmu \
--with-devices-riscv32=xteink \
--with-coroutine=ucontext \
--enable-gcrypt \
--enable-slirp \
--disable-werror \
--disable-docs \
--disable-tools
fi fi
if git apply --check "$PATCH" 2>/dev/null; then ninja -C "$BUILD" -j"$JOBS" qemu-system-riscv32
git apply "$PATCH" printf '%s\n' "$BUILD/qemu-system-riscv32"
elif ! git apply --reverse --check "$PATCH" 2>/dev/null; then
echo "QEMU source has changes that conflict with $PATCH" >&2
exit 1
fi
if [ ! -f build/build.ninja ]; then
./configure \
--target-list=riscv32-softmmu \
--enable-gcrypt \
--enable-slirp \
--disable-werror \
--disable-docs \
--disable-tools
fi
ninja -C build -j"$JOBS" qemu-system-riscv32
printf '%s\n' "$SRC/build/qemu-system-riscv32"