Skip to content

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

Close three environment assumptions found by auditing after the user's three failures

LNPANDY1cf1798374f5
diff --git a/frontend/NS-Port-Builder-macOS-arm64.zip b/frontend/NS-Port-Builder-macOS-arm64.zip
index e799157a..4c30c658 100644
Binary files a/frontend/NS-Port-Builder-macOS-arm64.zip and b/frontend/NS-Port-Builder-macOS-arm64.zip differ
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index b6215632..f2d375b5 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -534,6 +534,25 @@ final class BuildModel: ObservableObject {
let tidHex = Self.titleID(basePath).map { String(format: "%016llX", $0) } ?? "game"
let workDir = (outDir.isEmpty ? baseDir : outDir) + "/" + tidHex + "_build"
+ // A compressed dump (NSZ / XCZ) needs nsz in the interpreter the build runs under; it is not
+ // part of the dependency probe (most builds never see one), so install it here, once, only
+ // when such a file is actually selected — otherwise the build stops with "pip install nsz".
+ let compressed = ([basePath, updatePath] + dlcPaths).contains {
+ let e = ($0 as NSString).pathExtension.lowercased()
+ return e == "nsz" || e == "xcz"
+ }
+ if compressed, !Self.runOK(py, ["-c", "import nsz"]) {
+ say(t("msg.installingNsz"))
+ let r = Self.runCaptured([py, "-m", "pip", "install", "nsz"],
+ env: ["PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin",
+ "HOME": NSHomeDirectory()]) { line in
+ DispatchQueue.main.async { self.append(line + "\n") }
+ }
+ if !r {
+ fail(String(format: t("msg.nszFailed"), py))
+ return
+ }
+ }
var args = [repoPath + "/scripts/build_ipa_from_nsp.py", inputDir, "-k", keysPath,
"--work-dir", workDir, "--progress", "lines"]
if !outDir.isEmpty { args += ["-o", outDir + "/" + tidHex + ".ipa"] }
@@ -825,6 +844,9 @@ final class BuildModel: ObservableObject {
/// `compression.zstd` is built in from Python 3.14 and `backports.zstd` (which declares
/// Python < 3.14) is the only option before that. Requiring the backport unconditionally
/// rejected an otherwise working Homebrew Python 3.15 (issue #1).
+ /// nsz is deliberately not required here: it is only needed for NSZ / XCZ dumps, and the
+ /// pipeline says so by name when one shows up. The venv installs it anyway so that a player
+ /// who downloads a compressed dump never meets that error.
nonisolated static let importProbe = """
import lz4, capstone, fontTools
try:
@@ -844,8 +866,11 @@ final class BuildModel: ObservableObject {
nonisolated static func importsOK(_ py: String) -> Bool { runOK(py, ["-c", importProbe]) }
/// backports.zstd declares Python < 3.14, so it is only installed where it is needed.
+ /// nsz is always installed: NSZ / XCZ dumps are accepted by the pipeline now, and a player who
+ /// downloads one should not have to run pip by hand (it is a few hundred KB).
nonisolated static func pipPackages(_ version: (Int, Int)) -> [String] {
- version < (3, 14) ? ["lz4", "capstone", "fonttools", "backports.zstd"] : ["lz4", "capstone", "fonttools"]
+ version < (3, 14) ? ["lz4", "capstone", "fonttools", "backports.zstd", "nsz"]
+ : ["lz4", "capstone", "fonttools", "nsz"]
}
/// Create the venv (reusing an existing one) and install the packages into it. Returns the
@@ -986,10 +1011,18 @@ final class BuildModel: ObservableObject {
nonisolated static func detectDepsSync() -> [Dep] {
var out: [Dep] = []
- let xcode = FileManager.default.fileExists(atPath: "/Applications/Xcode.app")
+ // Xcode.app alone is not enough: since Xcode 15 the iOS platform ships as a separate
+ // download, so a fresh install has xcodebuild but no iOS SDK and the build dies deep in
+ // xcodebuild. Ask for the SDK version itself — that is the check that matches the name.
+ let xcodePresent = FileManager.default.fileExists(atPath: "/Applications/Xcode.app")
&& FileManager.default.isExecutableFile(atPath: "/usr/bin/xcodebuild")
+ let iosSDK = xcodePresent && runOK("/usr/bin/xcrun", ["--sdk", "iphoneos", "--show-sdk-version"])
out.append(Dep(id: "xcode", name: "dep.xcode", hint: "dep.xcode.hint",
- present: xcode, installCmd: []))
+ present: iosSDK,
+ detail: iosSDK ? "" : (xcodePresent ? "dep.xcode.noSDK" : ""),
+ installCmd: iosSDK ? [] : (xcodePresent
+ ? ["/usr/bin/xcodebuild", "-downloadPlatform", "iOS"]
+ : [])))
let mt = runOK("/usr/bin/xcrun", ["-sdk", "macosx", "metal", "--version"])
out.append(Dep(id: "metal", name: "dep.metal", hint: "dep.metal.hint",
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index 21b02ba5..06bd4bd2 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -121,6 +121,8 @@ enum L10n {
"dep.xcode": ("Xcode + iOS SDK", "Xcode + iOS SDK"),
"dep.xcode.hint": ("App Store 安装,约 12 GB", "from the App Store, about 12 GB"),
+ "dep.xcode.noSDK": ("Xcode 已装,但 iOS SDK 未下载(Xcode 15 起 iOS 平台是单独下载的)",
+ "Xcode is installed but the iOS SDK is not downloaded (a separate download since Xcode 15)"),
"dep.metal": ("Metal Toolchain", "Metal Toolchain"),
"dep.metal.hint": ("xcodebuild -downloadComponent MetalToolchain(约 840 MB)",
"xcodebuild -downloadComponent MetalToolchain (about 840 MB)"),
@@ -172,6 +174,10 @@ enum L10n {
// ---- build messages ----
"msg.running": ("运行:%@", "Running: %@"),
+ "msg.installingNsz": ("选中的是 NSZ / XCZ 压缩格式,正在给构建用的 Python 安装 nsz…",
+ "The selected dump is NSZ / XCZ — installing nsz into the build's Python…"),
+ "msg.nszFailed": ("nsz 安装失败(构建用的 Python:%@)——网络不通?或手动执行 pip install nsz",
+ "Could not install nsz (build Python: %@) — network trouble? Or run pip install nsz by hand"),
"msg.stopped": ("已停止", "Stopped"),
"msg.buildFailed": ("构建失败(退出码 %d),见下方日志",
"Build failed (exit code %d) — see the log below"),
diff --git a/scripts/build_ipa_from_nsp.py b/scripts/build_ipa_from_nsp.py
index 34a402e5..de0ec5f7 100755
--- a/scripts/build_ipa_from_nsp.py
+++ b/scripts/build_ipa_from_nsp.py
@@ -788,6 +788,13 @@ def check_prereqs(env, xlate, mac=False): # mac: a Mac-only build (PLATFORM 'm
if mac: del tools['xcodegen']
gone = [f'{t} ({how})' for t, how in tools.items() if not shutil.which(t, path=env['PATH'])]
if gone: raise BuildError('tools not found: ' + ', '.join(gone))
+ if not mac:
+ # Xcode 15 and later ship the iOS platform as a separate download: xcodebuild and the Metal
+ # compiler can both be there while the iOS SDK is not, and the failure then surfaces deep in
+ # xcodebuild. Check the SDK itself so the message names the right command.
+ sdk = subprocess.run(['xcrun', '--sdk', 'iphoneos', '--show-sdk-version'], capture_output=True, text=True, env=env)
+ if sdk.returncode:
+ raise BuildError('the iOS SDK is not installed (Xcode 15 and later download the platform separately): run xcodebuild -downloadPlatform iOS, or pick it in Xcode → Settings → Components')
mtl = subprocess.run(['xcrun', '-sdk', 'macosx' if mac else 'iphoneos', 'metal', '--version'], capture_output=True, text=True, env=env) # Xcode 26 and later install the Metal toolchain separately
if mtl.returncode: raise BuildError(f'the Metal compiler does not run ({(mtl.stderr.strip().splitlines() or ["no output"])[-1]}): install it with xcodebuild -downloadComponent MetalToolchain')
if not xlate.exists(): raise BuildError(f'the shader translator is missing from the repository: {xlate}')
diff --git a/scripts/sync_upstream.py b/scripts/sync_upstream.py
index ccc32d4c..3cab7e80 100644
--- a/scripts/sync_upstream.py
+++ b/scripts/sync_upstream.py
@@ -385,6 +385,23 @@ def patch_nsp(t):
''' if pkg_ver not in builds:
_reg = ", ".join("{} {}".format(v, b["display"]) for v, b in builds.items())
derived = f'{pkg_ver} is not a version game profile {g.id} registers ({_reg})\'''')]))
+ # Xcode 15 and later download the iOS platform separately: xcodebuild and the Metal compiler can
+ # both be present with no iOS SDK, and the failure then surfaced deep inside xcodebuild. Naming
+ # the SDK makes the error actionable (found while auditing environment assumptions, 2026-10-26).
+ P.append(('iOS SDK check', "the iOS SDK is not installed", [(
+ """ gone = [f'{t} ({how})' for t, how in tools.items() if not shutil.which(t, path=env['PATH'])]
+ if gone: raise BuildError('tools not found: ' + ', '.join(gone))
+""",
+ """ gone = [f'{t} ({how})' for t, how in tools.items() if not shutil.which(t, path=env['PATH'])]
+ if gone: raise BuildError('tools not found: ' + ', '.join(gone))
+ if not mac:
+ # Xcode 15 and later ship the iOS platform as a separate download: xcodebuild and the Metal
+ # compiler can both be there while the iOS SDK is not, and the failure then surfaces deep in
+ # xcodebuild. Check the SDK itself so the message names the right command.
+ sdk = subprocess.run(['xcrun', '--sdk', 'iphoneos', '--show-sdk-version'], capture_output=True, text=True, env=env)
+ if sdk.returncode:
+ raise BuildError('the iOS SDK is not installed (Xcode 15 and later download the platform separately): run xcodebuild -downloadPlatform iOS, or pick it in Xcode → Settings → Components')
+""")]))
for name, marker, pairs in P:
if marker in t:
skip(f'NSP script {name} (already patched)'); continue