Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -92,10 +91,10 @@ Scripts/check-android.sh arm64-v8a # cross-compiles the runtime
3. Make a Swift package at `<game>/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)
```
Expand Down Expand Up @@ -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`
Expand Down
17 changes: 16 additions & 1 deletion Scripts/build-sdl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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/)
Expand Down
17 changes: 6 additions & 11 deletions Scripts/build-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))"
Expand Down
6 changes: 3 additions & 3 deletions Scripts/check-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Comment thread
fleon marked this conversation as resolved.
Resolved
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
Expand Down
33 changes: 33 additions & 0 deletions Scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ 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 and stages nothing, so a standalone clone never grows
# an App beside it.
ensure_sdl() { # abi [--unstaged]
local abi="$1" unstaged=0
[ "${2:-}" = --unstaged ] && unstaged=1
if [ -d "$VENDOR_DIR/sdl3/$abi/include" ]; then
[ "$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
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; }
}

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
Expand Down
6 changes: 5 additions & 1 deletion Vendor/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading