Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
frontend-qt: fix Windows app build SDK symlink stubs, dav1d, host_msl_gen.h and dm_game_menu
LNPANDY267362279e22
diff --git a/frontend-qt/nspb_qt/win/build_app.py b/frontend-qt/nspb_qt/win/build_app.pyindex f8dbce95..79d1fcf4 100644--- a/frontend-qt/nspb_qt/win/build_app.py+++ b/frontend-qt/nspb_qt/win/build_app.py@@ -157,13 +157,27 @@ def host_sources(repo: Path, game_h_dir: Path) -> tuple[list[Path], list[Path]]:vpx = repo / 'dm' / 'third_party' / 'libvpx'vpx_src = sorted(vpx.rglob('*.c'), key=lambda p: p.as_posix())+ dav1d = repo / 'dm' / 'third_party' / 'dav1d'+ dav1d_src: list[Path] = []+ if dav1d.is_dir():+ dav1d_src = sorted(+ [p for p in (dav1d / 'src').glob('*.c') if not p.name.endswith('_tmpl.c')]+ + ([dav1d / 'src' / 'arm' / 'cpu.c'] if (dav1d / 'src' / 'arm' / 'cpu.c').is_file() else [])+ + list((dav1d / 'config' / 'tmpl').glob('*.c'))+ + [p for p in (dav1d / 'src' / 'arm' / '64').glob('*.S')+ if not p.name.endswith('_tmpl.S') and p.name != 'util.S'],+ key=lambda p: p.as_posix(),+ )+incs = [repo / 'dm' / 'gfx' / 'nvn' / 'include',repo / 'dm' / 'third_party' / 'vulkan-headers' / 'include',game_h_dir, vpx, repo / 'dm' / 'third_party' / 'stb_vorbis', vpx / 'config']+ if dav1d.is_dir():+ incs += [dav1d / 'include', dav1d, dav1d / 'config']ios_sources = (repo / 'dm' / 'ios' / 'Sources').resolve()files: list[Path] = []- for s in src + gfx + vpx_src:+ for s in src + gfx + vpx_src + dav1d_src:s = s.resolve()if not s.is_file():die(f'a source from dm/host/Makefile does not exist: {s}')@@ -609,6 +623,11 @@ def main(argv: list[str] | None = None) -> int:# --- generate Gen/ (the same generators build_ipa.sh calls)t('generate Gen/ (profile header, embedded modules, tables)')py(repo / 'dm/games/game.py', 'header', game, gen / 'profile/game_profile.h')+ msl_srcs = sorted((repo / 'dm/gfx/msl').glob('*.metal'))+ if msl_srcs:+ py(repo / 'dm/gfx/tools/host_msl.py', '--sdk', 'iphoneos',+ '--min', tc.setting('metal_ios_target', '18.0'),+ gen / 'profile/host_msl_gen.h', *msl_srcs)es = gen / 'embed.S'jit_img = romfs.parent / 'jit' / 'jit.img'embed_extra = [jit_img] if jit_img.is_file() else []@@ -722,7 +741,8 @@ def main(argv: list[str] | None = None) -> int:if romfs.is_file():rid_file = base / 'romfs.id'r_id = subprocess.run([sys.executable, str(repo / 'dm/tools/romfs_image.py'),- '--identity', str(romfs)], capture_output=True)+ '--identity', str(romfs), str(game), str(version),+ str(pkg or '')], capture_output=True)if r_id.returncode == 0 and r_id.stdout:rid_file.write_bytes(r_id.stdout)maps.append(f'Payload/DmIOS.app/romfs.id={rid_file}')diff --git a/frontend-qt/nspb_qt/win/ios/Launcher.m b/frontend-qt/nspb_qt/win/ios/Launcher.mindex 9a44a594..c5aa1c9e 100644--- a/frontend-qt/nspb_qt/win/ios/Launcher.m+++ b/frontend-qt/nspb_qt/win/ios/Launcher.m@@ -595,6 +595,114 @@ static UIImage *nspb_app_icon(void) {- (BOOL)prefersHomeIndicatorAutoHidden { return YES; }@end+#pragma mark - in-game menu (GameMenu.swift port)++extern int dm_pad_layout(void);+extern bool dm_pad_layout_offered(int layout);+extern void dm_pad_layout_set(int layout);+extern bool dm_setting_live(const char *env, const char *value);+extern void *dm_quit_menu(void);++static NspbModel *g_game_menu_model;++static UIMenuElement *nspb_game_menu_row(NspbModel *m, NspbSetting *s) {+ NSString *now = [m value:s];+ BOOL fixed = [m locked:s];+ UIMenuElementAttributes attrs = fixed ? UIMenuElementAttributesDisabled : 0;+ void (^pick)(NSString *) = ^(NSString *v) {+ if (fixed || ![s accepts:v]) return;+ m.values[s.env] = v;+ NSString *key = [@"launcher." stringByAppendingString:s.env];+ if ([s isDefault:v]) [m.defaults removeObjectForKey:key];+ else [m.defaults setObject:v forKey:key];+ setenv(s.env.UTF8String, v.UTF8String, 1);+ fprintf(stderr, "launcher: %s=%s (in-game menu)\n", s.env.UTF8String, v.UTF8String);+ dm_setting_live(s.env.UTF8String, v.UTF8String);+ };+ if ([s.kind isEqualToString:@"toggle"]) {+ NSString *next = [now isEqualToString:s.onValue] ? s.offValue : s.onValue;+ UIAction *a = [UIAction actionWithTitle:s.label image:nil identifier:nil handler:^(__kindof UIAction *__unused act) {+ pick(next);+ }];+ a.attributes = attrs;+ a.state = [now isEqualToString:s.onValue] ? UIMenuElementStateOn : UIMenuElementStateOff;+ if (fixed) a.subtitle = @"Set in env.txt";+ return a;+ }+ NSArray<NSArray<NSString *> *> *options = s.options ?: @[];+ NSString *current = now;+ NSMutableArray<UIAction *> *actions = [NSMutableArray arrayWithCapacity:options.count];+ for (NSArray<NSString *> *o in options) {+ if ([o[0] isEqualToString:now]) current = o[1];+ NSString *val = o[0];+ UIAction *a = [UIAction actionWithTitle:o[1] image:nil identifier:nil handler:^(__kindof UIAction *__unused act) {+ pick(val);+ }];+ a.attributes = attrs;+ a.state = [val isEqualToString:now] ? UIMenuElementStateOn : UIMenuElementStateOff;+ [actions addObject:a];+ }+ UIMenu *sub = [UIMenu menuWithTitle:s.label image:nil identifier:nil options:UIMenuOptionsSingleSelection children:actions];+ if (fixed && [sub respondsToSelector:@selector(setSubtitle:)]) {+ sub.subtitle = [NSString stringWithFormat:@"%@, set in env.txt", current];+ }+ return sub;+}++static NSArray<UIMenuElement *> *nspb_game_menu_items(void) {+ NSArray<NSString *> *names = @[@"2D", @"3D", @"Tap"];+ NSMutableArray<UIAction *> *layouts = [NSMutableArray array];+ for (int l = 0; l < 3; l++) {+ if (!dm_pad_layout_offered(l)) continue;+ UIAction *a = [UIAction actionWithTitle:names[l] image:nil identifier:nil handler:^(__kindof UIAction *__unused act) {+ dm_pad_layout_set(l);+ }];+ a.state = (dm_pad_layout() == l) ? UIMenuElementStateOn : UIMenuElementStateOff;+ [layouts addObject:a];+ }+ UIMenu *layout = [UIMenu menuWithTitle:@"Controller layout" image:nil identifier:nil options:UIMenuOptionsSingleSelection children:layouts];+ NSMutableArray<UIMenuElement *> *items = [NSMutableArray array];+ BOOL placed = NO;+ NspbModel *m = g_game_menu_model;+ if (m) {+ for (NSString *section in m.sections) {+ NSMutableArray<UIMenuElement *> *rows = [NSMutableArray array];+ if ([section isEqualToString:@"Controls"]) {+ [rows addObject:layout];+ placed = YES;+ }+ for (NspbSetting *s in m.settings) {+ if (![s.sectionTitle isEqualToString:section]) continue;+ if (([s.kind isEqualToString:@"choice"] || [s.kind isEqualToString:@"toggle"]) &&+ dm_setting_live(s.env.UTF8String, NULL)) {+ [rows addObject:nspb_game_menu_row(m, s)];+ }+ }+ if (rows.count) {+ [items addObject:[UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:rows]];+ }+ }+ }+ if (!placed) {+ [items insertObject:[UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:@[layout]] atIndex:0];+ }+ void *quit = dm_quit_menu();+ if (quit) {+ UIMenu *qm = CFBridgingRelease(quit);+ if (qm) [items addObject:qm];+ }+ return items;+}++void *dm_game_menu(void) {+ NSString *title = g_game_menu_model ? @"More settings on the start screen" : @"";+ UIDeferredMenuElement *def = [UIDeferredMenuElement elementWithUncachedProvider:^(void (^done)(NSArray<UIMenuElement *> *)) {+ done(nspb_game_menu_items());+ }];+ UIMenu *menu = [UIMenu menuWithTitle:title children:@[def]];+ return (void *)CFBridgingRetain(menu);+}+#pragma mark - entry point// A capture IPA (the run-time shader capture done on the device instead of a Mac) sets@@ -633,6 +741,7 @@ bool dm_show_launcher(void *view_controller, void (*done)(void)) {}UIViewController *parent = (__bridge UIViewController *)view_controller;NspbModel *model = [[NspbModel alloc] initWith:settings];+ g_game_menu_model = model;NspbLauncherVC *vc = [NspbLauncherVC new];vc.m = model;vc.modalPresentationStyle = UIModalPresentationFullScreen;diff --git a/frontend-qt/nspb_qt/win/sdk_fetch.py b/frontend-qt/nspb_qt/win/sdk_fetch.pyindex 0dfcded5..e73b3ce5 100644--- a/frontend-qt/nspb_qt/win/sdk_fetch.py+++ b/frontend-qt/nspb_qt/win/sdk_fetch.py@@ -85,29 +85,53 @@ def materialize_symlinks(repo: Path, sub: str, log: Callable[[str], None]) -> inargs = ['ls-files', '-s', '-z']if sub:args += ['--', sub]+ git = str(tc.git_exe() or shutil.which('git') or 'git')try:- r = subprocess.run(['git', '-C', str(repo), *args], capture_output=True, **tc.no_window())+ r = subprocess.run([git, '-C', str(repo), *args], capture_output=True, **tc.no_window())except OSError:return 0if r.returncode:return 0- fixed = 0+ symlinks: list[Path] = []for entry in r.stdout.split(b'\x00'):if not entry:continuemeta, _, rel = entry.partition(b'\t')if meta.split(b' ')[0] != b'120000':continue- p = repo / os.fsdecode(rel)- if not p.is_file() or p.is_symlink():- continue- target = p.read_text(encoding='utf-8', errors='replace').strip()- real = (p.parent / target).resolve()- if not real.is_file():- log(f' {rel.decode("utf-8", "replace")}: its target {target!r} is missing, left as it is')- continue- p.write_bytes(real.read_bytes())- fixed += 1+ symlinks.append(repo / os.fsdecode(rel))+ pending = set(symlinks)+ fixed = 0+ for _pass in range(4):+ round_fixed = 0+ for p in list(symlinks):+ if p not in pending:+ continue+ if not p.is_file() or p.is_symlink():+ pending.discard(p)+ continue+ target = p.read_text(encoding='utf-8', errors='replace').strip()+ cand = p.parent / target+ if cand in pending:+ continue # target is itself a symlink stub; resolve it first+ real = cand.resolve()+ if real.is_dir():+ p.unlink()+ shutil.copytree(real, p, dirs_exist_ok=True)+ pending.discard(p)+ round_fixed += 1+ fixed += 1+ elif real.is_file():+ p.write_bytes(real.read_bytes())+ pending.discard(p)+ round_fixed += 1+ fixed += 1+ if not round_fixed:+ break+ for p in sorted(pending):+ if p.is_file() and not p.is_symlink():+ target = p.read_text(encoding='utf-8', errors='replace').strip()+ log(f' {p.relative_to(repo).as_posix()}: its target {target!r} is missing, left as it is')if fixed:log(f' materialized {fixed} symlink stubs into real files (Windows checkout of git symlinks)')return fixed@@ -209,14 +233,16 @@ def clone_sdk(version: str = tc.SDK_PINNED, dest: Path | None = None,if target.exists():shutil.rmtree(target, ignore_errors=True)shutil.move(str(src), str(target))- shutil.rmtree(work, ignore_errors=True)+ rmtree(work)+ repair_tbd_stubs(target, log=log)log(f'SDK ready: {target} ({tc.sdk_version(target)[0]})')return targetdef available_versions(log: Callable[[str], None] | None = None) -> list[str]:"""The SDK versions the repository currently offers (needs network; best effort)."""- git = shutil.which('git')+ found = tc.git_exe() or shutil.which('git')+ git = str(found) if found else Noneif not git:return []try:diff --git a/frontend-qt/nspb_qt/win/shim.py b/frontend-qt/nspb_qt/win/shim.pyindex bc73ea31..75d918c9 100644--- a/frontend-qt/nspb_qt/win/shim.py+++ b/frontend-qt/nspb_qt/win/shim.py@@ -335,6 +335,8 @@ if os.name == 'nt' and not os.environ.get('NSPB_SHIM_OFF'):process per call: a shader build makes thousands of them."""if len(rest) < 3 or rest[0] not in ('-sdk', '--sdk') or rest[2] not in ('metal', 'metallib'):return None+ if rest[2] == 'metal' and '-c' not in rest[3:] and '-o' in rest[3:]:+ return None # compile+link in one call (host_msl.py): handled by xcrun_shim.pyif 'modules' not in _CACHE:if _PKG not in sys.path:sys.path.insert(0, _PKG)diff --git a/frontend-qt/nspb_qt/win/toolchain.py b/frontend-qt/nspb_qt/win/toolchain.pyindex 51bc1ec1..0596a805 100644--- a/frontend-qt/nspb_qt/win/toolchain.py+++ b/frontend-qt/nspb_qt/win/toolchain.py@@ -610,36 +610,71 @@ def sdk_cache_dir() -> Path:return base / 'NS Port Builder' / 'sdks'+def _is_symlink_stub_bytes(raw: bytes) -> str | None:+ """Return the relative target string if `raw` looks like a git symlink stub, else None."""+ if not (1 <= len(raw) <= 256) or raw.startswith(b'--- !tapi-tbd'):+ return None+ if any(b in raw for b in (b'\n', b'\r', b'\x00', b' ', b'\t', b';', b'{', b'}', b'#')):+ return None+ try:+ target = raw.decode('utf-8')+ except UnicodeDecodeError:+ return None+ if not target or target in ('.', '..') or target.startswith(('/', '\\')):+ return None+ return target++def repair_tbd_stubs(sdk: Path | str, log=None) -> int:- """Fix `.tbd` files that a Windows git checkout left as text stubs, without git.-- An SDK downloaded through a git route before the symlink materialization (or copied from a- broken checkout) keeps every symlink `.tbd` as a small text file naming its target- (`libSystem.tbd` → `libSystem.B.tbd`). `ld64.lld` opens it, finds no `--- !tapi-tbd`, and- refuses: "unhandled file type" (LNPANDY/NX2Apple PR #596 fixed the clone route; cached SDKs- from before it still carry the stubs). Content-keyed repair: a `.tbd` that does not start- with the format's `--- !tapi-tbd` marker and names an existing sibling file gets that- sibling's bytes copied over it. Real TBD files and dangling stubs are never touched.- Returns how many were repaired.+ """Fix git symlink text stubs (`.tbd`, `.h`, framework dirs) in a Windows SDK checkout.++ An SDK checked out on Windows without `core.symlinks=true` (or before `materialize_symlinks`+ used `toolchain.git_exe()`) leaves every symlink as a small one-line text file naming its+ relative target (`libSystem.tbd` → `libSystem.B.tbd`, `usr/include/pthread.h` →+ `pthread/pthread.h`, `IOKit.framework/Versions/Current` → `A`). Running up to 4 passes+ resolves chained symlinks (`libm.tbd` → `libSystem.tbd` → `libSystem.B.tbd` and+ `Headers` → `Versions/Current/Headers`) without needing git or `.git`."""+ sdk_root = Path(sdk).resolve()fixed = 0- for p in sorted(Path(sdk).rglob('*.tbd')):- if not p.is_file() or p.is_symlink():- continue- if p.read_bytes()[:13] == b'--- !tapi-tbd':- continue- target = p.read_text(encoding='utf-8', errors='replace').strip()- if not target or '/' in target or '\\' in target or target.startswith('.'):- continue- real = (p.parent / target).resolve()- if not real.is_file() or real.resolve() == p.resolve():- continue- if real.read_bytes()[:13] != b'--- !tapi-tbd':- continue- p.write_bytes(real.read_bytes())- fixed += 1- if log:- log(f'repaired {p.name} ← {target}')+ for _pass in range(4):+ round_fixed = 0+ for p in sorted(sdk_root.rglob('*')):+ try:+ if p.is_symlink() or not p.is_file():+ continue+ st = p.stat()+ if not (1 <= st.st_size <= 256):+ continue+ target = _is_symlink_stub_bytes(p.read_bytes())+ if not target:+ continue+ cand = p.parent / target+ real = cand.resolve()+ if real == p.resolve() or not str(real).startswith(str(sdk_root)):+ continue+ if real.is_dir():+ p.unlink()+ shutil.copytree(real, p, dirs_exist_ok=True)+ round_fixed += 1+ fixed += 1+ if log:+ log(f'repaired dir {p.relative_to(sdk_root)} ← {target}')+ elif real.is_file():+ real_bytes = real.read_bytes()+ if _is_symlink_stub_bytes(real_bytes) is not None:+ continue # target is itself an unexpanded stub; next pass will resolve it+ if p.suffix == '.tbd' and real_bytes[:13] != b'--- !tapi-tbd':+ continue+ p.write_bytes(real_bytes)+ round_fixed += 1+ fixed += 1+ if log:+ log(f'repaired {p.name} ← {target}')+ except OSError:+ continue+ if not round_fixed:+ breakreturn fixeddiff --git a/frontend-qt/nspb_qt/win/xcrun_shim.py b/frontend-qt/nspb_qt/win/xcrun_shim.pyindex e71eb679..f1588015 100644--- a/frontend-qt/nspb_qt/win/xcrun_shim.py+++ b/frontend-qt/nspb_qt/win/xcrun_shim.py@@ -171,6 +171,27 @@ def main(argv: list[str] | None = None) -> int:' (see the Windows build section of frontend-qt/README.md)'))if tool == 'metal':rest = metal_args(sdk, rest)+ if '-c' not in rest and '-o' in rest:+ idx = rest.index('-o')+ if idx + 1 < len(rest) and rest[idx + 1].endswith('.metallib'):+ ml_out = rest[idx + 1]+ air_tmp = ml_out + '.air'+ compile_rest = rest[:idx] + ['-c', '-o', air_tmp] + rest[idx + 2:]+ ml_exe = find(sdk, 'metallib')+ if ml_exe:+ try:+ r1 = subprocess.run([str(exe)] + compile_rest)+ if r1.returncode != 0:+ return r1.returncode+ r2 = subprocess.run([str(ml_exe), air_tmp, '-o', ml_out])+ return r2.returncode+ except OSError as e:+ _die(f'cannot start {exe}: {e}')+ finally:+ try:+ Path(air_tmp).unlink(missing_ok=True)+ except OSError:+ passelif tool == 'clang':rest = clang_args(rest)try:diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.pyindex ee37824f..ae9df182 100644--- a/frontend-qt/tests/test_win.py+++ b/frontend-qt/tests/test_win.py@@ -2349,6 +2349,82 @@ class WindowsBuildFixesTest(unittest.TestCase):m._on_line('[04:35:04] [RED] patch_nso.py failed')self.assertEqual(m._last_error, '[RED] patch_nso.py failed')+ def test_repair_tbd_stubs_fixes_headers_chained_tbds_and_framework_dirs(self) -> None:+ with tempfile.TemporaryDirectory() as td:+ sdk = Path(td) / 'iPhoneOS26.0.sdk'+ # 1. usr/include/pthread.h -> pthread/pthread.h and arpa/nameser.h -> ../nameser.h+ (sdk / 'usr/include/pthread').mkdir(parents=True)+ (sdk / 'usr/include/arpa').mkdir(parents=True)+ real_pthread = '#ifndef _PTHREAD_H\n#define _PTHREAD_H\ntypedef struct _opaque_pthread_t *pthread_t;\n#endif\n'+ (sdk / 'usr/include/pthread/pthread.h').write_text(real_pthread, encoding='utf-8')+ (sdk / 'usr/include/pthread.h').write_text('pthread/pthread.h', encoding='utf-8')+ (sdk / 'usr/include/nameser.h').write_text('#define _NAMESER_H 1\n', encoding='utf-8')+ (sdk / 'usr/include/arpa/nameser.h').write_text('../nameser.h', encoding='utf-8')++ # 2. Chained .tbd: libm.tbd -> libSystem.tbd -> libSystem.B.tbd+ (sdk / 'usr/lib').mkdir(parents=True)+ tbd_body = '--- !tapi-tbd\ntbd-version: 4\ntargets: [ arm64-ios ]\n...\n'+ (sdk / 'usr/lib/libSystem.B.tbd').write_text(tbd_body, encoding='utf-8')+ (sdk / 'usr/lib/libSystem.tbd').write_text('libSystem.B.tbd', encoding='utf-8')+ (sdk / 'usr/lib/libm.tbd').write_text('libSystem.tbd', encoding='utf-8')++ # 3. Framework dir symlinks: Versions/Current -> A, Headers -> Versions/Current/Headers+ fw = sdk / 'System/Library/Frameworks/IOKit.framework'+ (fw / 'Versions/A/Headers').mkdir(parents=True)+ (fw / 'Versions/A/Headers/IOKitLib.h').write_text('#define IOKIT 1\n', encoding='utf-8')+ (fw / 'Versions/Current').write_text('A', encoding='utf-8')+ (fw / 'Headers').write_text('Versions/Current/Headers', encoding='utf-8')++ fixed = tc.repair_tbd_stubs(sdk)+ self.assertEqual(fixed, 6)+ self.assertEqual((sdk / 'usr/include/pthread.h').read_text(encoding='utf-8'), real_pthread)+ self.assertEqual((sdk / 'usr/include/arpa/nameser.h').read_text(encoding='utf-8'), '#define _NAMESER_H 1\n')+ self.assertEqual((sdk / 'usr/lib/libSystem.tbd').read_text(encoding='utf-8'), tbd_body)+ self.assertEqual((sdk / 'usr/lib/libm.tbd').read_text(encoding='utf-8'), tbd_body)+ self.assertTrue((fw / 'Headers/IOKitLib.h').is_file())+ self.assertEqual((fw / 'Headers/IOKitLib.h').read_text(encoding='utf-8'), '#define IOKIT 1\n')+ # Second pass is a no-op+ self.assertEqual(tc.repair_tbd_stubs(sdk), 0)++ def test_host_sources_includes_dav1d_and_launcher_defines_dm_game_menu(self) -> None:+ from nspb_qt.win import build_app+ repo = QT.parent / 'engine'+ if not (repo / 'dm/host/Makefile').is_file():+ self.skipTest('engine/ is missing')+ with tempfile.TemporaryDirectory() as td:+ files, incs = build_app.host_sources(repo, Path(td))+ names = {f.name for f in files}+ self.assertIn('lib.c', names, 'dav1d src/lib.c must be in host_sources')+ self.assertIn('itx.S', names, 'dav1d arm64 assembly must be in host_sources')+ inc_strs = [p.as_posix() for p in incs]+ self.assertTrue(any(p.endswith('dm/third_party/dav1d/include') for p in inc_strs))+ self.assertTrue(any(p.endswith('dm/third_party/dav1d/config') for p in inc_strs))++ launcher_m = (QT / 'nspb_qt/win/ios/Launcher.m').read_text(encoding='utf-8')+ self.assertIn('void *dm_game_menu(void)', launcher_m)+ build_app_src = (QT / 'nspb_qt/win/build_app.py').read_text(encoding='utf-8')+ self.assertIn('host_msl_gen.h', build_app_src)++ def test_xcrun_shim_splits_compile_and_link_for_metal_without_c_flag(self) -> None:+ from nspb_qt.win import xcrun_shim+ calls: list[list[str]] = []++ def fake_run(cmd, *a, **k):+ calls.append([str(c) for c in cmd])+ return subprocess.CompletedProcess(cmd, 0)++ with mock.patch.object(xcrun_shim, 'find', side_effect=lambda sdk, tool: Path(f'C:/metal/{tool}.exe')), \+ mock.patch.object(subprocess, 'run', side_effect=fake_run):+ rc = xcrun_shim.main(['-sdk', 'iphoneos', 'metal', '-mios-version-min=18.0',+ '-o', 'C:/tmp/clear_depth.metallib', 'C:/src/clear_depth.metal'])+ self.assertEqual(rc, 0)+ self.assertEqual(len(calls), 2)+ self.assertEqual(calls[0][0], 'C:/metal/metal.exe')+ self.assertIn('-c', calls[0])+ self.assertIn('C:/tmp/clear_depth.metallib.air', calls[0])+ self.assertEqual(calls[1], ['C:/metal/metallib.exe', 'C:/tmp/clear_depth.metallib.air',+ '-o', 'C:/tmp/clear_depth.metallib'])+if __name__ == '__main__':unittest.main(verbosity=2)