Skip to content

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

Test the RomFS image handling, trim the README claim, tidy shim.py

v0lumehifb06349d4a49
diff --git a/frontend-qt/README.md b/frontend-qt/README.md
index 66e5b546..d3a7a40f 100644
--- a/frontend-qt/README.md
+++ b/frontend-qt/README.md
@@ -60,9 +60,8 @@ the bundle's `fonts` folder (`build-qt.yml`). If the file is missing the system
## What is not there yet
- **The Windows build path remains experimental.** One Rhythm Heaven Groove 1.0.0 IPA built on
- Windows installed and launched on an iPhone Air running iOS 27.0.1; Play started the game, which
- showed 60 FPS on the app's own frame-rate counter (no frame-time measurements were taken), and
- the button mappings were correct. That IPA needed three local changes beyond this branch:
+ Windows installed and launched on an iPhone Air running iOS 27.0.1; Play started the game, and the
+ button mappings were correct. That IPA needed three local changes beyond this branch:
seedds/nxnative#591 (the Windows image reader), an updated `dmsh_chain.lock` with a regenerated
`DMSH_CHAIN` for this machine's SPIRV-Cross and Metal tools, and a two-line declaration of
`CMMotionManager.deviceMotionBody` because the Windows toolchain still ships `iPhoneOS26.0.sdk`.
@@ -274,7 +273,7 @@ the tool offers it. The IPA name and the RomFS archive come out where the macOS
## Open risks
The frontend's setup has run on Windows, and one locally patched Windows build installed, launched
-and started the game at 60 FPS (counter only) on an iPhone. That test does not settle these risks
+and started the game on an iPhone. That test does not settle these risks
for other games or for an unmodified checkout:
1. **Shader libraries on the device.** They come from the Windows Metal compiler, not Xcode's.
diff --git a/frontend-qt/nspb_qt/win/build_app.py b/frontend-qt/nspb_qt/win/build_app.py
index 39637c4d..e2823fc3 100644
--- a/frontend-qt/nspb_qt/win/build_app.py
+++ b/frontend-qt/nspb_qt/win/build_app.py
@@ -64,6 +64,25 @@ FRAMEWORKS_BASE = [
_IMPORT = re.compile(r'^\s*#\s*(?:import|include)\s*<(\w+)/', re.M)
+#: Paths the pack step drops from the base app (a full IPA maps its RomFS back in as `romfs` or `romfs.img`).
+PACK_SKIPS = ('Payload/DmIOS.app/msl', 'Payload/DmIOS.app/aoc',
+ 'Payload/DmIOS.app/romfs', 'Payload/DmIOS.app/romfs.img')
+
+
+def romfs_has(repo, romfs, marker: str) -> bool:
+ """Whether the RomFS (a folder or an image file) holds `marker`, read through the engine's `romfs.Path`."""
+ tools = str(Path(repo) / 'dm' / 'tools')
+ if tools not in sys.path:
+ sys.path.insert(0, tools)
+ from romfs import Path as RomFSPath
+ return (RomFSPath(romfs) / marker).exists()
+
+
+def romfs_resource(romfs) -> str:
+ """The name a full IPA gives the RomFS: an image file is `romfs.img`, a folder is `romfs`."""
+ return 'romfs.img' if Path(romfs).is_file() else 'romfs'
+
+
def t(msg: str) -> None:
print(f'[{time.strftime("%H:%M:%S")}] {msg}', flush=True)
@@ -482,9 +501,7 @@ def main(argv: list[str] | None = None) -> int:
for m in mods:
if not ((patched / f'{m}.patched.bin').exists() and (patched / f'{m}.fixups.tsv').exists()):
die(f'no rewritten module {patched}/{m} (the rewrite step must run first)')
- sys.path.insert(0, str(repo / 'dm' / 'tools'))
- from romfs import Path as RomFSPath
- if not (RomFSPath(romfs) / marker).exists():
+ if not romfs_has(repo, romfs, marker):
die(f'no RomFS at {romfs} (missing {marker})')
name = env.get('DM_DISPLAY_NAME') or ''
@@ -675,7 +692,7 @@ def main(argv: list[str] | None = None) -> int:
t('add-on content: ' + ' '.join(sorted(p.name for p in aoc.iterdir())))
full = bool(env.get('DM_FULL_ROMFS'))
if full:
- resource = 'romfs.img' if romfs.is_file() else 'romfs'
+ resource = romfs_resource(romfs)
maps.append(f'Payload/DmIOS.app/{resource}={romfs}')
t('packing the full IPA with the RomFS (only sensible for small games)')
else:
@@ -685,8 +702,9 @@ def main(argv: list[str] | None = None) -> int:
pack = [sys.executable, str(repo / 'dm/ios/tools/pack_ipa.py'), str(out_ipa)]
if store:
pack += ['--store', ':'.join(store.split(':'))]
- pack += ['--skip', 'Payload/DmIOS.app/msl', '--skip', 'Payload/DmIOS.app/aoc',
- '--skip', 'Payload/DmIOS.app/romfs', '--skip', 'Payload/DmIOS.app/romfs.img', *maps]
+ for skip in PACK_SKIPS:
+ pack += ['--skip', skip]
+ pack += maps
r = subprocess.run(pack, capture_output=True, text=True, errors='replace')
if r.returncode:
print(((r.stdout or '') + (r.stderr or ''))[-3000:], file=sys.stderr)
diff --git a/frontend-qt/nspb_qt/win/shim.py b/frontend-qt/nspb_qt/win/shim.py
index ff9b4773..7f8edb8d 100644
--- a/frontend-qt/nspb_qt/win/shim.py
+++ b/frontend-qt/nspb_qt/win/shim.py
@@ -323,7 +323,8 @@ def build_env(base: dict[str, str] | None = None, python_exe: str | None = None)
p = tc.find_exe(name)
if p:
parts.append(str(p.parent))
- if name == 'spirv-cross': env.setdefault('SPIRV_CROSS', str(p))
+ if name == 'spirv-cross':
+ env.setdefault('SPIRV_CROSS', str(p))
# tc.dotnet_dir() first: it knows about the SDK the app installed for itself, which is not on
# PATH and not in Program Files. `which` alone missed it, so `dotnet build` and the shader
# translator failed on a machine that had just installed .NET through this app.
diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.py
index dfe00d8f..97e985ac 100644
--- a/frontend-qt/tests/test_win.py
+++ b/frontend-qt/tests/test_win.py
@@ -441,6 +441,58 @@ class InfoPlistTest(unittest.TestCase):
self.assertNotIn('CFBundleIcons', p)
+class RomfsPackTest(unittest.TestCase):
+ """The RomFS can be a folder or an image file: marker check, resource name and pack skips."""
+
+ def setUp(self):
+ self._tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(self._tmp.cleanup)
+ self.root = Path(self._tmp.name)
+ tools = self.root / 'repo' / 'dm' / 'tools'
+ tools.mkdir(parents=True)
+ # A stand-in for the engine's dm/tools/romfs.py: an image file is a text list of its entries.
+ (tools / 'romfs.py').write_text(
+ 'from pathlib import Path as _P\n'
+ 'class Path:\n'
+ ' def __init__(self, p):\n'
+ ' self.p = _P(p); self.rel = ""\n'
+ ' def __truediv__(self, n):\n'
+ ' o = Path(self.p); o.rel = n; return o\n'
+ ' def exists(self):\n'
+ ' if self.p.is_file():\n'
+ ' return self.rel in self.p.read_text().split()\n'
+ ' return (self.p / self.rel).exists()\n', encoding='utf-8')
+ self.repo = self.root / 'repo'
+ self._path = list(sys.path)
+ self.addCleanup(lambda: (sys.path.__setitem__(slice(None), self._path), sys.modules.pop('romfs', None)))
+ sys.modules.pop('romfs', None)
+
+ def test_marker_in_image_file(self):
+ img = self.root / 'RomFS.img'
+ img.write_text('graph/a.bin')
+ self.assertTrue(build_app.romfs_has(self.repo, img, 'graph/a.bin'))
+ self.assertFalse(build_app.romfs_has(self.repo, img, 'graph/b.bin'))
+
+ def test_marker_in_folder(self):
+ d = self.root / 'RomFS'
+ (d / 'graph').mkdir(parents=True)
+ (d / 'graph' / 'a.bin').write_bytes(b'')
+ self.assertTrue(build_app.romfs_has(self.repo, d, 'graph/a.bin'))
+ self.assertFalse(build_app.romfs_has(self.repo, d, 'graph/b.bin'))
+
+ def test_resource_name(self):
+ img = self.root / 'RomFS.img'
+ img.write_text('x')
+ d = self.root / 'RomFS'
+ d.mkdir()
+ self.assertEqual(build_app.romfs_resource(img), 'romfs.img')
+ self.assertEqual(build_app.romfs_resource(d), 'romfs')
+
+ def test_pack_skips_both_names(self):
+ self.assertIn('Payload/DmIOS.app/romfs', build_app.PACK_SKIPS)
+ self.assertIn('Payload/DmIOS.app/romfs.img', build_app.PACK_SKIPS)
+
+
class IpaModesTest(unittest.TestCase):
"""The zip mode fixer, which stands in for `pack_ipa.py --exec` (an upstream file we
must not edit)."""