Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/build-qt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ jobs:
- name: Generate the localisation table
run: python frontend-qt/gen_localization.py

# The build packages ride in the zip: the venv step then installs from disk (--no-index),
# so a fresh machine needs no PyPI round-trip for lz4/capstone/fonttools/nsz. The runner's
# Python is the version these wheels target (3.12), matching the interpreter the app
# installs for its venv.
- name: Download the venv wheels
run: python -m pip download lz4 capstone fonttools backports.zstd nsz -d frontend-qt/wheels

- name: Build
working-directory: frontend-qt
shell: bash
Expand Down Expand Up @@ -123,6 +130,7 @@ jobs:
shell: bash
run: |
cd frontend-qt/dist
cp -r ../wheels "NS Port Builder/wheels"
powershell -Command "Compress-Archive -Path 'NS Port Builder' -DestinationPath '../NS-Port-Builder-qt-windows-x64.zip'"

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ frontend/NX2Apple.app/

# the virtual environment the README creates for the Python packages
.venv/
frontend-qt/wheels/
frontend-qt/NS-Port-Builder-qt-windows-x64.zip
10 changes: 9 additions & 1 deletion frontend-qt/nspb_qt/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,11 @@
'dep.show': ('展开', 'Show', 'Show'),
'dep.pick': ('选择文件夹…', 'Choose folder…', 'Choose folder…'),
'dep.pick.ios_sdk.title': ('选择 iPhoneOS SDK 文件夹', 'Choose the iPhoneOS SDK folder', 'Choose the iPhoneOS SDK folder'),
'dep.pick.metal_dir.title': ('选择 Metal Developer Tools 文件夹', 'Choose the Metal Developer Tools folder', 'Choose the Metal Developer Tools folder'),
'dep.pick.metal_dir.title': ('选择 Metal Developer Tools(下载的 zip 或解压后的文件夹)', 'Choose Metal Developer Tools (the downloaded zip, or the unpacked folder)', 'Choose Metal Developer Tools (the downloaded zip, or the unpacked folder)'),
'dep.pick.metal': ('选择 zip / 文件夹…', 'Choose zip / folder…', 'Choose zip / folder…'),
'dep.metal.unpacking': ('正在解压 %@…', 'Unpacking %@…', 'Unpacking %@…'),
'dep.metal.done': ('Metal Developer Tools 已安装:%@', 'Metal Developer Tools installed: %@', 'Metal Developer Tools installed: %@'),
'dep.pick.metal.invalid': ('“%@”里没有 metal.exe(需要 bin\\\\metal.exe 或 ios\\\\bin\\\\metal.exe):确认下载的是 “Metal Developer Tools for Windows”。', 'No metal.exe inside "%@" (needs bin\\\\metal.exe or ios\\\\bin\\\\metal.exe): check that the download is "Metal Developer Tools for Windows".', 'No metal.exe inside "%@" (needs bin\\\\metal.exe or ios\\\\bin\\\\metal.exe): check that the download is "Metal Developer Tools for Windows".'),
'dep.pick.saved': ('已记住:%@', 'Remembered: %@', 'Remembered: %@'),
'dep.pick.iossdk.saved': ('SDK 已记住:%@', 'SDK remembered: %@', 'SDK remembered: %@'),
'dep.pick.iossdk.version': ('SDK 版本:%@', 'SDK version: %@', 'SDK version: %@'),
Expand All @@ -634,6 +638,10 @@
'dep.fix.brewMissing': ('没装 Homebrew:从 brew.sh 安装(安装程序会要你的密码),再点「重新检测」。', 'Homebrew is not installed: install it from brew.sh (the installer asks for your password), then press Check again.', 'Homebrew är inte installerat. Installera från brew.sh. Installationsprogrammet ber om ditt lösenord. Välj sedan ”Kontrollera igen”.'),
'dep.fix.xcodeLicense': ('Xcode 的许可协议还没接受:运行 sudo xcodebuild -license accept。', "Xcode's license is not accepted yet: run sudo xcodebuild -license accept.", 'Xcodes licensavtal är inte godkänt. Kör sudo xcodebuild -license accept.'),
'dep.fix.network': ('下载失败了:检查网络(代理或 VPN 可能拦住了 Homebrew 的域名),再试一次。', "The download failed: check the network (a proxy or VPN can block Homebrew's hosts) and try again.", 'Hämtningen misslyckades. Kontrollera nätverket; proxy eller VPN kan blockera Homebrews domäner. Försök sedan igen.'),
'dep.git.downloading': ('正在下载 PortableGit(SDK 下载需要它,约 45 MB)…', 'Downloading PortableGit (the SDK download needs it, about 45 MB)…', 'Downloading PortableGit (the SDK download needs it, about 45 MB)…'),
'dep.git.done': ('PortableGit 已安装:%@', 'PortableGit installed: %@', 'PortableGit installed: %@'),
'dep.fix.nonascii': ('SDK 所在路径含非英文字符(比如用户名里的中文):ld64.lld 在 Windows 上可能因此打不开 SDK 文件。把整个 SDK 文件夹拷到一个纯英文路径(如 C:\\\\NSPB\\\\sdk),然后在依赖面板用「选择文件夹…」指向它。', "The SDK path contains non-ASCII characters (a Chinese username, for example): ld64.lld on Windows may fail to open it. Copy the whole SDK folder to an ASCII-only path (e.g. C:\\\\NSPB\\\\sdk) and point the dependencies panel's Choose folder… at it.", "The SDK path contains non-ASCII characters (a Chinese username, for example): ld64.lld on Windows may fail to open it. Copy the whole SDK folder to an ASCII-only path (e.g. C:\\\\NSPB\\\\sdk) and point the dependencies panel's Choose folder… at it."),
'dep.row.log': ('依赖 %@:[%@] %@', 'dependency %@: [%@] %@', 'dependency %@: [%@] %@'),
'dep.fix.diskspace': ('磁盘空间不足:清理后(SDK 和工具链解压需要数 GB)再点「安装」。', 'The disk is full: free some space (the SDK and toolchains unpack to several GB) and press Install again.', 'The disk is full: free some space (the SDK and toolchains unpack to several GB) and press Install again.'),
'dep.fix.log': ('完整输出在 Mac/iPhone 选择下面的日志里。', 'The full output is in the log under the Mac/iPhone choice.', 'Fullständig utdata finns i loggen under Mac/iPhone-valet.'),
'dep.python.missing': ('%@ 缺包', '%@ is missing packages', '%@ saknar paket'),
Expand Down
112 changes: 106 additions & 6 deletions frontend-qt/nspb_qt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class Model(QObject):
#: Set by the window: asks for a folder (QFileDialog lives in the UI layer) and returns the
#: path, or '' when the user cancelled. `pick_dep_folder` calls it, so the model stays UI-free.
ask_folder: Callable[[str], str] | None = None
#: Same, for a file ('Metal Developer Tools*.zip' the user downloaded from Apple).
ask_file: Callable[[str], str] | None = None
_metal_zip: Path | None = None

def __init__(self) -> None:
super().__init__()
Expand Down Expand Up @@ -299,6 +302,16 @@ def _check_deps(self) -> None:
d.last_error, d.fix_hint = p.last_error, p.fix_hint

self.deps = deps
# The panel can only show one row at a time; the log keeps every detail, so a report sent
# from a handheld always carries the full probe text (the truncated link row is why this
# exists).
for d in deps:
if not d.ok and d.detail:
# three placeholders, three args: a mismatch makes t() fall back to the raw
# "dependency %@: [%@] %@" line (the report's log had it six times)
name = d.title_key.replace('dep.', '').replace('.hint', '')
self.log(self.t('dep.row.log', name, d.state.value,
d.detail.replace('\n', ' | ')) + '\n')
if not pu.IS_WIN:
# On Windows `_windows_deps` already set python_path (the interpreter the app
# installed, which find_python without its candidates cannot see) and dotnet_path
Expand Down Expand Up @@ -744,9 +757,27 @@ def work() -> None:
elif what == 'ios_sdk':
self.log(self.t('dep.iossdk.downloading') + '\n')
from .win import sdk_fetch as sf
# clone_sdk runs git, which a fresh machine has none of: the app installs
# PortableGit itself (per-user, no installer) instead of sending the player
# to git-scm.com — the report's SDK row failed three times on exactly that.
if not (wtc.git_exe() or shutil.which('git')):
self.log(self.t('dep.git.downloading') + '\n')
from .win import fetch as wf
git = wf.install_git(log=lambda s: self.log(str(s) + '\n'))
self.log(self.t('dep.git.done', str(git)) + '\n')
path = sf.clone_sdk(log=lambda s: self.log(str(s) + '\n'))
self.log(self.t('dep.iossdk.done', str(path)) + '\n')
ok = True
elif what == 'metal_zip':
# Apple's tools are Apple-ID-gated: the browser download is the licensed
# path, the app does the unpack and remembers the folder.
self.log(self.t('dep.metal.unpacking', self._metal_zip.name) + '\n')
from .win import fetch as wf
dest = wf.install_metal_from_zip(self._metal_zip,
log=lambda s: self.log(str(s) + '\n'))
wtc.save_config('metal_dir', str(dest))
self.log(self.t('dep.metal.done', str(dest)) + '\n')
ok = True
else:
self.log(f'unknown Windows install target: {what}\n')
except Exception as e:
Expand Down Expand Up @@ -796,6 +827,19 @@ def pick_dep_folder(self, dep: Dep) -> None:
if not dep.pick_key:
return
from .win import toolchain as wtc
if dep.pick_key == 'metal_dir':
# The Metal zip is a file, not a folder: the ask_file callback (the window's file
# dialog filters *.zip) takes the browser download straight away. An already
# unpacked folder is equally accepted.
ask_file = self.ask_file
if ask_file is None:
return
picked = ask_file(self.t('dep.pick.metal_dir.title'))
if not picked:
return
if picked.lower().endswith('.zip'):
return self.install_metal_zip(Path(picked))
return self._save_metal_folder(Path(picked))
ask = self.ask_folder
if ask is None:
return # no window attached (tests): nothing to ask with
Expand All @@ -819,6 +863,29 @@ def pick_dep_folder(self, dep: Dep) -> None:
self.log(self.t('dep.pick.saved', folder) + '\n')
self.check_deps()

def _save_metal_folder(self, folder: Path) -> None:
"""A folder the user already unpacked: validate the two layouts metal_dir() accepts."""
from .win import toolchain as wtc
if not (folder / 'bin' / 'metal.exe').is_file() and \
not (folder / 'ios' / 'bin' / 'metal.exe').is_file():
self.log(self.t('dep.pick.metal.invalid', str(folder)) + '\n')
return
wtc.save_config('metal_dir', str(folder))
self.log(self.t('dep.pick.saved', str(folder)) + '\n')
self.check_deps()

def install_metal_zip(self, zip_path: Path) -> None:
"""Unpack the Apple zip the player downloaded and remember the folder (the one manual
dependency on Windows: Apple-ID-gated, so the app cannot fetch it itself)."""
if not zip_path.is_file():
self.log(self.t('dep.pick.metal.invalid', str(zip_path)) + '\n')
return
self._metal_zip = zip_path
dep = next((d for d in self.deps if d.id == 'metal'), None)
if dep is None:
return
self._install_win(dep, 'metal_zip')

def _progress_logger(self, label: str):
"""A progress callback that logs at 5% steps, not on every chunk.

Expand All @@ -839,6 +906,26 @@ def report(done: int, total: int) -> None:

return report

@staticmethod
def bundled_wheels() -> Path | None:
"""The wheel folder shipped in the Windows zip (`wheels/` beside the exe).

The build packages (lz4, capstone, fonttools, nsz, backports.zstd) are downloaded by the
release workflow at packaging time, so the venv step installs from disk with no network
and no PyPI — the same "the app carries it" promise the Mac's bundled CPython makes.
Source runs have no such folder and fall back to PyPI.
"""
base = getattr(sys, '_MEIPASS', None) or Path(sys.executable).parent
w = Path(base) / 'wheels'
return w if w.is_dir() and any(w.glob('*.whl')) else None

@staticmethod
def _pip_args(pkgs: list[str], wheels: Path | None) -> list[str]:
"""pip's arguments: offline from the bundled wheels when they cover the packages."""
if wheels:
return ['install', '--no-index', '--find-links', str(wheels)] + pkgs
return ['install'] + pkgs

def _make_venv(self, base: str) -> bool:
"""Create or reuse the app's venv and install the build packages into it."""
vpy = pu.venv_python()
Expand Down Expand Up @@ -879,9 +966,12 @@ def _make_venv(self, base: str) -> bool:
pkgs = ['lz4', 'capstone', 'fonttools', 'nsz']
if ver < (3, 14):
pkgs.insert(3, 'backports.zstd')
self.log(f'$ {vpy} -m pip install {" ".join(pkgs)}\n')
wheels = self.bundled_wheels()
args = self._pip_args(pkgs, wheels)
self.log(f'$ {vpy} -m pip {" ".join(args)}'
+ ('' if wheels else ' (from PyPI)') + '\n')
try:
p = subprocess.Popen([vpy, '-m', 'pip', 'install'] + pkgs, stdout=subprocess.PIPE,
p = subprocess.Popen([vpy, '-m', 'pip'] + args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, text=True, errors='replace',
env=pu.child_env(), **pu.no_window_kwargs())
assert p.stdout is not None
Expand Down Expand Up @@ -919,18 +1009,28 @@ def install_all_missing(self) -> None:

def run_all() -> None:
try:
attempted: set[str] = set()
# attempted is keyed by (id, fix): an id may legitimately come back in a later
# pass with a DIFFERENT fix — installing the Python interpreter turns its row
# into "pip install the packages", which is exactly the step install-all must
# then run (the report: only the interpreter was installed, the packages step
# needed a second click on the row).
attempted: dict[str, tuple] = {}
while True:
rows = [d for d in self.deps if not d.ok and d.install
and d.id not in attempted]
def pending(d) -> bool:
if d.ok or not d.install:
return False
return attempted.get(d.id) != tuple(d.install)
rows = [d for d in self.deps if pending(d)]
if not rows:
break
progressed = False
for d in rows:
live = next((r for r in self.deps if r.id == d.id), None)
if live is None or live.ok or not live.install or live.installing:
continue
attempted.add(live.id)
if attempted.get(live.id) == tuple(live.install):
continue
attempted[live.id] = tuple(live.install)
self.log(f'--- {self.t(live.title_key)} ---\n')
self.install_dep(live)
progressed = True
Expand Down
30 changes: 28 additions & 2 deletions frontend-qt/nspb_qt/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(self, model: Model) -> None:
self.m.finished.connect(self._on_finished)

self._refresh_all()
self.m.ask_folder = lambda title: self._ask_folder(title)
self.m.ask_file = lambda title: self._ask_file(title)
self.m.check_deps()

# ---------------------------------------------------------------- header
Expand Down Expand Up @@ -486,6 +488,21 @@ def _refresh_deps(self) -> None:
detail = self.m.t(detail)
elif detail:
detail = pu.short_path(detail)
# A long detail (the link probe's three-attempt report) would be elided to nothing on
# one line: it moves into its own wrapped block under the row, where it is readable.
if len(detail) > 140 or '\n' in detail:
head = QLabel(detail[:120] + '…')
head.setObjectName('mono')
head.setTextInteractionFlags(Qt.TextSelectableByMouse)
h.addWidget(head, 1)
note = QLabel(detail)
note.setObjectName('mono')
note.setWordWrap(True)
note.setTextInteractionFlags(Qt.TextSelectableByMouse)
note.setContentsMargins(20, 0, 0, 4)
self.deps_container.addWidget(row)
self.deps_container.addWidget(note)
continue
lab = QLabel(detail)
lab.setObjectName('mono')
lab.setTextInteractionFlags(Qt.TextSelectableByMouse)
Expand All @@ -500,8 +517,9 @@ def _refresh_deps(self) -> None:
h.addWidget(btn)
if d.pick_key:
# Apple-licensed pieces cannot be downloaded by the app: Choose points at a
# copy the user already has (validated, remembered in toolchain.json).
pick = QPushButton(self.m.t('dep.pick'))
# copy the user already has — an unpacked folder, or (Metal) the downloaded
# zip, which the app unpacks and remembers.
pick = QPushButton(self.m.t('dep.pick.metal' if d.pick_key == 'metal_dir' else 'dep.pick'))
pick.clicked.connect(lambda _=False, dep=d: self.m.pick_dep_folder(dep))
h.addWidget(pick)
if not d.install and not d.pick_key:
Expand Down Expand Up @@ -675,6 +693,14 @@ def _build_clicked(self) -> None:
self.failure_box.hide()
self.m.start_build()

def _ask_folder(self, title: str) -> str:
d = QFileDialog.getExistingDirectory(self, title)
return d or ''

def _ask_file(self, title: str) -> str:
d, _ = QFileDialog.getOpenFileName(self, title, '', 'Metal tools zip (*.zip)')
return d or ''

def _choose_repo(self) -> None:
d = QFileDialog.getExistingDirectory(self, self.m.t('repo.pickMessage'))
if d:
Expand Down
2 changes: 1 addition & 1 deletion frontend-qt/nspb_qt/win/build_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def link(clang: Path, sdk: Path, objs: list[Path], frameworks: list[str], out: P
"""Link the app, then prove the result is an unsigned iOS executable."""
args = [str(clang), '-target', f'arm64-apple-ios{deployment}', '-isysroot', str(sdk),
'-fuse-ld=lld', '-fobjc-arc', '-o', str(out), *map(str, objs),
'-Wl,-rpath,@executable_path/Frameworks', '-lobjc',
'-Wl,-rpath,@executable_path/Frameworks', '-lobjc', '-lSystem',
*[x for fw in frameworks for x in ('-framework', fw)], *embed_flags]
if rt_obj:
args.append(str(rt_obj))
Expand Down
Loading
Loading