Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
25 changes: 23 additions & 2 deletions .github/workflows/build-mac-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
# "up to date" — a silent failure of the update path for every existing install. Copies from before
# the app was renamed (NS Port Builder) look for NS-Port-Builder-macOS-arm64.zip, so that one goes up too.
#
# The app also carries its build tools (zstd, glslangValidator, spirv-cross, xcodegen) and a Python with the packages the build scripts import,
# so a player installs neither Homebrew nor Python (frontend/tools/bundle_tools.sh builds them from pinned, checksummed sources; check_bundle.sh
# runs each from the assembled bundle with a clean PATH, checks the load paths and the signature).
#
# - push a tag vX.Y.Z → builds and attaches the app to that release
# - workflow_dispatch → artifact only
# - a pull request that touches frontend/ or this file → artifact only, so a change to the bundle is tested before a release needs it
name: Build nxnative (native macOS)

on:
push:
tags: ['v*']
pull_request:
paths: ['frontend/**', '.github/workflows/build-mac-app.yml']
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -63,6 +70,9 @@ jobs:
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
cp .build/release/NSPortBuilder "$APP/Contents/MacOS/NSPortBuilder"
cp AppIcon.icns "$APP/Contents/Resources/AppIcon.icns"
# The build tools and the Python go into Resources before the bundle is signed (bundle_tools.sh signs each nested Mach-O file
# itself: --deep below does not reach code that sits in Resources).
tools/bundle_tools.sh "$APP/Contents/Resources" "$RUNNER_TEMP/bundle-tools-work"
V="${{ steps.ver.outputs.version }}"
cat > "$APP/Contents/Info.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -77,7 +87,7 @@ jobs:
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>$V</string>
<key>CFBundleVersion</key><string>$V</string>
<key>LSMinimumSystemVersion</key><string>13.0</string>
<key>LSMinimumSystemVersion</key><string>26.6</string>
<key>NSHighResolutionCapable</key><true/>
</dict>
</plist>
Expand All @@ -86,9 +96,19 @@ jobs:
# Ad-hoc: the app is distributed as a zip and the user right-clicks → Open once, which is
# what the README says. A real Developer ID would need a certificate this repo has none of.
codesign --force --deep --sign - "$APP"
codesign -v "$APP"
codesign -v --deep --strict "$APP"
plutil -p "$APP/Contents/Info.plist" | grep -i version

- name: Check the bundled tools from the assembled bundle
working-directory: frontend
shell: bash
run: |
set -euo pipefail
# zstd, glslangValidator, spirv-cross and xcodegen run by their bundle paths with a PATH of /usr/bin:/bin; the Python imports
# lz4, capstone, fontTools and nsz; no Mach-O file links into /opt/homebrew; the signature verifies.
tools/check_bundle.sh NX2Apple.app
codesign -v --deep --strict NX2Apple.app

- name: Package
working-directory: frontend
shell: bash
Expand All @@ -111,6 +131,7 @@ jobs:
(cd "legacy-$legacy" && ditto -c -k --keepParent "$legacy.app" "../${zname}-macOS-arm64.zip")
done
ls -la *.zip
du -sh "$APP/Contents/Resources/tools" "$APP/Contents/Resources/python"

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ follows upstream automatically. What it adds:
3. **Pick your game files** — base game, update, DLC and `prod.keys`, separately or as one folder.
4. **Press build**, then follow the three install steps it prints.

> Requirements: an Apple Silicon Mac on macOS 26.6+, [Xcode](https://apps.apple.com/app/xcode/id497799835) 27.1 with the iOS SDK, Python 3.9+, .NET SDK 10.
> The app's dependency panel detects each of these and installs what it can. Your own game files and
> `prod.keys` — nothing is bundled.
> Requirements: an Apple Silicon Mac on macOS 26.6 or later and [Xcode](https://apps.apple.com/app/xcode/id497799835) 27.1 (an iPhone build also needs
> Xcode's iOS platform). The app carries its own build tools and Python, so no Homebrew and no Python
> install; .NET SDK 10 is the one tool it still installs for you. The app's dependency panel detects
> each requirement and installs what it can. Your own game files and `prod.keys` — nothing of a game
> is bundled.

---

Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ NVN-on-Metal、各游戏的 profile 都是上游的工作,本 fork 自动跟
3. **选好游戏文件** —— 本体、更新包、DLC 和 `prod.keys`,分开选或一个文件夹全选。
4. **按构建**,然后照它给出的三步装到手机。

> 环境要求:Apple Silicon Mac + macOS 26.6+、装了 iOS SDK 的 [Xcode](https://apps.apple.com/app/xcode/id497799835) 27.1、Python 3.9+、.NET SDK 10。
> 环境要求:Apple Silicon Mac + macOS 26.6 或更新、Xcode 27.1(打 iPhone 版还需要 Xcode 的 iOS 平台)。App 自带构建工具和 Python,不需要装 Homebrew 和 Python;.NET SDK 10 仍由 App 帮你安装。
> App 的依赖面板会逐项检测,能装的直接装。游戏文件和 `prod.keys` 需要你自己的——本仓库不含任何数据。

---
Expand Down
2 changes: 1 addition & 1 deletion frontend/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PackageDescription

let package = Package(
name: "NSPortBuilder",
platforms: [.macOS(.v13)],
platforms: [.macOS("26.6")],
targets: [
.executableTarget(name: "NSPortBuilder", path: "Sources/NSPortBuilder"),
.testTarget(name: "NSPortBuilderTests", dependencies: ["NSPortBuilder"])
Expand Down
15 changes: 14 additions & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ or double-click `nxnative.app` in this folder (ad-hoc signed; rebuild it with `s
and copy the binary into `Contents/MacOS/`). The app's settings and library stay under the folder name it
had before the rename, `~/Library/Application Support/NS Port Builder/`.

SwiftUI, macOS 13+.
SwiftUI, macOS 26.6+ (what the project supports; Xcode 27.1, Apple silicon).

### Why the dependency check does not use `which`

Expand All @@ -221,6 +221,19 @@ and picks the first interpreter that can really import
`lz4 capstone fontTools backports.zstd`. That same interpreter then runs the
build.

### The bundled build tools and Python

The release app (`NX2Apple.app`) carries `zstd`, `glslangValidator`, `spirv-cross`, `xcodegen` (in
`Contents/Resources/tools/bin`) and a relocatable CPython 3.13 with `lz4 capstone fonttools
backports.zstd nsz` (`Contents/Resources/python`), so a player needs no Homebrew and no Python.
`tools/bundle_tools.sh` fills them in during the release workflow (pinned versions and sha256 of the
sources, built for macOS 26.6 with static libraries; the Python packages come from
`tools/bundled-python-requirements.txt`) and `tools/check_bundle.sh` runs each tool from the bundle
with a clean PATH. The dependency check (`BundledTools.swift`) prefers them to Homebrew's and shows
"bundled"; the build's PATH starts with them. Under `swift run`, or in a build without the bundle,
nothing changes: Homebrew's tools, a system Python or the launcher's venv. To try the bundle by hand:
`tools/bundle_tools.sh <folder> <work folder>`, then `tools/check_bundle.sh <folder>`.

## Language

The interface follows the system language at every launch: any Chinese variant
Expand Down
30 changes: 30 additions & 0 deletions frontend/Sources/NSPortBuilder/AppUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ enum AppUpdate {
return nil
}

// ---- What the running macOS can open ----

/// "26.6" or "26.6.1" as an OS version; nil for anything else.
static func parseOSVersion(_ s: String) -> OperatingSystemVersion? {
let n = s.trimmingCharacters(in: .whitespaces).split(separator: ".", omittingEmptySubsequences: false).map { Int($0) }
guard (1...3).contains(n.count), n.allSatisfy({ $0 != nil && $0! >= 0 }) else { return nil }
return OperatingSystemVersion(majorVersion: n[0]!, minorVersion: n.count > 1 ? n[1]! : 0, patchVersion: n.count > 2 ? n[2]! : 0)
}

/// `a` is older than `b`, field by field (major, minor, patch).
static func isOlder(_ a: OperatingSystemVersion, than b: OperatingSystemVersion) -> Bool {
(a.majorVersion, a.minorVersion, a.patchVersion) < (b.majorVersion, b.minorVersion, b.patchVersion)
}

static func describe(_ v: OperatingSystemVersion) -> String {
v.patchVersion == 0 ? "\(v.majorVersion).\(v.minorVersion)" : "\(v.majorVersion).\(v.minorVersion).\(v.patchVersion)"
}

/// The staged app's `LSMinimumSystemVersion`, as written ("26.6"), when it is above `running`: the release cannot be
/// opened on this Mac, so it must not replace the launcher that can. nil when it opens here, or names no minimum
/// (macOS then applies none) or one that cannot be read (the release workflow writes it; an unreadable value is
/// not a reason to keep a Mac from updating).
static func minimumOSAbove(_ running: OperatingSystemVersion, app: URL) -> String? {
guard let data = try? Data(contentsOf: app.appendingPathComponent("Contents/Info.plist")),
let info = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
let text = info["LSMinimumSystemVersion"] as? String, let min = parseOSVersion(text)
else { return nil }
return isOlder(running, than: min) ? describe(min) : nil
}

// ---- What may replace itself ----

enum Installability: Equatable {
Expand Down
47 changes: 47 additions & 0 deletions frontend/Sources/NSPortBuilder/BundledTools.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Foundation

/// The build tools and the Python that the release app carries in Contents/Resources (frontend/tools/bundle_tools.sh fills them in):
///
/// tools/bin zstd, glslangValidator, spirv-cross, xcodegen
/// python/ a relocatable CPython with lz4, capstone, fontTools and nsz installed
///
/// Every function takes the resources folder as a parameter (the tests pass a fake bundle) and defaults to this app's own. There is
/// none under `swift run` or in a build that predates the bundle, and each function then answers nil, so everything else behaves as
/// it did before: Homebrew's tools, a system Python or the launcher's venv.
enum BundledTools {
/// This app's Resources folder, but only inside a .app: `swift run` gives the executable's own folder, which is not a bundle.
nonisolated static var resources: URL? {
guard Bundle.main.bundleURL.pathExtension == "app" else { return nil }
return Bundle.main.resourceURL
}

nonisolated static func isExecutable(_ url: URL) -> Bool { FileManager.default.isExecutableFile(atPath: url.path) }

/// tools/bin, when the bundle has it.
nonisolated static func binDirectory(in resources: URL? = resources) -> String? {
guard let dir = resources?.appendingPathComponent("tools/bin"),
(try? FileManager.default.contentsOfDirectory(atPath: dir.path))?.isEmpty == false else { return nil }
return dir.path
}

/// The path of one bundled tool (`binary` is the file name in tools/bin), when it is there and runs.
nonisolated static func tool(_ binary: String, in resources: URL? = resources) -> String? {
guard let url = resources?.appendingPathComponent("tools/bin/" + binary), isExecutable(url) else { return nil }
return url.path
}

/// The bundled interpreter, when it is there.
nonisolated static func python(in resources: URL? = resources) -> String? {
guard let url = resources?.appendingPathComponent("python/bin/python3"), isExecutable(url) else { return nil }
return url.path
}

/// A PATH for the processes that run the build: the bundled tools first, then the bundled Python's folder (so that a script that
/// starts `python3` by name gets this one and not the system's 3.9), then `base`. `base` unchanged when there is no bundle.
nonisolated static func path(_ base: String, in resources: URL? = resources) -> String {
var dirs: [String] = []
if let bin = binDirectory(in: resources) { dirs.append(bin) }
if let py = python(in: resources) { dirs.append((py as NSString).deletingLastPathComponent) }
return (dirs + [base]).joined(separator: ":")
}
}
Loading
Loading