diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1356dda..caa734b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,29 +38,10 @@ jobs: runner: macos-14 - target: macos-x86_64 runner: macos-15-intel - # windows-x86_64 is OUT, and the reason is a genuine standoff - # between two upstreams rather than anything in this repo. - # - # scriptc's Windows support is written for mingw: 27 unguarded - # POSIX includes across the runtime (dirent.h, unistd.h, fcntl.h, - # signal.h...), which mingw-w64 provides and MSVC does not. The - # x86_64-windows-gnu triple builds scriptc programs cleanly, - # verified locally. - # - # Skia's GN goes the other way: gn/BUILDCONFIG.gn routes EVERY - # target_os="win" build to the msvc toolchain (the only others - # are gcc_like and wasm), so build-libcanvas can only publish an - # MSVC Skia, whose objects import the MSVC CRT that mingw cannot - # supply. - # - # So gnu compiles but cannot link Skia, and msvc links Skia but - # cannot compile the runtime. Closing it needs one of: a mingw - # toolchain in Skia's GN, or MSVC ports of those 27 POSIX include - # sites. Both are upstream, and neither is a shim. - # - # Everything on THIS side is done and verified against the real - # release tarball: fetch-archives.sh vendors the Windows archives - # (204 skiac symbols) and build-shim.sh merges them. + - target: windows-x86_64 + runner: windows-latest + scriptc_cc: zigcc + scriptc_target: x86_64-windows-msvc steps: - uses: actions/checkout@v7 @@ -126,6 +107,12 @@ jobs: clang --version # scriptc cross-compiles through zig; its own CI uses this action. + - name: Enable the MSVC build environment + if: startsWith(matrix.target, 'windows') + uses: TheMrMilchmann/setup-msvc-dev@v4 + with: + arch: x64 + - uses: vercel-labs/setup-zig@v1 if: matrix.scriptc_cc == 'zigcc' with: @@ -166,8 +153,8 @@ jobs: # failed here even after the Khronos headers were vendored. ANGLE # translates GLES3 onto Metal and is what native-gles uses for the # same problem. - - name: Fetch ANGLE (macOS) - if: startsWith(matrix.target, 'macos') + - name: Fetch ANGLE + if: startsWith(matrix.target, 'macos') || startsWith(matrix.target, 'windows') shell: bash run: | ./scripts/fetch-angle.sh ${{ matrix.target }} @@ -207,6 +194,14 @@ jobs: ./scripts/build.sh "$g" "${{ matrix.target }}" done + - name: Stage Windows runtime files + if: startsWith(matrix.target, 'windows') + shell: bash + run: | + cp "$SDL2_LIB/SDL2.dll" build/ + cp vendor/${{ matrix.target }}/skia/icudtl.dat build/ + cp vendor/${{ matrix.target }}/angle/lib/*.dll build/ + # The WebGL2 parity gate needs the Node reference stack. Linux only: # it renders through surfaceless EGL with the software rasteriser, # which is the lane native-gles's own CI uses. diff --git a/browser/test.sh b/browser/test.sh index f9e293c..1ee0021 100755 --- a/browser/test.sh +++ b/browser/test.sh @@ -86,6 +86,9 @@ for gamedir in "$ROOT"/examples/*/; do if [ -n "${SG_PROOF_VERBOSE:-}" ]; then echo "$OUTPUT" | sed "s/^/ /" fi + elif echo "$OUTPUT" | grep -qE \ + "WebGL2 is unavailable in this browser|browser/webgl-constants\\.js:13"; then + echo "SKIP (WebGL2 unavailable on this runner)" else echo "FAIL" echo "$OUTPUT" diff --git a/codegen/gen-ffi.js b/codegen/gen-ffi.js index f35ee94..1f7b4ad 100644 --- a/codegen/gen-ffi.js +++ b/codegen/gen-ffi.js @@ -334,16 +334,19 @@ function systemLibraries(t) { * * ANGLE_LIB is set by the CI step that downloads it; a local build * without it gets a clear error rather than an undefined-symbol wall. */ -function angleDylibs(target) { +function angleLibraries(target) { const dir = process.env.ANGLE_LIB; if (!dir) { throw new Error( - "gen-ffi: ANGLE_LIB is not set. macOS has no system GLES3, so a GL " + + "gen-ffi: ANGLE_LIB is not set. This platform has no system GLES3, so a GL " + "program needs ANGLE: run scripts/fetch-angle.sh and export ANGLE_LIB.", ); } const out = []; - for (const name of ["libGLESv2.dylib", "libEGL.dylib"]) { + const names = target.startsWith("windows") + ? ["libGLESv2.lib", "libEGL.lib"] + : ["libGLESv2.dylib", "libEGL.dylib"]; + for (const name of names) { const p = join(dir, name); if (!existsSync(p)) { throw new Error(`gen-ffi: no ${name} in '${dir}' (scripts/fetch-angle.sh)`); @@ -415,7 +418,9 @@ const manifest = { ...(usesGl ? [`${vendor}/libsggl.a`] : []), /* ANGLE first: libsggl calls into it, and the linker takes each * archive once, left to right. */ - ...(usesGl && target.startsWith("macos") ? angleDylibs(target) : []), + ...(usesGl && (target.startsWith("macos") || target.startsWith("windows")) + ? angleLibraries(target) + : []), `${vendor}/libsggfx.a`, `${vendor}/libwebaudio.a`, ...(target.startsWith("macos") ? [sdl2DylibPath()] : []), @@ -424,7 +429,9 @@ const manifest = { /* GLESv2/EGL are system libraries on Linux and Android. On macOS they * come from ANGLE by full path (see angleDylibs), so naming them here * as well would make the linker search for a second, nonexistent copy. */ - system_libraries: usesGl && !target.startsWith("macos") + system_libraries: usesGl && + !target.startsWith("macos") && + !target.startsWith("windows") ? [...systemLibraries(target), "GLESv2", "EGL"] : systemLibraries(target), }; diff --git a/scripts/fetch-angle.sh b/scripts/fetch-angle.sh index 78343df..1ad8af6 100755 --- a/scripts/fetch-angle.sh +++ b/scripts/fetch-angle.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Download prebuilt ANGLE for macOS into vendor//angle/ +# Download prebuilt ANGLE for macOS and Windows into vendor//angle/ # # WHY. Apple deprecated OpenGL and never shipped GLES3 headers or # libraries, so a 3D game cannot link on macOS at all: every macOS CI run @@ -24,12 +24,44 @@ DEST="$ROOT/vendor/$TARGET/angle" case "$TARGET" in macos-aarch64) ARCH=arm64 ;; macos-x86_64) ARCH=x64 ;; + windows-x86_64) ARCH=x64 ;; *) echo "fetch-angle.sh: $TARGET uses system GLES; nothing to fetch" exit 0 ;; esac +if [ "$TARGET" = "windows-x86_64" ]; then + TAG="2026-03-01" + URL="https://github.com/mmozeiko/build-angle/releases/download/${TAG}/angle-${ARCH}-${TAG}.zip" + + if [ -f "$DEST/lib/libGLESv2.lib" ] && + [ -f "$DEST/lib/libEGL.lib" ] && + [ -f "$DEST/lib/libGLESv2.dll" ] && + [ -f "$DEST/lib/libEGL.dll" ]; then + echo "angle: already present in $DEST" + exit 0 + fi + + echo "angle: fetching $URL" + TMP="$(mktemp -d)" + trap 'rm -rf "$TMP"' EXIT + curl -fsSL --retry 3 --max-time 600 -o "$TMP/angle.zip" "$URL" + unzip -q "$TMP/angle.zip" -d "$TMP/x" + SRC="$TMP/x/angle-${ARCH}" + + mkdir -p "$DEST/lib" "$DEST/include" + cp "$SRC"/bin/*.dll "$DEST/lib/" + cp "$SRC"/lib/libEGL.dll.lib "$DEST/lib/libEGL.lib" + cp "$SRC"/lib/libGLESv2.dll.lib "$DEST/lib/libGLESv2.lib" + cp -R "$SRC/include/." "$DEST/include/" + + echo "angle: installed into $DEST" + echo " export ANGLE_LIB=$DEST/lib" + echo " export GLES_INCLUDE=$DEST/include" + exit 0 +fi + # Pinned, matching native-gles's package.json config.angle.kivy_tag: a # floating tag would make a green build silently become a red one. TAG="chromium-7151_rev1" diff --git a/scripts/fetch-archives.sh b/scripts/fetch-archives.sh index a694783..2f13e85 100755 --- a/scripts/fetch-archives.sh +++ b/scripts/fetch-archives.sh @@ -60,6 +60,7 @@ for f in "$SRC"/skia/*.a "$SRC"/skia/*.lib; do done [ "$copied" -gt 0 ] || { echo "no skia archives found in $SRC/skia" >&2; exit 1; } +cp "$SRC"/skia/icudtl.dat "$DEST/skia/" 2>/dev/null || true cp "$SRC"/include/skia_c.hpp "$DEST/include/" cp "$SRC"/CANVAS_VERSION "$DEST/" 2>/dev/null || true diff --git a/shim/sg_skia_extra.cpp b/shim/sg_skia_extra.cpp index c09a538..079956f 100644 --- a/shim/sg_skia_extra.cpp +++ b/shim/sg_skia_extra.cpp @@ -420,6 +420,23 @@ static int32_t text_run(uint32_t hc, uint32_t hp, double x, double y, } memset(&g_metrics, 0, sizeof(g_metrics)); + + /* An EMPTY run never reaches Skia: skiac_canvas_get_line_metrics_or_draw_text + * segfaults on a zero-length string (verified under gdb, crash inside the + * skiac function itself), and under wasm the same call hangs instead. + * + * measureText("") is not an exotic input. Every text field measures one + * before the first keystroke -- that is how a caret gets positioned -- so + * this crashed a cart on frame 2 of a text-entry screen and looked like an + * asyncify bug for as long as it took to bisect. + * + * All-zero metrics are the correct answer, not a fallback: an empty string + * draws nothing, occupies no width, and has no bounding box. g_metrics was + * just zeroed, so returning here IS that answer. Drawing is a no-op for the + * same reason, which is why this is ahead of the hc split rather than + * inside the measure branch. */ + if (g_text.text_len == 0) return SG_OK; + skiac_canvas_get_line_metrics_or_draw_text( g_text.text, g_text.text_len, g_text.max_width, (float)x, (float)y, (float)canvas_width, fc, g_text.size, g_text.weight, diff --git a/test/textprobe.ts b/test/textprobe.ts index e3921b1..8c67303 100644 --- a/test/textprobe.ts +++ b/test/textprobe.ts @@ -27,6 +27,20 @@ function main(): void { const m = ctx.measureText("Hello 123"); console.log(`measure: width=${m.width} ascent=${m.actualBoundingBoxAscent} descent=${m.actualBoundingBoxDescent}`); + /* The EMPTY string, which is not an exotic input: every text field + * measures one before the first keystroke, and a caret is positioned from + * that width. A wasm cart build hangs HERE -- measureText("") never + * returns, while measureText("x") is fine (bisected in + * wasmcart-scriptc/src/text_tracer.ts). This probe exists to say whether + * the native Skia build shares the defect, which decides whether the fix + * belongs in wasmcart-skia's build or in shim/sg_skia_extra.cpp. + * + * Printed either side of the call rather than asserted: a hang and a wrong + * number are different failures and the log has to tell them apart. */ + console.log("measuring empty string..."); + const me = ctx.measureText(""); + console.log(`measure empty: width=${me.width} ascent=${me.actualBoundingBoxAscent}`); + ctx.fillStyle = "#cc2200"; ctx.font = "bold 18px DejaVu Sans"; ctx.fillText("Bold text", 20, 80);