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
Sync as a pull request: workflows, issue forms and docs for the patch queue
v0lumehi4dd8d6a3d5a7
diff --git a/.github/ISSUE_TEMPLATE/build_problem.yml b/.github/ISSUE_TEMPLATE/build_problem.ymlindex 8849f4ef..821557fa 100644--- a/.github/ISSUE_TEMPLATE/build_problem.yml+++ b/.github/ISSUE_TEMPLATE/build_problem.yml@@ -88,6 +88,14 @@ body:placeholder: MacBook Pro M2 Max, macOS 26.1validations:required: true+ - type: input+ id: fork-patches+ attributes:+ label: Fork patches line+ description: "The patches your build carries beyond upstream's engine: the first line of the game app's log (`fork patches: ...`), or the contents of `dm/fork_patches.txt` in the NX2Apple folder you built from. Optional."+ placeholder: "fork patches: runtime-profile, romfsarc, ..."+ validations:+ required: false- type: checkboxesid: no-game-filesattributes:diff --git a/.github/ISSUE_TEMPLATE/game_problem.yml b/.github/ISSUE_TEMPLATE/game_problem.ymlindex e99664b0..b99026b8 100644--- a/.github/ISSUE_TEMPLATE/game_problem.yml+++ b/.github/ISSUE_TEMPLATE/game_problem.yml@@ -94,6 +94,14 @@ body:- iPhone or iPad: `log.txt` in the Files app, under the app's name (the run before is `log.prev.txt`).validations:required: true+ - type: input+ id: fork-patches+ attributes:+ label: Fork patches line+ description: "The first line of the game's log (`fork patches: ...`): the patches this build carries beyond upstream's engine. Optional, but it says whether a report belongs here or with seedds/nxnative."+ placeholder: "fork patches: runtime-profile, romfsarc, ..."+ validations:+ required: false- type: textareaid: performanceattributes:diff --git a/.github/pull_request_template.md b/.github/pull_request_template.mdindex 78cd610b..71daf224 100644--- a/.github/pull_request_template.md+++ b/.github/pull_request_template.md@@ -7,7 +7,7 @@## Checked<!-- Delete what does not apply. Say what was not checked too. -->-- Tests: <!-- `cd frontend && swift test`; frontend-qt tests if you changed it; for scripts/sync_upstream.py, `python3 -m pytest scripts/tests/test_sync_patchers.py` (fetch `seedds main` first; CI runs it with unittest) and the sync run on a scratch checkout -->+- Tests: <!-- `cd frontend && swift test`; frontend-qt tests if you changed it; `python3 scripts/patches.py check` when `patches/` or a vendored path changed -->- Visual QA: <!-- `NX_LAUNCHER_CAPTURE_DIR=<dir> swift test` captures the views, for a UI change -->- Run on a device or Mac: <!-- what was built, played or installed, with title ID and version; chip and OS -->@@ -17,5 +17,5 @@## Scope-- [ ] No vendored file (`dm/`, `scripts/`, `docs/`, `ref/`, `AGENTS.md`) is edited, or it goes through a sync patcher or upstream first (`pr-scope`)+- [ ] No vendored file (`dm/`, `scripts/`, `docs/`, `ref/`, `AGENTS.md`) is edited directly: a change there is a patch in `patches/` (`scripts/patches.py export`; `patches.py check` passes), with its `Upstream-Status`- [ ] No keys, game files or data extracted from a game in the change or the attachmentsdiff --git a/.github/workflows/daily-health.yml b/.github/workflows/daily-health.ymlindex 90e88e70..03496009 100644--- a/.github/workflows/daily-health.yml+++ b/.github/workflows/daily-health.yml@@ -2,9 +2,9 @@# purpose — that workflow can fail silently (its own issue step needs a permission it may not have),# so this one reports on the state of the tree rather than on a sync attempt:# - the last sync is recent (catches a schedule that stopped firing, or a run that died early)-# - the patchers still reproduce the tree (catches a source fix without its patcher entry)+# - the patch queue reproduces the vendored tree (catches a vendored edit without its patch) and shows which patches a bump to upstream main would conflict on# - the host builds and the host unit tests pass (catches a fork change that broke a test rule)-# - upstream has not moved without a sync (catches a failed sync that left no issue)+# - upstream has not moved without a sync (catches a failed sync that left no issue or PR)# A problem opens an issue with the log; a clean run just succeeds. No push, ever.name: Daily health check@@ -23,12 +23,12 @@ jobs:steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:- fetch-depth: 0 # the patcher check compares against upstream/main+ fetch-depth: 0 # the patch queue applies onto the pinned upstream commit- name: Fetch upstreamrun: |- git remote add upstream https://github.com/seedds/nxnative.git- git fetch upstream main # whole history: the dry run below needs the last sync base (.upstream-ref), not only the tip+ git remote add seedds https://github.com/seedds/nxnative.git+ git fetch --no-tags seedds main- name: Health checkid: check@@ -46,19 +46,22 @@ jobs:echoecho "=== upstream drift ==="- NEW=$(git rev-parse upstream/main)- echo "upstream/main: $NEW"+ NEW=$(git rev-parse seedds/main)+ echo "seedds/main: $NEW"if [ "$LAST" != none ] && [ "$LAST" != "$NEW" ]; thenBEHIND=$(git rev-list --count "$LAST..$NEW" 2>/dev/null || echo '?')echo "commits upstream since the last sync: $BEHIND"fiecho- echo "=== patcher consistency ==="- # The dry run uses the real base, as the sync workflow does (--old "$NEW" made every file upstream added since- # the last sync read as a fork edit). Without .upstream-ref it falls back to $NEW, as the sync does.- BASE=$LAST; [ "$BASE" != none ] || BASE=$NEW- python3 scripts/sync_upstream.py --old "$BASE" --new "$NEW" --skip-build 2>&1 | tail -40+ echo "=== patch queue (check: the series reproduces the vendored tree) ==="+ python3 scripts/patches.py check 2>&1 | tail -40+ CHECK_RC=${PIPESTATUS[0]}+ echo+ echo "=== patch queue (dry bump to seedds/main: which patches would conflict) ==="+ python3 scripts/patches.py bump --dry --to "$NEW" 2>&1 | tail -80 || true+ [ "$CHECK_RC" -eq 0 ] || echo "PROBLEM: patches.py check failed"+ [ "$CHECK_RC" -eq 0 ] # the group's status: a failed check fails the step (the dry bump only reports)} 2>&1 | tee check.log- name: Host build and unit tests@@ -88,5 +91,5 @@ jobs:$(tail -60 check.log 2>/dev/null || echo 'see the workflow log')\`\`\`- Common causes: a fork source change without its patcher entry (patcher drift), a test rule that no longer links a new dependency, or a sync that has not run for over two days." \+ Common causes: a vendored file edited without its patch (patches/README.md), a test rule that no longer links a new dependency, or a sync that has not run for over two days." \|| echo "issue creation failed; the log is in the workflow run"diff --git a/.github/workflows/pr-scope.yml b/.github/workflows/pr-scope.ymlindex c7586e65..ae959b74 100644--- a/.github/workflows/pr-scope.yml+++ b/.github/workflows/pr-scope.yml@@ -1,80 +1,32 @@-# Guard the sync: fail a PR that edits a vendored file outside the fork's protection.+# Guard the patch queue: fail a PR that edits a vendored file without a patch.#-# The sync takes dm/, scripts/, docs/, AGENTS.md and ref/ from upstream file by file. Three kinds-# of file keep the fork's changes: OURS (fork-only files), PATCHED (carriers whose patcher-# re-applies them), and fork-only paths the sync never takes (frontend/, frontend-qt/,-# .github/workflows/). A PR that edits any other vendored file will be silently reverted the next-# time upstream touches it — issue #29 (v0lumehi reading the sync script) is what made this a-# check instead of a note in CONTRIBUTING.-#-# What a PR author sees on failure: the list of files at risk, and the two ways out (propose the-# change upstream first, or ask a maintainer to add a patcher entry).+# dm/, scripts/, docs/, ref/ and AGENTS.md are upstream (seedds/nxnative, pinned in .upstream-ref) plus the patches in+# patches/. A PR that edits one of those files directly would be reverted by the next bump, so `scripts/patches.py check`+# (the series applied to the pin must give the committed tree) fails it. What a PR author sees: the files that differ, and the+# way out (commit the change, `scripts/patches.py export <commit>`, fill in the header; patches/README.md).+# A sync PR (branch sync/upstream-*) is checked too, on purpose: it must reproduce its own tree. The old per-file guard+# and its skip for sync branches are gone with the anchor patchers.+# The same check is a job in tests.yml; this one starts on the vendored paths only, and says so in its own name.name: PR scope (sync safety)on:pull_request:- paths: ['dm/**', 'scripts/**', 'docs/**', 'ref/**', 'AGENTS.md']+ paths: ['dm/**', 'scripts/**', 'docs/**', 'ref/**', 'AGENTS.md', 'patches/**', '.upstream-ref']permissions:contents: readjobs:check:- runs-on: macos-latest+ runs-on: ubuntu-lateststeps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:- fetch-depth: 0 # the merge base of the PR and its base, for the three-dot diff below-- - name: Files the sync protects or never overwrites- id: known- run: |- python3 - <<'PY' >> "$GITHUB_OUTPUT"- import sys- sys.path.insert(0, 'scripts')- import sync_upstream as su- ours = sorted(su.OURS)- patched = sorted(su.PATCHED)- print(f'ours={",".join(ours)}')- print(f'patched={",".join(patched)}')- PY-- - name: Check the PR's changed files- env:- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}- OURS: ${{ steps.known.outputs.ours }}- PATCHED: ${{ steps.known.outputs.patched }}+ fetch-depth: 0+ persist-credentials: false+ - name: Fetch the pinned upstream commitrun: |- # A sync PR carries upstream's own new files by design (hundreds of them, none in- # OURS or PATCHED because they are upstream's); the sync's own check_unprotected()- # already refused to write over an unprotected fork edit before this branch existed.- # Only normal PRs need the file-by-file guard.- if [[ "${GITHUB_HEAD_REF}" == sync/upstream-* ]]; then- echo "sync PR: the sync's own protection check ran; nothing to guard file by file."- exit 0- fi- # changed files = base...head, minus deletions (nothing to protect there)- BASE="${{ github.event.pull_request.base.sha }}"- HEAD="${{ github.event.pull_request.head.sha }}"- git fetch --no-tags origin "$BASE" "$HEAD" 2>/dev/null || true- # Three dots: the PR's own changes since it left the base (the checkout keeps the history for the merge base). Two dots- # compared the base's tip with the PR's head, so every commit main gained after the PR branched counted as the PR's- CHANGED=$(git diff --name-only --diff-filter=d "$BASE"..."$HEAD" | sort -u)- at_risk=""- for f in $CHANGED; do- case "$f" in- frontend/*|frontend-qt/*|.github/*) continue ;; # fork-only, never taken from upstream- esac- case ",$OURS," in *",$f,"*) continue ;; esac- case ",$PATCHED," in *",$f,"*) continue ;; esac- at_risk="$at_risk$f\n"- done- if [ -n "$at_risk" ]; then- echo "::error::These vendored files would be reverted by the next sync (they are not in OURS or PATCHED):"- echo -e "$at_risk"- echo ""- echo "Send the change to seedds/nxnative first (it comes back with the daily sync), or ask a"- echo "maintainer to add a patcher entry in scripts/sync_upstream.py for it."- exit 1- fi- echo "PR touches no unprotected vendored files."+ git remote add seedds https://github.com/seedds/nxnative.git+ git fetch --no-tags seedds "$(cat .upstream-ref)"+ - name: The series reproduces the vendored tree+ run: python3 scripts/patches.py checkdiff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.ymlindex 2caaac7b..8dd643ee 100644--- a/.github/workflows/sync-upstream.yml+++ b/.github/workflows/sync-upstream.yml@@ -1,8 +1,12 @@-# Daily: follow upstream seedds/nxnative. The fork is a fresh repository (no shared git-# history), so GitHub's own "Sync fork" does not apply; scripts/sync_upstream.py is the-# sync instead — upstream's tree, the fork's features re-applied, then verification-# (Python 3.9 parse, bash -n, the archive reader test, a macOS host build). Success is-# committed and pushed; a failure opens an issue and pushes nothing.+# Daily: follow upstream seedds/nxnative as a patch queue (issue #123, patches/README.md). The vendored+# paths are upstream at a pinned commit (.upstream-ref) plus the patches in patches/; scripts/patches.py+# bump moves the pin, re-applies the series, drops the patches that landed upstream, and leaves the rest+# for review. Nothing is pushed to main (it is protected): the result is a pull request from the branch+# sync/upstream-<short sha> (or, when a patch no longer applies, an issue naming it).+#+# A PR opened with the default GITHUB_TOKEN does not start other workflows (GitHub's rule), so this job+# runs the checks itself before it opens the PR. A repository secret SYNC_TOKEN (a fine-grained token+# with contents, pull requests and issues write) makes the PR start tests.yml as well.name: Sync upstreamon:@@ -12,69 +16,96 @@ on:permissions:contents: write- issues: writepull-requests: write+ issues: writejobs:sync:runs-on: macos-latest # the host build needs clang + macOS headers+ env:+ GH_TOKEN: ${{ secrets.SYNC_TOKEN || secrets.GITHUB_TOKEN }}steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ fetch-depth: 0 # the pinned upstream commit's blobs come from seedds below; the fork's own history is small+ token: ${{ secrets.SYNC_TOKEN || secrets.GITHUB_TOKEN }}- name: Fetch upstreamrun: |- git remote add upstream https://github.com/seedds/nxnative.git- git fetch upstream main+ git remote add seedds https://github.com/seedds/nxnative.git+ git fetch --no-tags seedds main+ echo "NEW=$(git rev-parse seedds/main)" >> "$GITHUB_ENV"+ echo "OLD=$(cat .upstream-ref)" >> "$GITHUB_ENV"- - name: Sync (and verify)- id: sync+ - name: Bump the pin and re-apply the patches+ id: bumprun: |- LAST=$(cat .upstream-ref 2>/dev/null || true)- NEW=$(git rev-parse upstream/main)- echo "new=$NEW" >> "$GITHUB_OUTPUT"- if [ "$LAST" = "$NEW" ]; then echo "Already at $NEW"; exit 0; fi- python3 scripts/sync_upstream.py --old "${LAST:-$NEW}" --new "$NEW" 2>&1 | tee sync.log- exit ${PIPESTATUS[0]}+ if [ "$OLD" = "$NEW" ]; then echo "Already at $NEW"; echo "changed=no" >> "$GITHUB_OUTPUT"; exit 0; fi+ set +e+ python3 scripts/patches.py bump --to "$NEW" 2>&1 | tee bump.log+ rc=${PIPESTATUS[0]}+ if [ $rc -eq 0 ]; then echo "changed=yes" >> "$GITHUB_OUTPUT"+ elif [ $rc -eq 1 ]; then echo "changed=conflict" >> "$GITHUB_OUTPUT"+ else echo "changed=error" >> "$GITHUB_OUTPUT"; exit $rc; fi++ - name: Check the patch queue+ if: steps.bump.outputs.changed == 'yes'+ run: |+ python3 scripts/patches.py check+ python3 -m unittest discover scripts/tests+ # every .py parses on the Python this fork supports as its floor, the iOS build script survives bash -n+ python3 -m compileall -q scripts dm/tools dm/games dm/mac > /dev/null+ bash -n dm/ios/tools/build_ipa.sh+ GAME=$(ls dm/games | grep '^0100' | head -1)+ make -C dm/host GAME=$GAME dmhost -j4 2>&1 | tail -20- name: Commit to a sync branch and open a pull request- if: success() && steps.sync.outcome == 'success'- env:- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ if: steps.bump.outputs.changed == 'yes'# main is protected (a pull request is required, force pushes and deletions are# blocked, and the rules apply to everyone including the owner and this bot), so the- # sync result goes to a branch and a PR instead of straight to main. The PR runs the- # full test suite, then a person merges it.+ # sync result goes to a branch and a PR instead of straight to main. A person merges it.+ # -R, because gh would otherwise resolve the target repository from the remotes+ # (daily-health.yml has the full note).run: |git config user.name "sync-bot"git config user.email "[email protected]"- NEW=$(git rev-parse upstream/main)- SHORT=$(git rev-parse --short upstream/main)- git rev-parse upstream/main > .upstream-ref- git add -A+ SHORT=${NEW:0:7}+ git add -A patches .upstream-ref dm scripts docs ref AGENTS.mdif git diff --cached --quiet; then echo "nothing to sync"; exit 0; figit checkout -b "sync/upstream-$SHORT"git commit -m "Sync upstream $SHORT"git push -u origin "sync/upstream-$SHORT"+ {+ echo "The patch queue re-applied on upstream \`${NEW:0:12}\` (was \`${OLD:0:12}\`): every patch applied, and \`scripts/patches.py check\`, the tests and a macOS host build passed. Merging brings seedds/nxnative to \`$NEW\`."+ echo+ echo "Upstream: https://github.com/seedds/nxnative/compare/${OLD:0:12}...${NEW:0:12}"+ echo+ echo '```'+ tail -40 bump.log+ echo '```'+ echo+ echo "Patches listed under dropped landed upstream; their files are deleted from patches/. \`scripts/patches.py status\` lists what is still carried."+ } > body.mdgh pr create -R "${{ github.repository }}" --base main --head "sync/upstream-$SHORT" \- --title "Sync upstream $SHORT" \- --body "The scheduled upstream sync, verified by scripts/sync_upstream.py (patchers, Python 3.9 parse, bash -n, the archive reader test, a macOS host build). Merging brings seedds/nxnative to \`$NEW\`.+ --title "Sync upstream $SHORT" --body-file body.md || echo "PR creation failed; the branch is pushed"- \`\`\`- $(tail -12 sync.log)- \`\`\`" || echo "PR creation failed; the branch is pushed"- - name: Open an issue when the sync fails- if: failure()- env:- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}- # -R, because the `upstream` remote added above makes gh resolve the target repository as- # seedds/nxnative, where this token cannot write (daily-health.yml has the full note).+ - name: Open an issue when a patch conflicts+ if: steps.bump.outputs.changed == 'conflict' || failure()run: |- NEW=$(git rev-parse upstream/main 2>/dev/null || echo '?')- tail -40 sync.log > sync-tail.log 2>/dev/null || echo "see the workflow log" > sync-tail.log- gh issue create -R "${{ github.repository }}" --title "Upstream sync failed at ${NEW:0:7}" \- --body "The scheduled sync could not re-apply the fork's patches or verify the build. The tree is untouched on main; run scripts/sync_upstream.py locally to see the full picture.-- \`\`\`- $(tail -40 sync.log 2>/dev/null)- \`\`\`" || echo "issue creation failed; the log is in sync.log"+ tail -60 bump.log > tail.log 2>/dev/null || echo "see the workflow log" > tail.log+ TITLE="Upstream sync blocked at ${NEW:0:7}"+ {+ echo "The nightly bump to \`${NEW:0:12}\` stopped at a patch that no longer applies. main is untouched. Whoever owns the patch refreshes it:"+ echo "run \`scripts/patches.py bump --to ${NEW:0:12}\` locally, resolve the conflict in the worktree it names, \`git am --continue\`, then \`scripts/patches.py refresh <worktree> --to ${NEW:0:12}\` (patches/README.md)."+ echo+ echo '```'+ cat tail.log+ echo '```'+ } > issue.md+ N=$(gh issue list -R "${{ github.repository }}" --state open --search "Upstream sync blocked in:title" --json number --jq '.[0].number // empty')+ if [ -n "$N" ]; then+ gh issue edit "$N" -R "${{ github.repository }}" --title "$TITLE" --body-file issue.md+ else+ gh issue create -R "${{ github.repository }}" --title "$TITLE" --body-file issue.md || echo "issue creation failed; the log is in the workflow run"+ fidiff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex 265293f9..83abb5ec 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -123,26 +123,32 @@ jobs:path: logsretention-days: 7- sync-patchers:- name: Sync patchers against seedds main (issue #92)+ patch-queue:+ name: Patch queue (check, dry bump against seedds main, issue #123)runs-on: ubuntu-latesttimeout-minutes: 10steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:persist-credentials: false+ fetch-depth: 0- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0with:python-version: '3.14'- # The patchers of scripts/sync_upstream.py are run on the files of seedds/nxnative main (the remote the fork syncs from) and of the last sync base- # (.upstream-ref): one that no longer fits, or whose marker upstream's own text satisfies, fails here before a sync stops or drops fork code silently.- - name: Fetch seedds main and the last sync base+ # scripts/patches.py check: the series applies to the pinned upstream (.upstream-ref) and reproduces the committed vendored tree. A vendored+ # file edited without a patch, a patch whose header is incomplete and a patch that touches the shader chain fail here. The dry bump to+ # seedds main only reports (the nightly sync opens the PR or the issue); it lists the patches that would conflict.+ - name: Fetch seedds main and the pinned baserun: |git remote add seedds https://github.com/seedds/nxnative.git- git fetch --no-tags --depth=1 seedds main- git fetch --no-tags --depth=1 seedds "$(cat .upstream-ref)"- - name: Patcher tests- run: python -m unittest -v scripts/tests/test_sync_patchers.py+ git fetch --no-tags seedds main+ git fetch --no-tags seedds "$(cat .upstream-ref)"+ - name: Patch queue check+ run: python scripts/patches.py check+ - name: Patch queue tests+ run: python -m unittest -v scripts/tests/test_patches.py+ - name: Dry bump to seedds main (report only)+ run: python scripts/patches.py bump --dry --to "$(git rev-parse seedds/main)" || truebuild:name: Build check (Mac host, gfx tests, iOS sources)diff --git a/CLAUDE.md b/CLAUDE.mdindex 54534ad7..0462563d 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -2,4 +2,4 @@- Read [AGENTS.md](AGENTS.md) first.- For an issue or a pull request, follow [CONTRIBUTING.md](CONTRIBUTING.md), section "For AI agents and other tools", and the templates in `.github/`.-- `dm/`, `scripts/`, `docs/`, `ref/` and `AGENTS.md` are vendored from upstream; do not edit them in a PR (see CONTRIBUTING.md).+- `dm/`, `scripts/`, `docs/`, `ref/` and `AGENTS.md` are upstream plus the patch queue in `patches/`: a change there is a patch (`scripts/patches.py export`, see [patches/README.md](patches/README.md)), not a direct edit; `scripts/patches.py check` fails otherwise.diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex ccda69ce..61b3c4d6 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -1,6 +1,6 @@# Contributing-Issues and pull requests are welcome. NX2Apple is the launcher (`frontend/`, `frontend-qt/`) and the glue around the [nxnative](https://github.com/seedds/nxnative) engine, which is vendored here and synced from upstream every day. [AGENTS.md](AGENTS.md) describes the engine.+Issues and pull requests are welcome. NX2Apple is the launcher (`frontend/`, `frontend-qt/`) and the glue around the [nxnative](https://github.com/seedds/nxnative) engine, which is vendored here as upstream plus a queue of patches, and bumped to upstream's latest every day. [AGENTS.md](AGENTS.md) describes the engine.## Reporting a problem@@ -22,7 +22,7 @@ Pick a form: **Game problem**, **Build problem** or **Launcher problem or idea**- One change per PR, off `main`. Commit messages say what changed and why, in plain English, as `git log` does.- Fill in the PR template: what and why, what was checked, screenshots for UI changes.- **`frontend/` and `frontend-qt/` are the fork's own:** change them freely. Run `cd frontend && swift test`; for a UI change also capture the views for visual QA (`NX_LAUNCHER_CAPTURE_DIR`, see [frontend/README.md](frontend/README.md#verification)).-- **`dm/`, `scripts/`, `docs/`, `ref/` and `AGENTS.md` are vendored from upstream.** The daily sync takes them file by file, so an edit there is reverted the next time upstream touches the file. The `pr-scope` check fails a PR that edits one. Send the change to seedds/nxnative first (it comes back with the sync), or ask a maintainer to add a patcher in `scripts/sync_upstream.py`. Files under `.github/` and in the repository root that are not in that list (this file, `CLAUDE.md`, the README) are the fork's.+- **`dm/`, `scripts/`, `docs/`, `ref/` and `AGENTS.md` are upstream plus the patch queue.** They are generated: seedds/nxnative at the commit in `.upstream-ref` with the patches in `patches/` applied, so a direct edit fails `scripts/patches.py check` (the `pr-scope` and `patch-queue` jobs) and would be lost on the next bump. Commit the change, turn it into a patch with `scripts/patches.py export <commit>`, fill in its header (`Upstream-Status`, `Reason`, `Issue`), and send the same change to seedds/nxnative so the patch can go: [patches/README.md](patches/README.md) walks through it and states the patch policy (what a patch may and may not change). Files under `.github/` and in the repository root that are not in that list (this file, `CLAUDE.md`, the README) are the fork's.## For AI agents and other toolsdiff --git a/README.md b/README.mdindex 4b934f92..bcf8f25e 100644--- a/README.md+++ b/README.md@@ -403,13 +403,15 @@ Open an issue with one of the [issue forms](https://github.com/LNPANDY/NX2Apple/## Staying current with upstream+The engine (`dm/`, `scripts/`, `docs/`, `ref/`, `AGENTS.md`) is [seedds/nxnative](https://github.com/seedds/nxnative)+at the commit in `.upstream-ref`, plus a queue of patches in [`patches/`](patches/README.md): one+`git format-patch` file per change, each saying why the fork carries it and where it stands upstream.A scheduled GitHub Actions workflow (`.github/workflows/sync-upstream.yml`, daily 21:30 UTC, also-runnable by hand) follows [seedds/nxnative](https://github.com/seedds/nxnative): it re-applies this-fork's features onto upstream's tree through `scripts/sync_upstream.py`, verifies the result-(Python 3.9 parse of every script, `bash -n`, the archive reader test, a macOS host build) and-pushes — or opens an issue with the log when a patch no longer fits, pushing nothing. The repo is a-fresh repository rather than a true fork, so GitHub's own "Sync fork" does not apply here; the last-synced upstream commit lives in `.upstream-ref`.+runnable by hand) moves the pin with `scripts/patches.py bump`, re-applies the patches with a+three-way merge, drops the ones upstream has taken, verifies the result (the patch queue check, the+tests, a macOS host build) and opens a pull request on `sync/upstream` — or an issue naming the+patch when one no longer applies. Nothing is pushed to `main`. `scripts/patches.py status` lists+what the fork carries.## How to playdiff --git a/README.zh-CN.md b/README.zh-CN.mdindex 1c47e462..9d684ea5 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -244,12 +244,13 @@ cd frontend && swift run # 或直接双击 frontend/nxnative.app## 跟随上游更新-一个定时的 GitHub Actions 工作流(`.github/workflows/sync-upstream.yml`,每天 21:30 UTC,也可手动-触发)跟随 [seedds/nxnative](https://github.com/seedds/nxnative):通过 `scripts/sync_upstream.py`-把本 fork 的特性重新应用到上游新树上,并做验证(全部脚本按 Python 3.9 解析、`bash -n`、归档读取-测试、macOS 宿主编译),通过即提交推送;补丁对不上时开一个 issue 并附日志,不推送。本仓库是独立-新建的仓库而非真正的 fork,GitHub 自带的「Sync fork」用不了;上次同步的上游提交记录在-`.upstream-ref`。+引擎(`dm/`、`scripts/`、`docs/`、`ref/`、`AGENTS.md`)就是 [seedds/nxnative](https://github.com/seedds/nxnative)+在 `.upstream-ref` 所记提交上的内容,再加 [`patches/`](patches/README.md) 里的一组补丁:每项改动一个+`git format-patch` 文件,写明本 fork 为什么带着它、它在上游处于什么状态。定时的 GitHub Actions 工作流+(`.github/workflows/sync-upstream.yml`,每天 21:30 UTC,也可手动触发)用 `scripts/patches.py bump`+移动基准提交,以三方合并重新应用补丁,丢掉上游已采纳的补丁,做验证(补丁队列检查、测试、macOS+宿主编译),然后在 `sync/upstream` 分支上开一个 pull request;某个补丁对不上时,开一个点名该补丁的+issue。不会向 `main` 直接推送。`scripts/patches.py status` 列出本 fork 带着的全部补丁。## 使用方法diff --git a/patches/README.md b/patches/README.mdnew file mode 100644index 00000000..e66f311f--- /dev/null+++ b/patches/README.md@@ -0,0 +1,95 @@+# The patch queue++`dm/`, `scripts/`, `docs/`, `ref/` and `AGENTS.md` are not edited by hand. They are+[seedds/nxnative](https://github.com/seedds/nxnative) at the commit in `../.upstream-ref`, plus the patches in this folder+applied in the order of `series` with `git am -3`. The same model carries Chromium's changes in Electron and the upstream+source's changes in a Debian package. The proposal and its reasons are [#123](https://github.com/LNPANDY/NX2Apple/issues/123).++Every patch is a `git format-patch` file. Its commit message carries a header:++```+Upstream-Status: forwarded seedds/nxnative#475 | pending | fork-only | backport <sha>+Reason: <one line: why the fork carries it>+Issue: LNPANDY/NX2Apple#<n>+```++| Upstream-Status | Meaning |+|---|---|+| `forwarded seedds/nxnative#N` | the same change is a pull request upstream; the patch goes when it merges |+| `pending` | meant for upstream, no pull request yet |+| `fork-only` | stays here: a fork product choice, or upstream declined it (`fork-only (declined seedds/nxnative#N)`) |+| `backport <sha>` | upstream has it (that commit); the patch goes on the next bump |++A status may carry a note in brackets. `scripts/patches.py status` lists every patch with its status, reason and age, so the+list of what the fork carries and why is one command, and it should keep shrinking.++## Day to day++```sh+python3 scripts/patches.py status # what we carry, and why+python3 scripts/patches.py check # series on the pin == the vendored tree of this checkout+python3 scripts/patches.py apply # rebuild the vendored tree from the pin and the series+python3 scripts/patches.py bump --to <sha> # move the pin (the nightly job does this)+python3 scripts/patches.py bump --dry --to <sha> # which patches would conflict, changing nothing+python3 scripts/patches.py export <commit> # a local commit becomes a patch+```++`apply` and `bump` need the upstream commit in the local repository (`git fetch seedds`, the remote+`https://github.com/seedds/nxnative.git`). Scratch worktrees go to `$PATCHES_TMP` (or `--tmp`), else the system's temporary folder.+`dm/fork_patches.txt` is generated by `apply` and `bump` (one patch name per line); do not edit it.++## Carrying a quick fix, and sending it upstream++1. Branch off `main`. Make the fix as an ordinary commit in the vendored files, with a message that says what and why.+2. `python3 scripts/patches.py export HEAD` writes `patches/NNNN-<subject>.patch`, adds it to `series`, and puts the header+ template into the message (`Upstream-Status: pending`, `Reason: TODO`, `Issue: TODO`; `--status`, `--reason` and `--issue` set them). Fill the three lines in. A range+ (`export main..HEAD`) makes one patch per commit. Rename the file if you want a shorter name; the name is what+ `fork_patches.txt` and `status` show.+3. `python3 scripts/patches.py check` must pass: the series applied to the pin gives exactly the tree you committed. Commit the+ patch file with the change in the same pull request. The files you edited are already in your commit, so they are part of the PR.+4. Send the same change to seedds/nxnative as a pull request from a branch off *their* main (`git fetch seedds`,+ `git switch -c fix-x seedds/main`, `git cherry-pick <commit>`), and set the patch to `forwarded seedds/nxnative#<N>`.+5. When upstream merges it, the next bump finds the patch empty and drops it (`landed upstream` in the sync PR). If upstream took it+ in a different form (as `Co-authored-by`, reworked), the patch conflicts instead; delete it then, and set nothing else.++## Bumping, and what a conflict is++`bump` applies the series onto the new upstream commit with a three-way merge. A patch that comes out empty is dropped and+listed as landed upstream. A patch that conflicts stops the bump: it names the patch, its Reason and its Upstream-Status, and+leaves the conflict in a worktree.++1. In that worktree, resolve the conflict, `git add`, `git am --continue`. If upstream has taken the patch's change in another+ form, `git am --skip` instead.+2. Apply the patches after it: `git am -3 <the remaining patch files>`.+3. `python3 scripts/patches.py refresh <worktree> --to <sha>` writes the commits back as the series (patches with no commit are+ deleted), moves `.upstream-ref` and regenerates the vendored tree.+4. Run the checks (`check`, the tests, the host build), commit, open the pull request.++The nightly workflow does the first step only: it opens a pull request on `sync/upstream` when every patch applies, and an issue+naming the blocking patch when one does not. Whoever owns the patch refreshes it.++## Patch policy++Upstream's compatibility is the baseline. A patch does not change it silently.++1. **The default is upstream's support matrix:** macOS 26.6 and later, Xcode 27.1, Apple silicon, the iPhones upstream supports. A+ normal build stays inside it.+2. **Going beyond it takes a marked patch,** `Upstream-Status: fork-only (declined seedds/nxnative#N)` or `fork-only`, with the+ reason. Example: BC textures decoded on the CPU for older iPhones (`bc-cpu-decode`, declined in seedds/nxnative#488). Such a+ patch acts only where it is needed (no change on supported hardware), has its own tests, and is ours to maintain: if it+ conflicts on a bump, we refresh it or drop it.+3. **Off limits:** the shader chain (`DMSH_CHAIN`, `dm/gfx/nvn/dmsh_chain.h`, the chain tools `dm/gfx/tools/dmsh_*`, `Program.cs`,+ `ios_metal.py`, `dmsh_chain.lock`, the translator `dmsh_xlate_bin`; AGENTS.md has the exact list, and `patches.py` reads it+ from there), upstream's tool pins, and lowering a minimum version. Shader caches and game profiles depend on them; diverging there+ makes our builds incompatible with upstream's caches and bug reports. `patches.py check` and `export` reject a patch that touches+ these paths.+4. **Bug reports go where they belong.** Every build records the patches it carries: `DMForkPatches` in the app's `Info.plist` and+ the first line of the log (`fork patches: a, b, c`, `Documents/log.txt` on iOS, the Mac app's log). The issue forms ask for that+ line, so a report from a configuration upstream does not support comes to NX2Apple, not to seedds. The list is every patch in the+ series, whatever its status, because any of them makes the build differ from upstream's.++## What is not a patch++`.github/`, `frontend/`, `frontend-qt/`, the README, CONTRIBUTING.md, CLAUDE.md and everything else outside the five vendored paths+belong to the fork and are edited directly. Inside the vendored paths, the tool's own files (`scripts/patches.py`,+`scripts/tests/test_patches.py`) and the generated `dm/fork_patches.txt` are not part of the generated tree.