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
fix(win): stage Metal shader compiles when game or build paths contain non-ASCII characters
LNPANDY9e6b5a96cc44
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b2fd3c6b..460c853c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,7 +6,7 @@ Newest first. The fork follows upstream daily, so its game list and host fixes a| Date | Version | What changed ||---|---|---|-| 2026-11-06 | v1.2.2 | **New**: the experimental builder (Settings, Use experimental builder) now builds the whole game with nxbuild: the launcher runs `nxb build` and does not run the build script at all, for a Mac app and for the iPhone and iPad options. It reads NSP, NSZ, XCI, merged packages, a NUP, a game folder and DLC, and surveys a game with no profile. There is no fallback to the script: a case nxb does not take, or a failure, shows nxb's exit code and its last error line. It needs nxb 0.5.1 or newer, which the app bundles when its release is pinned. The setting is off by default and nothing changes for a default build. Not yet run on a device: the iPhone and iPad path, and the new input kinds on real game files (#749, #794). **Fixed**: building an NVN game for the shared iPhone and iPad app no longer stops at `FAIL: copy the shader libraries` after the engine packed the shader library into `b-<chain>.img`, reported by @zhukangyu26-stack, @tnt739660506-prog and @caixukun1919810114514, by @xiaofeng-han (#781, #795, #800, #782). On Windows, building from an extracted game folder no longer stops at `pack v...` with `FileNotFoundError: [WinError 2]` on `cp -c`, the shader split no longer fails with `ValueError: max_workers must be <= 61` on a PC with 32 or more CPU threads, and a fresh install opens the first-run setup assistant automatically |+| 2026-11-06 | v1.2.2 | **New**: the experimental builder (Settings, Use experimental builder) now builds the whole game with nxbuild: the launcher runs `nxb build` and does not run the build script at all, for a Mac app and for the iPhone and iPad options. It reads NSP, NSZ, XCI, merged packages, a NUP, a game folder and DLC, and surveys a game with no profile. There is no fallback to the script: a case nxb does not take, or a failure, shows nxb's exit code and its last error line. It needs nxb 0.5.1 or newer, which the app bundles when its release is pinned. The setting is off by default and nothing changes for a default build. Not yet run on a device: the iPhone and iPad path, and the new input kinds on real game files (#749, #794). **Fixed**: building an NVN game for the shared iPhone and iPad app no longer stops at `FAIL: copy the shader libraries` after the engine packed the shader library into `b-<chain>.img`, reported by @zhukangyu26-stack, @tnt739660506-prog and @caixukun1919810114514, by @xiaofeng-han (#781, #795, #800, #782). On Windows, building from an extracted game folder no longer stops at `pack v...` with `FileNotFoundError: [WinError 2]` on `cp -c`, the shader split no longer fails with `ValueError: max_workers must be <= 61` on a PC with 32 or more CPU threads, a game or build folder with Chinese or other non-ASCII characters no longer fails at `[5/7] iOS shaders` with `no iOS shader libraries`, and a fresh install opens the first-run setup assistant automatically (#803) || 2026-11-06 | v1.2.1 | **New**: Steam Controller (2026) over USB-C, Bluetooth and the Puck, with per-game mappings in the launcher, games must be rebuilt, by @thehobbit85 (#764, #731). A note in Launch options that says why a game has no resolution setting, by @Haseenesss (#574, #754). **Fixed**: the Mac launcher builds a Switch 2 NUP or a game folder of a game with no profile when the engine can survey it, the game itself does not run yet and needs upstream work (seedds/nxnative#1299), the Qt launcher still refuses it, reported by @xdgpx (#748, #783). The Mac host build uses the selected Python, reported by @temmiegreen, by @thehobbit85 (#711, #729). Windows finds `python.exe` in the install folder when it chains into the venv (#774). 20 Italian shell texts reworded by @zatteogit (#744). The README says Switch 2 games need no `prod.keys`, by @rivitt (#734). The compatibility switch for older iPhones and iPads writes the key the game reads, by @thehobbit85 (#719, #723). Build progress and log stay across launcher windows, by @thehobbit85 (#405, #724). A failure row for low disk space while building the Metal archive, by @thehobbit85 (#463, #725). `DM_PSO_BUNDLE=off` from env files works on iPhone and iPad, by @thehobbit85 (#726). The Tool tests job reports engine test failures and the shell and language-row tests are repaired (#690, #698, #722, #727, #728, #786) || 2026-11-05 | v1.2.0 | **Fixed**: wrong library covers such as a Switch 2 Edition or a bundle instead of the game, 164 of 167 titles with several shop products now pick the game, reported by @zatteogit (#403, #632). About 120 iPhone shell texts that were English in German, Swedish, French and Italian, and three error messages that were English everywhere, now in six languages, machine translated and waiting for review (#631). SideStore installs of a shared IPA with a very large shader tree, by @Silverhza (#587, #593). iPhone Duo rotation and the tabletop layout, by @jonochocki (#642). Game files with an upper case extension (#554). Games in a subfolder whose update or DLC sits in a sibling subfolder (#760, #762). The Mac app build on a disk without an atomic swap (#595, #742). The game language row for a Switch 2 game with a NUP update (#619). The game language row for a Switch 2 game with no control data, read from the game's own files, on the Mac and on iPhone and iPad (#668, #693). The iPhone quit prompt text (#620), the game data out of the iCloud backup (#618), the iPhone and iPad shell controller input order and tap echo guard by @Haseenesss (#660), the console mode pointer staying hidden while a game starts by @Haseenesss (#380, #741), the Windows engine recovery crash (#613), and the Windows Python install chaining directly into the venv and offline wheels setup plus 1.2 engine `tree_tar` and single-file shader library support (#765, #772). The stale shader notice popup for both reasons, texts waiting for a native review, by @djdev0010 (#320, #470). **New**: engine pin `777a5f6c618a` with 105 upstream commits, Mario Kart World, Mario Tennis Fever, Super Mario 3D All-Stars and more (#689), and `7249ee9f95ed` with 28 more upstream commits, Star Fox (Switch 2), Yoshi and the Mysterious Book (Switch 2) and DRAGON QUEST BUILDERS 2 at 60 fps, up to 120 fps for Fire Emblem Fortune's Weave and Mario & Luigi: Brothership, and single-file shader libraries and compile caches, by upstream's notes and not played by us, built games are rebuilt on the first Play (#712, #761). The Windows release (`NX2Apple-windows-x64.zip`) on the releases page with the 1.2.0 interface, the bundled engine tree so a Windows player needs no git, multi-core parallel NSO rewriting, cache management and an in-place iPhoneOS 27.2 SDK upgrade (#615, #616, #765, #768, #771, #772). Each iPhone and iPad game framework carries its own host binary (`loader: "FH"`), so future engine updates no longer require rebuilding existing games before they can start (#451, #756). Experimental builder (`nxbuild 0.2.0`, off by default) for Rust extraction and shader splitting of NSP, XCI, NSZ, dump folders and Switch 2 `.nup` packages (#749, #752, #766, #767). Split a Bluetooth Joy-Con pair into two sideways controllers on the Mac (#740, #745, #770). iPhone Duo side column for the chips and Back (#622, #633). "Preparing game…" after Play, by @Silverhza (#652). 24 Italian texts reworded, by @zatteogit and @Dino0005 (#687, #704). The .NET check follows the dotnet the build runs, by @oliphantaaron (#342). **Known issues**: of the Switch 2 games only Donkey Kong Bananza was tried, through the launcher on a Mac, an iPhone and an iPad (#445), the Switch 2 game language list is not seen on a device and has no Thai or Polish (#693), of the Switch 2 games only Donkey Kong Bananza has a store cover (#632), and the Duo side column is only checked in the Simulator (#622) || 2026-11-03 | v1.1.0 | **Switch 2 games in the launcher** (#603, #604, #605, #606, #607, #608, #609, #610): the Mac and the Windows launcher take a Switch 2 game folder or a `.nup` file, with no `prod.keys`. Games get a Switch 2 mark and a note for the chosen target, the build stages have names in every language, and a failure row says when the keys are older than the game. Nobody has played one through the launcher yet. **Touch controls** (#582, #581, #580, #600): a size setting, a left stick place, a hint for the right stick of the 3D layout, and an editor in the shell settings that moves each control. **Quit and delete**: hold the controller's Home button for 2 seconds to quit a Mac game on macOS 27 (#579). On iPhone and iPad, the gear menu in the game or a Home hold quits, and the app closes and opens on the library (#601). Delete a game from the launcher, with its saves kept unless chosen (#562). **Also new**: Cloud saves folder in the Mac launcher (#561), Start in console mode (#565), controller button mapping on iPhone and iPad by @Haseenesss (#495, #576), picture Fill or Fit (#575), iPhone Duo layouts by @jonochocki (#230), per-game mods and env.txt (#573, #566), moving the cache folder (#584, #567), the Finder way to send game data (#586), a clearer framework error (#568). **Engine pin** `641d1480021a` (#598): new Switch 2 and other games, by upstream's notes, not played by us. **Fixed**: NSPs without a title ID in the file name by @Haseenesss (#548), the Duo outer screen row (#563), the Windows IPA handoff by @tmrsm (#182), the Windows first sync (#597, #602). **Docs**: README in German, Swedish and French (#569), Italian documents by @PikaMan80 (#527), Italian texts reviewed by @Dino0005 (#541, #570). Requires macOS 27 for the Home quit. |diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.mdindex cdc37038..315dfc0c 100644--- a/CHANGELOG.zh-CN.md+++ b/CHANGELOG.zh-CN.md@@ -6,7 +6,7 @@ NX2Apple 的版本历史,最新在上,每个版本的完整说明见[发布| 日期 | 版本 | 变更 ||---|---|---|-| 2026-11-06 | v1.2.2 | **新增**:实验性构建器(设置里的「使用实验性构建器」)现在用 nxbuild 构建整个游戏:启动器直接运行 `nxb build`,完全不运行构建脚本,Mac App 和 iPhone、iPad 选项都是如此。它读取 NSP、NSZ、XCI、合并包、NUP、游戏文件夹和 DLC,并勘测没有配置的游戏。不会退回脚本:nxb 不支持的情况或失败时,会显示 nxb 的退出代码和最后一条错误。需要 nxb 0.5.1 或更新版本,固定版本后 App 会自带。该设置默认关闭,默认构建不受影响。尚未在真机上运行:iPhone 和 iPad 路径,以及真实游戏文件的新输入类型(#749、#794)。**修复**:引擎把 NVN 游戏的着色器库打包成单个文件 `b-<chain>.img` 后,为共用 iPhone 和 iPad 壳 App 构建游戏不再在 `FAIL: copy the shader libraries` 处停止,由 @zhukangyu26-stack、@tnt739660506-prog 和 @caixukun1919810114514 报告,作者 @xiaofeng-han(#781、#795、#800、#782)。Windows 上从解压的游戏文件夹构建不再因 `cp -c` 在 `pack v...` 阶段报 `FileNotFoundError: [WinError 2]`,32 线程及以上 CPU 在 `shader split` 阶段不再报 `ValueError: max_workers must be <= 61`,全新首次启动时会自动弹出设置向导 |+| 2026-11-06 | v1.2.2 | **新增**:实验性构建器(设置里的「使用实验性构建器」)现在用 nxbuild 构建整个游戏:启动器直接运行 `nxb build`,完全不运行构建脚本,Mac App 和 iPhone、iPad 选项都是如此。它读取 NSP、NSZ、XCI、合并包、NUP、游戏文件夹和 DLC,并勘测没有配置的游戏。不会退回脚本:nxb 不支持的情况或失败时,会显示 nxb 的退出代码和最后一条错误。需要 nxb 0.5.1 或更新版本,固定版本后 App 会自带。该设置默认关闭,默认构建不受影响。尚未在真机上运行:iPhone 和 iPad 路径,以及真实游戏文件的新输入类型(#749、#794)。**修复**:引擎把 NVN 游戏的着色器库打包成单个文件 `b-<chain>.img` 后,为共用 iPhone 和 iPad 壳 App 构建游戏不再在 `FAIL: copy the shader libraries` 处停止,由 @zhukangyu26-stack、@tnt739660506-prog 和 @caixukun1919810114514 报告,作者 @xiaofeng-han(#781、#795、#800、#782)。Windows 上从解压的游戏文件夹构建不再因 `cp -c` 在 `pack v...` 阶段报 `FileNotFoundError: [WinError 2]`,32 线程及以上 CPU 在 `shader split` 阶段不再报 `ValueError: max_workers must be <= 61`,包含中文或其他非 ASCII 字符的游戏目录或构建目录不再在 `[5/7] iOS shaders` 阶段报 `no iOS shader libraries`,全新首次启动时会自动弹出设置向导(#803) || 2026-11-06 | v1.2.1 | **新增**:Steam Controller(2026)支持 USB-C、蓝牙和 Puck,启动器里有每个游戏的映射,旧游戏需要重新构建,作者 @thehobbit85(#764、#731)。启动选项里新增说明游戏为什么没有分辨率设置的提示,作者 @Haseenesss(#574、#754)。**修复**:引擎能勘测游戏时,Mac 启动器可以构建没有配置的 Switch 2 NUP 或游戏文件夹,游戏本身还不能运行,需要上游的工作(seedds/nxnative#1299),Qt 启动器仍然拒绝,由 @xdgpx 报告(#748、#783)。Mac 宿主构建使用所选的 Python,由 @temmiegreen 报告,作者 @thehobbit85(#711、#729)。Windows 链接虚拟环境时在安装文件夹里找到 `python.exe`(#774)。@zatteogit 改写了 20 条意大利语壳 App 文字(#744)。README 说明 Switch 2 游戏不需要 `prod.keys`,作者 @rivitt(#734)。老 iPhone 和 iPad 的兼容开关写入游戏读取的键,作者 @thehobbit85(#719、#723)。构建进度和日志在多个启动器窗口之间保持,作者 @thehobbit85(#405、#724)。构建 Metal 归档时磁盘空间不足有了失败提示,作者 @thehobbit85(#463、#725)。env 文件里的 `DM_PSO_BUNDLE=off` 在 iPhone 和 iPad 上生效,作者 @thehobbit85(#726)。Tool tests 任务会报告引擎测试失败,壳 App 和语言行测试已修复(#690、#698、#722、#727、#728、#786) || 2026-11-05 | v1.2.0 | **修复**:游戏库封面不对(选成 Switch 2 版或套装而不是游戏本身),在有多个商店商品的 167 个游戏里 164 个现在选对,由 @zatteogit 报告(#403、#632)。约 120 条 iPhone 壳 App 文字在德语、瑞典语、法语和意大利语里是英文,另有三条错误信息在所有语言里都是英文,现已有六种语言,机器翻译,等待审校(#631)。着色器文件很多的共用 IPA 用 SideStore 安装失败,作者 @Silverhza(#587、#593)。iPhone Duo 旋转和桌面布局,作者 @jonochocki(#642)。扩展名为大写的游戏文件(#554)。子文件夹里的基础游戏与同级子文件夹里的更新或 DLC 自动关联(#760、#762)。在不支持原子替换的磁盘上构建 Mac App(#595、#742)。带 NUP 更新的 Switch 2 游戏的语言一行(#619)。没有控制数据的 Switch 2 游戏的语言一行,读自游戏自己的文件,Mac 和 iPhone、iPad 上都有(#668、#693)。iPhone 退出提示文字(#620)、游戏数据不进 iCloud 备份(#618)、iPhone 和 iPad 壳 App 手柄输入事件顺序与触控回声保护,作者 @Haseenesss(#660)、主机模式启动游戏期间鼠标指针保持隐藏,作者 @Haseenesss(#380、#741)、Windows 引擎恢复崩溃(#613),以及 Windows 安装 Python 后直接连装虚拟环境与内置离线 wheel 包、iOS 交叉构建支持 1.2 引擎 `tree_tar` 和单文件着色器库(#765、#772)。过期着色器提示在两种原因下都会弹出,文字等待母语者审校,作者 @djdev0010(#320、#470)。**新增**:引擎版本 `777a5f6c618a`(含上游 105 个提交,Mario Kart World、Mario Tennis Fever、Super Mario 3D All-Stars 等,#689)及 `7249ee9f95ed`(再进上游 28 个提交,Star Fox(Switch 2)、Yoshi and the Mysterious Book(Switch 2)和 DRAGON QUEST BUILDERS 2 60 帧,Fire Emblem Fortune's Weave 和 Mario & Luigi: Brothership 最高 120 帧,单文件着色器库与编译缓存,#712、#761),按上游的说明,我们没有玩过,已构建的游戏第一次点 Play 会重新构建。Windows 正式版(`NX2Apple-windows-x64.zip`)随发布页提供,对齐 1.2.0 界面并自带引擎目录(Windows 玩家不需要 git),支持多核并行 NSO 重写、缓存管理及就地升级到 iPhoneOS 27.2 SDK(#615、#616、#765、#768、#771、#772)。iPhone 和 iPad 每个游戏框架自带独立宿主二进制(`loader: "FH"`),后续引擎更新不再强制已构建游戏重新构建才能启动(#451、#756)。实验性构建器(`nxbuild 0.2.0`,默认关闭),用 Rust 快速完成 NSP、XCI、NSZ、解包目录及 Switch 2 `.nup` 软件包的解包与着色器拆分(#749、#752、#766、#767)。Mac 端支持将一对蓝牙 Joy-Con 拆分为两个独立横握手柄(#740、#745、#770)。iPhone Duo 侧边栏放置按钮和返回键(#622、#633)。点 Play 后显示「Preparing game…」,作者 @Silverhza(#652)。24 条意大利语文字改写,作者 @zatteogit 和 @Dino0005(#687、#704)。「.NET 检查」跟随构建实际使用的 dotnet,作者 @oliphantaaron(#342)。**已知问题**:Switch 2 游戏里只试过 Donkey Kong Bananza,通过启动器在 Mac、iPhone 和 iPad 上玩过(#445),Switch 2 游戏的语言列表没有在真机上看过,也没有泰语和波兰语(#693),Switch 2 游戏里只有 Donkey Kong Bananza 有商店封面(#632),Duo 侧边栏只在模拟器里检查过(#622) || 2026-11-03 | v1.1.0 | **启动器里的 Switch 2 游戏**(#603、#604、#605、#606、#607、#608、#609、#610):Mac 和 Windows 启动器可以选择 Switch 2 游戏文件夹或 `.nup` 文件,不需要 `prod.keys`。游戏带 Switch 2 标记和按目标显示的说明,构建阶段的名称有所有语言的版本,密钥比游戏旧时有专门的失败提示。还没有人通过启动器玩过。**触控按键**(#582、#581、#580、#600):大小设置、左摇杆位置、3D 布局右摇杆的提示,以及壳 App 设置里移动每个按键的编辑器。**退出和删除**:在 macOS 27 上按住手柄 Home 键 2 秒退出 Mac 游戏(#579)。在 iPhone 和 iPad 上,从游戏内齿轮菜单或按住 Home 退出,App 会关闭并在下次回到游戏库(#601)。在启动器里删除游戏,除非选择一并删除,否则存档保留(#562)。**其他新增**:Mac 启动器的云存档文件夹(#561)、启动时进入主机模式(#565)、iPhone 和 iPad 的手柄按键映射,作者 @Haseenesss(#495、#576)、画面填充或适应(#575)、iPhone Duo 布局,作者 @jonochocki(#230)、每个游戏的 mod 和 env.txt(#573、#566)、移动缓存文件夹(#584、#567)、用 Finder 发送游戏数据(#586)、更清楚的框架错误(#568)。**引擎固定点** `641d1480021a`(#598):新增 Switch 2 等游戏,出自上游的说明,我们没有玩过。**修复**:文件名里没有 title ID 的 NSP,作者 @Haseenesss(#548)、Duo 外屏的游戏行(#563)、Windows 的 IPA 交接,作者 @tmrsm(#182)、Windows 首次同步(#597、#602)。**文档**:德语、瑞典语和法语 README(#569)、意大利语文档,作者 @PikaMan80(#527)、由 @Dino0005 审校的意大利语文字(#541、#570)。用 Home 键退出需要 macOS 27。 |diff --git a/frontend-qt/nspb_qt/win/shim.py b/frontend-qt/nspb_qt/win/shim.pyindex 498e4361..dc200945 100644--- a/frontend-qt/nspb_qt/win/shim.py+++ b/frontend-qt/nspb_qt/win/shim.py@@ -454,6 +454,45 @@ if os.name == 'nt' and not os.environ.get('NSPB_SHIM_OFF'):mod._lock = lambda folder, say=None: Truemod._unlock = lambda folder: None+ def _ascii_temp_base():+ if _PKG not in sys.path:+ sys.path.insert(0, _PKG)+ import toolchain as _tc+ with _tc.ascii_temp_dir('nspb-probe-') as _p:+ return os.path.dirname(str(_p))++ def _patch_dmsh_pch_module(mod):+ if getattr(mod, '_nspb_patched', False) or not hasattr(mod, 'tempfile'):+ return+ mod._nspb_patched = True+ _orig_tf = mod.tempfile++ class _PchTempfile:+ def __getattr__(self, k):+ return getattr(_orig_tf, k)++ def mkdtemp(self, suffix=None, prefix=None, dir=None):+ if dir and (' ' in str(dir) or not str(dir).isascii()):+ dir = _ascii_temp_base()+ return _orig_tf.mkdtemp(suffix=suffix, prefix=prefix, dir=dir)++ mod.tempfile = _PchTempfile()++ def _patch_dmsh_mtlcache_module(mod):+ if getattr(mod, '_nspb_patched', False) or not hasattr(mod, 'Cache'):+ return+ mod._nspb_patched = True+ _orig_init = mod.Cache.__init__++ def _win_cache_init(self, store, targets, work):+ if work and (' ' in str(work) or not str(work).isascii()):+ import tempfile as _tf, atexit as _atexit+ work = _tf.mkdtemp(prefix='mtlwork_', dir=_ascii_temp_base())+ _atexit.register(shutil.rmtree, work, ignore_errors=True)+ _orig_init(self, store, targets, work)++ mod.Cache.__init__ = _win_cache_init+import importlib.machinery as _machinery_exec_module = _machinery.SourceFileLoader.exec_module@@ -470,6 +509,10 @@ if os.name == 'nt' and not os.environ.get('NSPB_SHIM_OFF'):_patch_tree_tar_module(module)elif name == 'pack_dump' or name.endswith('.pack_dump'):module.clone = shutil.copy2+ elif name == 'dmsh_pch' or name.endswith('.dmsh_pch'):+ _patch_dmsh_pch_module(module)+ elif name == 'dmsh_mtlcache' or name.endswith('.dmsh_mtlcache'):+ _patch_dmsh_mtlcache_module(module)_machinery.SourceFileLoader.exec_module = _win_exec_module@@ -560,8 +603,8 @@ if os.name == 'nt' and not os.environ.get('NSPB_SHIM_OFF'):return Noneif 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.py- if any(' ' in str(a) for a in rest[3:]):- return None # paths with spaces break metal.exe; xcrun_shim.py stages them via cwd+ if any(' ' in str(a) or not str(a).isascii() for a in rest[3:]):+ return None # paths with spaces or non-ASCII chars break metal.exe; xcrun_shim.py stages them via cwdif '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 69d76f4f..5471c152 100644--- a/frontend-qt/nspb_qt/win/toolchain.py+++ b/frontend-qt/nspb_qt/win/toolchain.py@@ -249,7 +249,7 @@ def no_window() -> dict:def config_path() -> Path:"""`toolchain.json` in the app's data folder (shared with the venv location)."""- base = Path(os.environ.get('LOCALAPPDATA', Path.home() / 'AppData' / 'Local'))+ base = Path(os.environ.get('LOCALAPPDATA') or (Path.home() / 'AppData' / 'Local'))return base / 'NS Port Builder' / 'toolchain.json'@@ -987,16 +987,18 @@ def ascii_temp_dir(prefix: str = 'nspb-'):except UnicodeEncodeError:return Falsecandidates = [tempfile.gettempdir()]- if os.name == 'nt':- candidates += [os.environ.get('PUBLIC', r'C:\Users\Public') + r'\Temp', r'C:\Windows\Temp', 'C:\\Temp']- for base in candidates:- if not base or not ok(base):- continue- try:- os.makedirs(base, exist_ok=True)- return _tf.TemporaryDirectory(prefix=prefix, dir=base)- except OSError:- continue+ if os.name == 'nt' or 'PUBLIC' in os.environ:+ candidates += [os.environ.get('PUBLIC', r'C:\Users\Public') + (r'\Temp' if os.name == 'nt' else '/Temp'),+ r'C:\Windows\Temp', 'C:\\Temp']+ for allow_space in (False, True):+ for base in candidates:+ if not base or not ok(base) or (not allow_space and ' ' in base):+ continue+ try:+ os.makedirs(base, exist_ok=True)+ return _tf.TemporaryDirectory(prefix=prefix, dir=base)+ except OSError:+ continue# Nothing ASCII is writable: fall back to the default (created first — the caller may be on a# system where gettempdir() names a folder that does not exist yet) and let the tool say what# it says.diff --git a/frontend-qt/nspb_qt/win/xcrun_shim.py b/frontend-qt/nspb_qt/win/xcrun_shim.pyindex 28358d90..2873d516 100644--- a/frontend-qt/nspb_qt/win/xcrun_shim.py+++ b/frontend-qt/nspb_qt/win/xcrun_shim.py@@ -138,20 +138,30 @@ def _die(msg: str, code: int = 127) -> None:raise SystemExit(code)+def _needs_staging(arg: str) -> bool:+ """Whether `arg` contains spaces or non-ASCII characters that break `metal.exe` / `metallib.exe`."""+ return ' ' in arg or not arg.isascii()+++def _safe_suffix(p: Path, default: str) -> str:+ sfx = p.suffix+ return sfx if (sfx and not _needs_staging(sfx)) else default++def _run_metal_staged(sdk: str, tool: str, exe: Path, rest: list[str]) -> int:- """Run `metal.exe` or `metallib.exe` in a staging directory using space-free relative names.-- Apple's Windows `metal.exe` splits input paths on spaces when forwarding them to its internal- frontend (e.g. `.../NS Port Builder/engine/dm/gfx/msl/builtin.metal` becomes three arguments- `.../NS`, `Port`, `Builder/...`). Staging inputs and outputs in `cwd` with plain filenames- (`in_0.metal`, `out.air`, `out.metallib`) keeps every argument passed to `metal.exe` and- `metallib.exe` completely free of spaces, even when the app folder, temp folder or user- profile path contains spaces.+ """Run `metal.exe` or `metallib.exe` in a pure-ASCII, space-free staging directory.++ Apple's Windows `metal.exe` and `metallib.exe` split input paths on spaces when forwarding+ them to their internal frontend and fail with `LLVM ERROR: Error opening '<path>'` when any+ input or output path contains non-ASCII characters (such as Chinese folder names). Staging+ inputs and outputs in a pure-ASCII `cwd` with plain filenames (`in_0.metal`, `out.air`,+ `out.metallib`) keeps every argument passed to `metal.exe` and `metallib.exe` completely+ ASCII and space-free."""idx = rest.index('-o')out_target = Path(rest[idx + 1]).resolve()compile_and_link = (tool == 'metal' and '-c' not in rest)- with tempfile.TemporaryDirectory() as td:+ with tc.ascii_temp_dir('nspb-metal-') as td:td_path = Path(td)staged: list[str] = []in_idx = 0@@ -161,10 +171,29 @@ def _run_metal_staged(sdk: str, tool: str, exe: Path, rest: list[str]) -> int:i += 2 # skip '-o' and its output path; added back below with a local namecontinuea = rest[i]- if not a.startswith('-') and (a.endswith(('.metal', '.air', '.dia', '.pch'))- or (' ' in a and Path(a).is_file())):+ if a == '-include-pch' and i + 1 < len(rest):+ pch_arg = rest[i + 1]+ pch_p = Path(pch_arg)+ if not _needs_staging(pch_arg) and pch_p.is_absolute():+ staged.extend(['-include-pch', pch_arg])+ else:+ local_pch = pch_p.name if not _needs_staging(pch_p.name) else f'in_{in_idx}.pch'+ in_idx += 1+ if pch_p.is_file():+ shutil.copyfile(pch_p, td_path / local_pch)+ for hdr in pch_p.parent.glob('*.h'):+ if not _needs_staging(hdr.name):+ shutil.copyfile(hdr, td_path / hdr.name)+ staged.extend(['-include-pch', local_pch])+ i += 2+ continue+ if not a.startswith('-') and (a.endswith(('.metal', '.air', '.dia', '.pch', '.h'))+ or (_needs_staging(a) and Path(a).is_file())):src_p = Path(a)- local_name = f'in_{in_idx}{src_p.suffix or ".in"}'+ if src_p.suffix == '.h' and not _needs_staging(src_p.name) and not (td_path / src_p.name).exists():+ local_name = src_p.name+ else:+ local_name = f'in_{in_idx}{_safe_suffix(src_p, ".in")}'in_idx += 1if src_p.is_file():shutil.copyfile(src_p, td_path / local_name)@@ -185,7 +214,7 @@ def _run_metal_staged(sdk: str, tool: str, exe: Path, rest: list[str]) -> int:return r2.returncodeout_local = td_path / 'out.metallib'else:- local_out_name = 'out' + (out_target.suffix or '.out')+ local_out_name = 'out' + _safe_suffix(out_target, '.out')r = subprocess.run([str(exe), *staged, '-o', local_out_name], cwd=td)if r.returncode != 0:return r.returncode@@ -233,10 +262,10 @@ 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 '-o' in rest and ('-c' not in rest or any(' ' in x for x in rest)):+ if '-o' in rest and ('-c' not in rest or any(_needs_staging(x) for x in rest)):return _run_metal_staged(sdk, tool, exe, rest)elif tool == 'metallib':- if '-o' in rest and any(' ' in x for x in rest):+ if '-o' in rest and any(_needs_staging(x) for x in rest):return _run_metal_staged(sdk, tool, exe, rest)elif tool == 'clang':rest = clang_args(rest)diff --git a/frontend-qt/tests/test_ascii_temp.py b/frontend-qt/tests/test_ascii_temp.pyindex d86e7d74..42d88927 100644--- a/frontend-qt/tests/test_ascii_temp.py+++ b/frontend-qt/tests/test_ascii_temp.py@@ -42,6 +42,15 @@ class AsciiTempDir(unittest.TestCase):self.assertTrue(ascii_only(str(d)), f'{d} is not ASCII')self.assertNotIn('中文', str(d))+ def test_a_temp_with_spaces_is_skipped_when_a_space_free_ascii_one_exists(self):+ """metal.exe splits paths on spaces; ascii_temp_dir prefers a space-free ASCII folder."""+ with mock.patch.object(tempfile, 'gettempdir', return_value='/tmp/My User'), \+ mock.patch.object(toolchain.os, 'name', 'nt'), \+ mock.patch.dict(os.environ, {'PUBLIC': '/tmp'}):+ with toolchain.ascii_temp_dir('probe-') as d:+ self.assertTrue(ascii_only(str(d)), f'{d} is not ASCII')+ self.assertNotIn(' ', str(d))+def test_it_still_yields_a_directory_when_nothing_is_ascii(self):"""No ASCII option: a directory is still created, so the tool can fail on its own terms."""with mock.patch.object(tempfile, 'gettempdir', return_value='/tmp/中文名'), \diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.pyindex 931a279c..c9643acb 100644--- a/frontend-qt/tests/test_win.py+++ b/frontend-qt/tests/test_win.py@@ -2817,6 +2817,84 @@ class WindowsBuildFixesTest(unittest.TestCase):self.assertTrue(m.settings_value('onboardingComplete', False))self.assertFalse(should_show(m))+ def test_non_ascii_paths_stage_metal_and_metallib_via_ascii_temp_dir(self) -> None:+ """Chinese folder names (e.g. C:\\Games\\星露谷物语\\nsp本体\\...) must be staged via an ASCII temp dir."""+ from nspb_qt.win import xcrun_shim+ with tempfile.TemporaryDirectory() as td:+ root = Path(td)+ ascii_fallback = root / 'ascii_tmp'+ ascii_fallback.mkdir()+ zh_build = root / '星露谷物语' / 'nsp本体' / '0100E65002BB8000_build'+ zh_ios = zh_build / 'shader' / 'ios' / 'b-223f10d34f97'+ zh_ios.mkdir(parents=True)+ zh_msl = zh_build / 'dmsh_123' / '0000000000000001.metal'+ zh_msl.parent.mkdir(parents=True)+ zh_msl.write_text('#include <metal_stdlib>\n', encoding='utf-8')+ zh_air = zh_build / 'dmsh_123' / '0000000000000001.air'+ zh_lib = zh_ios / '0000000000000001_b.metallib.tmp-999'++ seen_calls: list[tuple[list[str], str]] = []++ def strict_metal_run(cmd, *a, **kw):+ cwd = str(kw.get('cwd') or '')+ args = [str(x) for x in cmd]+ seen_calls.append((args, cwd))+ for token in args + ([cwd] if cwd else []):+ if not token.isascii() or ' ' in token:+ return subprocess.CompletedProcess(+ cmd, 1, '', f"LLVM ERROR: Error opening '{token}': Invalid argument\n")+ if '-o' in args:+ out_name = args[args.index('-o') + 1]+ out_p = (Path(cwd) / out_name) if cwd and not Path(out_name).is_absolute() else Path(out_name)+ out_p.write_bytes(b'MTLB_OK')+ return subprocess.CompletedProcess(cmd, 0, '', '')++ with mock.patch.object(tc, 'metal_tool', side_effect=lambda name, *a: Path(f'/opt/metal/{name}.exe')), \+ mock.patch.object(tempfile, 'gettempdir', return_value=str(root / '中文用户' / 'Temp')), \+ mock.patch.dict(os.environ, {'PUBLIC': str(ascii_fallback), 'LOCALAPPDATA': str(root / 'local')}, clear=False), \+ mock.patch.object(xcrun_shim.subprocess, 'run', side_effect=strict_metal_run):+ rc1 = xcrun_shim.main(['-sdk', 'iphoneos', 'metal', '-c', str(zh_msl), '-o', str(zh_air)])+ self.assertEqual(rc1, 0)+ self.assertTrue(zh_air.is_file(), 'staged metal compile must copy .air back to Chinese path')+ rc2 = xcrun_shim.main(['-sdk', 'iphoneos', 'metallib', str(zh_air), '-o', str(zh_lib)])+ self.assertEqual(rc2, 0)+ self.assertTrue(zh_lib.is_file(), 'staged metallib must copy .metallib back to Chinese path')+ self.assertEqual(zh_lib.read_bytes(), b'MTLB_OK')+ self.assertEqual(len(seen_calls), 2)++ # Verify sitecustomize._resolve rejects non-ASCII args so they go to xcrun_shim,+ # and dmsh_pch / dmsh_mtlcache redirect Chinese WORK folders to pure-ASCII temp dirs.+ sd = root / 'shim'+ shim.install(sd, python_exe=sys.executable)+ sc = (sd / 'sitecustomize.py').read_text(encoding='utf-8').replace(+ "if os.name == 'nt'", "if True", 1)+ (sd / 'sitecustomize.py').write_text(sc, encoding='utf-8')+ code = (+ "import os, sys, types\n"+ "import sitecustomize\n"+ f"zh_lib = {str(zh_lib)!r}\n"+ "assert sitecustomize._resolve(['-sdk', 'iphoneos', 'metallib', 'a.air', '-o', zh_lib]) is None\n"+ "import importlib.machinery as mach, tempfile\n"+ "pch_mod = types.ModuleType('dmsh_pch')\n"+ "pch_mod.tempfile = tempfile\n"+ "sitecustomize._patch_dmsh_pch_module(pch_mod)\n"+ f"d = pch_mod.tempfile.mkdtemp(prefix='pch_', dir={str(zh_build)!r})\n"+ "assert d.isascii() and ' ' not in d, d\n"+ "os.rmdir(d)\n"+ "mtl_mod = types.ModuleType('dmsh_mtlcache')\n"+ "class Cache:\n"+ " def __init__(self, store, targets, work):\n"+ " self.work = work\n"+ "mtl_mod.Cache = Cache\n"+ "sitecustomize._patch_dmsh_mtlcache_module(mtl_mod)\n"+ f"c = mtl_mod.Cache(None, {{}}, {str(zh_build)!r})\n"+ "assert c.work.isascii() and ' ' not in c.work, c.work\n"+ )+ r = subprocess.run([sys.executable, '-S', '-c', code],+ env={**os.environ, 'PYTHONPATH': str(sd)},+ capture_output=True, text=True)+ self.assertEqual(r.returncode, 0, r.stderr)+if __name__ == '__main__':unittest.main(verbosity=2)diff --git a/release-notes/v1.2.2.md b/release-notes/v1.2.2.mdindex 8c27f828..cf516486 100644--- a/release-notes/v1.2.2.md+++ b/release-notes/v1.2.2.md@@ -9,6 +9,7 @@- **iPhone and iPad shared app build (`FAIL: copy the shader libraries`)**: since the 1.2.0 engine pin `7249ee9f95ed`, an NVN game's iOS shader library is packed into the single file `shader/ios/b-<chain>.img` and the folder `b-<chain>/` is removed. The framework build step for the shared iPhone and iPad app still looked for the folder, so every NVN game build for the shared shell stopped at `rsync: .../shader/ios/b-223f10d34f97/: (l)stat: No such file or directory` and `FAIL: copy the shader libraries`. It now copies `b-<chain>.img` into the game framework's `msl/` folder, where the host loads it. Reported by @zhukangyu26-stack, @tnt739660506-prog and @caixukun1919810114514. By @xiaofeng-han (#781, #795, #800, #782)- **Windows game folder build (`FileNotFoundError: [WinError 2]` at `pack v...`)**: `pack_dump.py` tried `cp -c` for an APFS clone before falling back to `shutil.copy2`, which raised `FileNotFoundError` on Windows where `cp` does not exist. The Windows driver and shim now copy directly without spawning `cp` or `xattr`- **Windows shader split on 32+ thread CPUs (`ValueError: max_workers must be <= 61`)**: the Windows build environment and `ProcessPoolExecutor` now cap worker count at 61, CPython's `WaitForMultipleObjects` limit on Windows+- **Windows iOS shader build in Chinese or non-ASCII folders (`no iOS shader libraries`)**: Apple's Windows `metal.exe` and `metallib.exe` fail to open paths containing non-ASCII characters or spaces. The Windows `xcrun` shim and shader cache/PCH helpers now stage non-ASCII inputs and outputs through a pure-ASCII temporary folder- **Windows first-run setup assistant**: opening the Windows launcher for the first time now presents the guided setup dialog automatically once dependency detection finishes**Known issues**@@ -27,6 +28,7 @@- **iPhone 和 iPad 共用壳 App 构建(`FAIL: copy the shader libraries`)**:从 1.2.0 的引擎版本 `7249ee9f95ed` 起,NVN 游戏的 iOS 着色器库会被打包成单个文件 `shader/ios/b-<chain>.img` 并删除原文件夹 `b-<chain>/`。共用 iPhone 和 iPad 壳 App 的框架构建步骤仍在查找原文件夹,导致所有 NVN 游戏的共用壳构建都在最后停在 `rsync: .../shader/ios/b-223f10d34f97/: (l)stat: No such file or directory` 和 `FAIL: copy the shader libraries`。现在它会把 `b-<chain>.img` 复制进游戏框架的 `msl/` 目录供宿主直接读取。由 @zhukangyu26-stack、@tnt739660506-prog 和 @caixukun1919810114514 报告。作者 @xiaofeng-han(#781、#795、#800、#782)- **Windows 游戏文件夹构建(`pack v...` 阶段报 `FileNotFoundError: [WinError 2]`)**:`pack_dump.py` 在回退到 `shutil.copy2` 前会先尝试运行 `cp -c` 做 APFS 克隆,而在没有 `cp` 命令的 Windows 上直接抛出了 `FileNotFoundError`。现在 Windows 驱动和垫片层直接复制文件,不再调用 `cp` 或 `xattr`- **Windows 32 线程及以上 CPU 在 `shader split` 阶段报 `ValueError: max_workers must be <= 61`**:Windows 构建环境与 `ProcessPoolExecutor` 现在将工作进程数上限封顶在 61(Windows 版 Python `WaitForMultipleObjects` 的硬上限)+- **Windows 中文或非 ASCII 目录构建 iOS 着色器失败(`no iOS shader libraries`)**:苹果 Windows 版 `metal.exe` 与 `metallib.exe` 无法打开含中文或空格的路径。现在 Windows `xcrun` 垫片及着色器预编译头/编译缓存会自动通过纯 ASCII 临时目录暂存并回写输入输出文件- **Windows 首次启动设置向导**:全新首次打开 Windows 启动器时,依赖检测完成后会自动弹出引导式设置向导**已知问题**