Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Release: keep the bundled engine's binaries as built, so shader builds start

Dino000598fba5756c44
diff --git a/.github/workflows/build-mac-app.yml b/.github/workflows/build-mac-app.yml
index 9ab37ed4..7b53983a 100644
--- a/.github/workflows/build-mac-app.yml
+++ b/.github/workflows/build-mac-app.yml
@@ -231,12 +231,11 @@ jobs:
# itself: --deep below does not reach code that sits in Resources).
tools/bundle_tools.sh "$APP/Contents/Resources" "$RUNNER_TEMP/bundle-tools-work"
# The engine tree (Contents/ is read-only once signed: the launcher copies it to ~/Library/Application Support/NX2Apple/ on first
- # use). Its Mach-O files (the shader translator, spirv-cross) are signed on their own like the bundled tools: --deep does not reach
- # code in Resources. The zip asset keeps them as upstream built them.
+ # use). --deep does not reach code in Resources, but its Mach-O files (the shader translator, spirv-cross) are kept as upstream built
+ # them, already signed: re-signing rewrote spirv-cross, which dmsh_chain.lock pins by its bytes, and stopped every shader build from
+ # the bundled engine (own_compilers.py exit code 1). sign_engine_tree.sh signs only a Mach-O file without any signature and checks the rest.
ditto "$RUNNER_TEMP/engine-tree" "$APP/Contents/Resources/engine"
- while IFS= read -r -d '' f; do
- if file -b "$f" | grep -q 'Mach-O'; then codesign --force --sign - "$f" 2> /dev/null; fi
- done < <(find "$APP/Contents/Resources/engine" -type f -perm -u+x -print0)
+ tools/sign_engine_tree.sh "$APP/Contents/Resources/engine" "$RUNNER_TEMP/engine-tree"
V="${{ steps.ver.outputs.version }}"
cat > "$APP/Contents/Info.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
@@ -279,6 +278,8 @@ jobs:
cmp "$E/.upstream-ref" ../.upstream-ref
test -f "$E/scripts/build_ipa_from_nsp.py" && test -f "$E/dm/tools/romfs_image.py" && test -f "$E/dm/fork_patches.txt"
test ! -e "$E/.git"
+ # The engine files are the zip asset's, byte for byte, and spirv-cross matches dmsh_chain.lock, so a shader build from the bundled engine starts.
+ tools/sign_engine_tree.sh --check "$E" "$RUNNER_TEMP/engine-tree"
echo "engine in the bundle: $(cat "$E/.engine-id")"
- name: Package
diff --git a/frontend/tools/sign_engine_tree.sh b/frontend/tools/sign_engine_tree.sh
new file mode 100755
index 00000000..fb174cf4
--- /dev/null
+++ b/frontend/tools/sign_engine_tree.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+# Signs the engine tree inside the launcher bundle without changing the files the shader chain pins, and checks that it did not.
+#
+# The release used to re-sign every Mach-O file of Contents/Resources/engine (codesign --force --sign -). codesign rewrites the signature inside
+# the file, and dm/gfx/tools/dmsh_chain.lock pins spirv-cross by the SHA-256 of its bytes (tool_lock.py), so every shader build from the bundled
+# engine stopped with "translation chain tools do not match the lock file: spirv-cross" (own_compilers.py exit code 1). The upstream binaries
+# already carry a signature (spirv-cross the linker's ad-hoc one, the translator's apphost an ad-hoc one), which Apple silicon runs as it is.
+# So a Mach-O file is signed here only when it has no signature at all, and every other file stays byte for byte the one the zip asset holds.
+#
+# Usage: sign_engine_tree.sh <engine folder in the bundle> <engine tree it was copied from> sign what has no signature, then check
+# sign_engine_tree.sh --check <engine folder in the bundle> <engine tree it was copied from> only check
+set -uo pipefail
+CHECK_ONLY=0
+if [ "${1:-}" = --check ]; then CHECK_ONLY=1; shift; fi
+E=${1:?usage: sign_engine_tree.sh [--check] <engine folder> <engine tree>}
+TREE=${2:?usage: sign_engine_tree.sh [--check] <engine folder> <engine tree>}
+fail=0
+ok() { echo "ok $*"; }
+bad() { echo "FAIL $*"; fail=1; }
+sha16() { shasum -a 256 "$1" | cut -c1-16; }
+
+if [ "$CHECK_ONLY" = 0 ]; then
+ while IFS= read -r -d '' f; do
+ file -b "$f" | grep -q 'Mach-O' || continue
+ if codesign -d --arch arm64 "$f" > /dev/null 2>&1; then continue; fi # already signed (ad-hoc or by the linker): left as it is
+ codesign --force --sign - "$f" 2> /dev/null && echo "signed ${f#"$E"/} (it had no signature)" || bad "could not sign ${f#"$E"/}"
+ done < <(find "$E" -type f -perm -u+x -print0)
+fi
+
+# every file of the tree is in the bundle, unchanged, unless it had no signature and was signed above (then it has to verify)
+changed=0
+while IFS= read -r -d '' rel; do
+ rel=${rel#./}
+ if [ ! -f "$E/$rel" ]; then bad "missing from the bundle: $rel"; continue; fi
+ cmp -s "$TREE/$rel" "$E/$rel" && continue
+ if file -b "$E/$rel" | grep -q 'Mach-O' && ! codesign -d --arch arm64 "$TREE/$rel" > /dev/null 2>&1 && codesign -v "$E/$rel" 2> /dev/null; then
+ changed=$((changed + 1))
+ else
+ bad "changed in the bundle: $rel"
+ fi
+done < <(cd "$TREE" && find . -type f -print0)
+[ "$fail" = 0 ] && ok "the engine files are the tree's ($changed signed because they had no signature)"
+
+# the tools the lock pins by their bytes: spirv-cross (tool_lock.py reads the same lines)
+LOCK="$E/dm/gfx/tools/dmsh_chain.lock"
+want=$(awk -F'\t' '$1 == "spirv-cross" { print $2 }' "$LOCK" 2> /dev/null)
+have=$(sha16 "$E/dm/gfx/tools/spirv_cross_bin/spirv-cross" 2> /dev/null)
+if [ -n "$want" ] && [ "$want" = "$have" ]; then ok "spirv-cross matches dmsh_chain.lock ($have)"; else bad "spirv-cross is $have, dmsh_chain.lock says ${want:-nothing}"; fi
+codesign -d --arch arm64 "$E/dm/gfx/tools/spirv_cross_bin/spirv-cross" > /dev/null 2>&1 && ok "spirv-cross carries a signature" || bad "spirv-cross has no signature"
+
+exit "$fail"