From 7cdd5bb85641eebfcfa9be2097b0d8300acb146d Mon Sep 17 00:00:00 2001 From: Himanshu Kapoor Date: Sun, 22 Nov 2026 21:37:15 +0100 Subject: [PATCH 1/2] SDL and FreeType/HarfBuzz build themselves the first time a checkout needs them build-shell.sh and check-android.sh stopped with 'run Scripts/build-sdl.sh first' and 'run Vendor/build.sh android first' whenever the gitignored Vendor/ was empty, which is every fresh clone and worktree. They now build what's missing for the ABI asked for (ensure_sdl, ensure_text in config.sh), and build-shell.sh re-stages SDL into a cleaned App. Vendor/build.sh takes a single ABI, so an on-demand build compiles only that one. --- README.md | 17 +++++++++++------ Scripts/build-shell.sh | 17 ++++++----------- Scripts/check-android.sh | 6 +++--- Scripts/config.sh | 27 +++++++++++++++++++++++++++ Vendor/build.sh | 6 +++++- 5 files changed, 52 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b761768a..5d9250bc 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,7 @@ You'll need a Mac (the host tests compare against Apple's frameworks) and: git clone https://github.com/fleon/spritekit-android.git cd spritekit-android swift test # host tests: no device needed -Vendor/build.sh android # FreeType and HarfBuzz for Android -Scripts/check-android.sh arm64-v8a # cross-compiles the runtime +Scripts/check-android.sh arm64-v8a # cross-compiles the runtime (building SDL, FreeType and HarfBuzz the first time) ``` ### Bring your game to Android @@ -92,10 +91,10 @@ Scripts/check-android.sh arm64-v8a # cross-compiles the runtime 3. Make a Swift package at `/Android/Game` that links your game's `Source/` folder, adds a controller adopting `GameHost`, and exports `SDL_main`. -4. Build SDL and your game's shell library, then the app: +4. Build your game's shell library (the first build in a checkout builds + SDL, FreeType and HarfBuzz for it), then the app: ```bash - Scripts/build-sdl.sh arm64-v8a Scripts/build-shell.sh --debug arm64-v8a (cd ../App && ./gradlew installDebug) ``` @@ -859,14 +858,20 @@ The scripts find the game from the runtime's parent directory, or from (default `App/`), in `Scripts/config.sh`. ```bash -Vendor/build.sh android # FreeType + HarfBuzz, both ABIs -Scripts/build-sdl.sh arm64-v8a # SDL 3.4.20, staged into the game's App Scripts/build-shell.sh --debug arm64-v8a # the game's AndroidShell library, staged +Vendor/build.sh android # FreeType + HarfBuzz, both ABIs (or one: arm64-v8a, x86_64) +Scripts/build-sdl.sh arm64-v8a # SDL 3.4.20, staged into the game's App Scripts/check-android.sh arm64-v8a # this runtime alone, cross-compiled Scripts/art.sh # the game's asset catalogs, packed (below) swift test # host tests, on a Mac ``` +`Vendor/` is gitignored, so a fresh clone or worktree has no SDL and no +text stack: `build-shell.sh` and `check-android.sh` build them for the ABI +they're asked for the first time it's missing (`ensure_sdl` and +`ensure_text` in `config.sh`), and `build-shell.sh` also re-stages SDL into +a cleaned App. `Vendor/build.sh` and `build-sdl.sh` rebuild them by hand. + `build-shell.sh --debug` is for every check; an optimised build (no flag) is for measuring frame times, and `--store` for a store upload (no `DEBUG`, and symbols kept for the bundle's native debug metadata). `Scripts/launch.js` diff --git a/Scripts/build-shell.sh b/Scripts/build-shell.sh index 764ad0f4..e23c217a 100755 --- a/Scripts/build-shell.sh +++ b/Scripts/build-shell.sh @@ -5,9 +5,10 @@ # config.sh and stage it, with exactly the runtime libraries it needs, into # the game's Gradle project's jniLibs. # -# Needs Scripts/build-sdl.sh to have run first: the shell compiles against -# SDL's headers and links its .so, and Vendor/build.sh android, because the -# renderer links the text stack for the glyph atlas. +# The shell compiles against SDL's headers and links its .so, and the +# renderer links the text stack (FreeType, HarfBuzz) for the glyph atlas: a +# checkout without them builds them first (Scripts/build-sdl.sh, +# Vendor/build.sh), for just the ABIs asked for. # # Scripts/build-shell.sh --debug # both ABIs, unoptimised: checks, emulator runs, pre-merge # Scripts/build-shell.sh # both ABIs, optimised, with DEBUG: frame-time measurements @@ -48,20 +49,14 @@ done for abi in "${targets[@]}"; do triple="$(swift_triple "$abi")" prefix="$VENDOR_DIR/sdl3/$abi" - if [ ! -d "$prefix/include" ]; then - echo "no SDL for $abi — run Scripts/build-sdl.sh first" >&2 - exit 1 - fi + ensure_sdl "$abi" # FreeType and HarfBuzz, found through pkg-config exactly as Text/ finds # them. Without this the shell fails to resolve CTextShaping and # says so in a way that reads like a missing module rather than a missing # build step. text_prefix="$VENDOR_DIR/out/$(vendor_triple "$abi")" - if [ ! -d "$text_prefix/lib/pkgconfig" ]; then - echo "no FreeType/HarfBuzz for $abi — run Vendor/build.sh android first" >&2 - exit 1 - fi + ensure_text "$abi" export PKG_CONFIG_PATH="$text_prefix/lib/pkgconfig" echo "==> building AndroidShell for $abi ($triple, $CONFIG$([ "$DEBUG_DEFINE" = 1 ] && [ "$CONFIG" = release ] && echo ", DEBUG"))" diff --git a/Scripts/check-android.sh b/Scripts/check-android.sh index b3ee9942..cc2b265e 100755 --- a/Scripts/check-android.sh +++ b/Scripts/check-android.sh @@ -8,7 +8,7 @@ # Scripts/check-android.sh # arm64-v8a # Scripts/check-android.sh x86_64 # -# Needs Vendor/build.sh android and Scripts/build-sdl.sh for the ABI first. +# Builds SDL and FreeType/HarfBuzz for the ABI first if the checkout has none. . "$(dirname "$0")/config.sh" require_ndk @@ -18,8 +18,8 @@ abi="${1:-arm64-v8a}" triple="$(swift_triple "$abi")" sdl="$VENDOR_DIR/sdl3/$abi" text="$VENDOR_DIR/out/$(vendor_triple "$abi")" -[ -d "$sdl/include" ] || { echo "no SDL for $abi — run Scripts/build-sdl.sh $abi first" >&2; exit 1; } -[ -d "$text/lib/pkgconfig" ] || { echo "no FreeType/HarfBuzz for $abi — run Vendor/build.sh android first" >&2; exit 1; } +ensure_sdl "$abi" --unstaged +ensure_text "$abi" export PKG_CONFIG_PATH="$text/lib/pkgconfig" for package in "$RUNTIME_DIR" "$RUNTIME_DIR/Modules" "$RUNTIME_DIR/Shell" "$RUNTIME_DIR/Platform"; do diff --git a/Scripts/config.sh b/Scripts/config.sh index ba3d5c1b..ed949704 100644 --- a/Scripts/config.sh +++ b/Scripts/config.sh @@ -56,6 +56,33 @@ swift_triple() { esac } +# SDL and the text stack (FreeType, HarfBuzz) for an ABI, built the first +# time a checkout needs them: both live in the gitignored Vendor/, so every +# fresh clone and worktree starts without them. The builds' output goes to +# stderr, so a script's stdout stays its own. +# For a game's build, SDL also counts as missing when it isn't staged into +# the game's jniLibs (a cleaned App), which build-sdl.sh redoes +# incrementally; `--unstaged` (the runtime's own checks, with no game) asks +# for the build alone. +ensure_sdl() { # abi [--unstaged] + local abi="$1" + if [ -d "$VENDOR_DIR/sdl3/$abi/include" ]; then + [ "${2:-}" = --unstaged ] || [ -f "$JNI_LIBS/$abi/libSDL3.so" ] && return 0 + fi + echo "==> no SDL for $abi in this checkout or the game: building it (Scripts/build-sdl.sh $abi)" >&2 + "$RUNTIME_DIR/Scripts/build-sdl.sh" "$abi" >&2 + [ -d "$VENDOR_DIR/sdl3/$abi/include" ] || { echo "building SDL for $abi failed: see its output above" >&2; exit 1; } +} + +ensure_text() { # abi + local abi="$1" prefix + prefix="$VENDOR_DIR/out/$(vendor_triple "$abi")" + [ -d "$prefix/lib/pkgconfig" ] && return 0 + echo "==> no FreeType/HarfBuzz for $abi in this checkout: building them (Vendor/build.sh $abi)" >&2 + "$VENDOR_DIR/build.sh" "$abi" >&2 + [ -d "$prefix/lib/pkgconfig" ] || { echo "building FreeType/HarfBuzz for $abi failed: see its output above" >&2; exit 1; } +} + require_ndk() { : "${ANDROID_NDK_HOME:=$HOME/Library/Android/android-ndk-r30}" if [ ! -d "$ANDROID_NDK_HOME" ]; then diff --git a/Vendor/build.sh b/Vendor/build.sh index d3569819..19a9eb51 100755 --- a/Vendor/build.sh +++ b/Vendor/build.sh @@ -5,6 +5,8 @@ # ./build.sh everything (host, arm64-v8a, x86_64) # ./build.sh host just the Mac, which is what `swift test` needs # ./build.sh android just the two device ABIs +# ./build.sh arm64-v8a one device ABI (or x86_64): what the scripts +# build on demand when a checkout has none # # Nothing binary is committed: this fetches the pinned tarballs in # versions.sh, checks their hashes and builds static libraries into @@ -169,10 +171,12 @@ case "$what" in host) build_one host "${HOST_FLAGS[@]}" ;; android) build_android arm64-v8a aarch64-linux-android build_android x86_64 x86_64-linux-android ;; + arm64-v8a) build_android arm64-v8a aarch64-linux-android ;; + x86_64) build_android x86_64 x86_64-linux-android ;; all) build_one host "${HOST_FLAGS[@]}" build_android arm64-v8a aarch64-linux-android build_android x86_64 x86_64-linux-android ;; - *) echo "usage: build.sh [host|android|all]" >&2; exit 2 ;; + *) echo "usage: build.sh [host|android|arm64-v8a|x86_64|all]" >&2; exit 2 ;; esac echo From 508520ce07c744fd4f5de3a2f614e289f4646ab4 Mon Sep 17 00:00:00 2001 From: Himanshu Kapoor Date: Sun, 22 Nov 2026 21:46:17 +0100 Subject: [PATCH 2/2] check-android.sh's on-demand SDL stages into no game build-sdl.sh takes --no-stage, which ensure_sdl --unstaged passes: a standalone clone's check built SDL and then copied it, and SDL's Java, into an App beside the clone. --- Scripts/build-sdl.sh | 17 ++++++++++++++++- Scripts/config.sh | 14 ++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Scripts/build-sdl.sh b/Scripts/build-sdl.sh index 11eb1dff..0af5038d 100755 --- a/Scripts/build-sdl.sh +++ b/Scripts/build-sdl.sh @@ -9,11 +9,23 @@ # # Scripts/build-sdl.sh # both ABIs # Scripts/build-sdl.sh arm64-v8a # just one +# Scripts/build-sdl.sh --no-stage arm64-v8a +# # SDL alone, staged into no game: the +# # runtime's own checks (check-android.sh), +# # where the game's App would be the clone's +# # parent . "$(dirname "$0")/config.sh" require_ndk -targets=("$@") +stage=1 +targets=() +for arg in "$@"; do + case "$arg" in + --no-stage) stage=0 ;; + *) targets+=("$arg") ;; + esac +done [ ${#targets[@]} -eq 0 ] && targets=("${ABIS[@]}") mkdir -p "$VENDOR_DIR" @@ -44,11 +56,14 @@ for abi in "${targets[@]}"; do cmake --build "$build" --parallel cmake --install "$build" >/dev/null + [ "$stage" = 1 ] || continue mkdir -p "$JNI_LIBS/$abi" cp "$prefix/lib/libSDL3.so" "$JNI_LIBS/$abi/" echo " staged $JNI_LIBS/$abi/libSDL3.so" done +[ "$stage" = 1 ] || exit 0 + # SDL's Android glue is Java: the activity, the GL surface, input, audio. # It is part of SDL, not of this project, so it is compiled from the # checkout rather than forked: the runtime's Android library (Library/) diff --git a/Scripts/config.sh b/Scripts/config.sh index ed949704..f5a57785 100644 --- a/Scripts/config.sh +++ b/Scripts/config.sh @@ -63,14 +63,20 @@ swift_triple() { # For a game's build, SDL also counts as missing when it isn't staged into # the game's jniLibs (a cleaned App), which build-sdl.sh redoes # incrementally; `--unstaged` (the runtime's own checks, with no game) asks -# for the build alone. +# for the build alone and stages nothing, so a standalone clone never grows +# an App beside it. ensure_sdl() { # abi [--unstaged] - local abi="$1" + local abi="$1" unstaged=0 + [ "${2:-}" = --unstaged ] && unstaged=1 if [ -d "$VENDOR_DIR/sdl3/$abi/include" ]; then - [ "${2:-}" = --unstaged ] || [ -f "$JNI_LIBS/$abi/libSDL3.so" ] && return 0 + [ "$unstaged" = 1 ] || [ -f "$JNI_LIBS/$abi/libSDL3.so" ] && return 0 fi echo "==> no SDL for $abi in this checkout or the game: building it (Scripts/build-sdl.sh $abi)" >&2 - "$RUNTIME_DIR/Scripts/build-sdl.sh" "$abi" >&2 + if [ "$unstaged" = 1 ]; then + "$RUNTIME_DIR/Scripts/build-sdl.sh" --no-stage "$abi" >&2 + else + "$RUNTIME_DIR/Scripts/build-sdl.sh" "$abi" >&2 + fi [ -d "$VENDOR_DIR/sdl3/$abi/include" ] || { echo "building SDL for $abi failed: see its output above" >&2; exit 1; } }