Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Verify DOTNET_ROOT by running the shader translator; never fall back to a guess

LNPANDYd0ed53df8286
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index 2d8e5383..b6215632 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -544,13 +544,16 @@ final class BuildModel: ObservableObject {
p.arguments = args
p.currentDirectoryURL = URL(fileURLWithPath: repoPath)
// The root of the runtime the apphost looks for: derived from the detected installation,
- // not assumed to be ~/.dotnet (Homebrew keeps it in …/opt/dotnet/libexec). Both variables
- // carry the same root, as the apphost checks the arch-specific one first.
- let droot = Self.dotnetRoot(for: dotnetPath.isEmpty ? "dotnet" : dotnetPath)
- ?? (dotnetPath as NSString).deletingLastPathComponent
- p.environment = ["PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
- "DOTNET_ROOT": droot, "DOTNET_ROOT_ARM64": droot,
- "USER": NSUserName(), "HOME": NSHomeDirectory(), "LANG": "en_US.UTF-8"]
+ // not assumed to be ~/.dotnet (Homebrew keeps it in …/opt/dotnet/libexec). Only set when the
+ // derivation actually answered — a wrong root is worse than none, and the pipeline derives
+ // and verifies its own (DOTNET_ROOT, build_ipa_from_nsp.py) when this is absent.
+ var denv: [String: String] = ["PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
+ "USER": NSUserName(), "HOME": NSHomeDirectory(), "LANG": "en_US.UTF-8"]
+ if let droot = Self.dotnetRoot(for: dotnetPath.isEmpty ? "dotnet" : dotnetPath) {
+ denv["DOTNET_ROOT"] = droot // both variables carry the same root, as the apphost checks the arch-specific one first
+ denv["DOTNET_ROOT_ARM64"] = droot
+ }
+ p.environment = denv
let pipe = Pipe()
p.standardOutput = pipe; p.standardError = pipe
p.terminationHandler = { [weak self] status in
@@ -960,7 +963,10 @@ final class BuildModel: ObservableObject {
p.waitUntilExit()
guard p.terminationStatus == 0 else { return nil }
let out = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""
- return parseDotnetRoot(out) ?? ((dotnet as NSString).deletingLastPathComponent)
+ // No directory fallback: for Homebrew's symlink layout the binary's directory is not the root,
+ // and a wrong DOTNET_ROOT is worse than none (the apphost stops searching once it is set).
+ // When this returns nil the pipeline derives and verifies a root itself.
+ return parseDotnetRoot(out)
}
nonisolated static func findDotnet() -> (path: String, ok: Bool) {
diff --git a/scripts/build_ipa_from_nsp.py b/scripts/build_ipa_from_nsp.py
index e7bf989d..34a402e5 100755
--- a/scripts/build_ipa_from_nsp.py
+++ b/scripts/build_ipa_from_nsp.py
@@ -1629,6 +1629,37 @@ def main(args=None):
break
except Exception: pass
env['DOTNET_ROOT'] = os.environ['DOTNET_ROOT'] = root or str(Path(dn).resolve().parent)
+ # The shader translator (dmsh_xlate_bin/dmsh_xlate) is a framework-dependent apphost like
+ # nx_extract, and a set-but-wrong DOTNET_ROOT is worse than none: the apphost stops searching
+ # once the variable is there, so a stale root from the environment (or the fallback above, wrong
+ # for Homebrew's symlink layout) kills the shader step while `dotnet` on PATH keeps working —
+ # nx_extract builds fine, then dmsh_build refuses with "'xlate_source: lock … / actual' empty".
+ # Verify by actually running the translator; when it answers nothing, try candidate roots and
+ # keep the first that works. With none verified the variable is dropped, so the apphost at least
+ # searches its default locations.
+ xlate_bin = repo / 'dm/gfx/tools/dmsh_xlate_bin/dmsh_xlate'
+ def xlate_answers(root):
+ e = dict(env)
+ if root: e['DOTNET_ROOT'] = str(root)
+ else: e.pop('DOTNET_ROOT', None)
+ try:
+ r = subprocess.run([str(xlate_bin), '--source-sha'], capture_output=True, text=True, env=e, timeout=120)
+ return r.returncode == 0 and bool(r.stdout.strip())
+ except Exception:
+ return False
+ if not xlate_answers(env.get('DOTNET_ROOT')):
+ cands = []
+ if dn := shutil.which('dotnet', path=env['PATH']):
+ real = Path(dn).resolve()
+ for base in (real.parent.parent, real.parent.parent.parent):
+ cands += [base / 'libexec', base] # Homebrew's bin/../libexec; share/dotnet and aliases
+ cands += [Path.home() / '.dotnet', Path('/usr/local/share/dotnet'), Path('/opt/homebrew/opt/dotnet/libexec')]
+ if hit := next((c for c in cands if c.is_dir() and xlate_answers(c)), None):
+ env['DOTNET_ROOT'] = os.environ['DOTNET_ROOT'] = str(hit)
+ say(f'DOTNET_ROOT: {hit} (verified — the shader translator runs)')
+ elif env.get('DOTNET_ROOT'):
+ del env['DOTNET_ROOT']; os.environ.pop('DOTNET_ROOT', None)
+ say('DOTNET_ROOT: removed (none verified — the apphost searches its default locations)')
env.setdefault('J', str(os.cpu_count() or 8)) # shader_split.py's and dmsh_build.py's workers (their default is 8)
py = sys.executable
app, fam = scan_nsps(nsp_dir)
diff --git a/scripts/sync_upstream.py b/scripts/sync_upstream.py
index 0f5acdef..ad392f27 100644
--- a/scripts/sync_upstream.py
+++ b/scripts/sync_upstream.py
@@ -329,7 +329,38 @@ def patch_nsp(t):
elif p: root = p
break
except Exception: pass
- env['DOTNET_ROOT'] = os.environ['DOTNET_ROOT'] = root or str(Path(dn).resolve().parent)""")]))
+ env['DOTNET_ROOT'] = os.environ['DOTNET_ROOT'] = root or str(Path(dn).resolve().parent)
+ # The shader translator (dmsh_xlate_bin/dmsh_xlate) is a framework-dependent apphost like
+ # nx_extract, and a set-but-wrong DOTNET_ROOT is worse than none: the apphost stops searching
+ # once the variable is there, so a stale root from the environment (or the fallback above, wrong
+ # for Homebrew's symlink layout) kills the shader step while `dotnet` on PATH keeps working —
+ # nx_extract builds fine, then dmsh_build refuses with \"'xlate_source: lock … / actual' empty\".
+ # Verify by actually running the translator; when it answers nothing, try candidate roots and
+ # keep the first that works. With none verified the variable is dropped, so the apphost at least
+ # searches its default locations.
+ xlate_bin = repo / 'dm/gfx/tools/dmsh_xlate_bin/dmsh_xlate'
+ def xlate_answers(root):
+ e = dict(env)
+ if root: e['DOTNET_ROOT'] = str(root)
+ else: e.pop('DOTNET_ROOT', None)
+ try:
+ r = subprocess.run([str(xlate_bin), '--source-sha'], capture_output=True, text=True, env=e, timeout=120)
+ return r.returncode == 0 and bool(r.stdout.strip())
+ except Exception:
+ return False
+ if not xlate_answers(env.get('DOTNET_ROOT')):
+ cands = []
+ if dn := shutil.which('dotnet', path=env['PATH']):
+ real = Path(dn).resolve()
+ for base in (real.parent.parent, real.parent.parent.parent):
+ cands += [base / 'libexec', base] # Homebrew's bin/../libexec; share/dotnet and aliases
+ cands += [Path.home() / '.dotnet', Path('/usr/local/share/dotnet'), Path('/opt/homebrew/opt/dotnet/libexec')]
+ if hit := next((c for c in cands if c.is_dir() and xlate_answers(c)), None):
+ env['DOTNET_ROOT'] = os.environ['DOTNET_ROOT'] = str(hit)
+ say(f'DOTNET_ROOT: {hit} (verified — the shader translator runs)')
+ elif env.get('DOTNET_ROOT'):
+ del env['DOTNET_ROOT']; os.environ.pop('DOTNET_ROOT', None)
+ say('DOTNET_ROOT: removed (none verified — the apphost searches its default locations)')""")]))
P.append(('3.9 survey note', "listed = ', '.join('{} ({})'.format(n, mods[n]['kind'])", [(
''' if extra: notes.append(f'modules besides main / sdk: {", ".join(f"{n} ({mods[n]["kind"]})" for n in extra)}; the provisional profile loads {G["modules"][0]} (load order main, subsdk*, sdk)')''',
''' if extra: