Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
Environments move only between engines of one architecture. No prefix has been moved between the Intel engines and the native arm64 line, in either direction, so the engine picker, the advice after a failed launch and a recipe's engine ask no longer offer it. The ask offers a new environment and says why, and a move asked for anyway is refused with a log line. An environment whose engine folder is gone keeps every choice, as before. The engine download size in the ask and on the switch page counts each archive once, since two components can unpack folders of one archive and the store fetches it once. 536 tests pass on the M4.
Gauthier Piarrette6b64874e9b9b
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex c7e6a0f..eb41f3f 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -2872,6 +2872,14 @@ final class AppState {}/// What the bottle's Engine picker lists: installed engines, then known ones to download.+ /// Whether `bottle` may move to `target` (EngineStore.sameArch). The bottle's engine is read+ /// from the installed list, and from the bundled manifests only when its folder is gone.+ func canMove(_ bottle: Bottle, to target: EngineManifest) -> Bool {+ let id = bottle.settings.engineID+ let arch = engines.first { $0.id == id }?.manifest.arch ?? Self.bundledManifests.first { $0.id == id }?.arch+ return EngineStore.sameArch(current: arch, target: target.arch)+ }+func offeredEngines(for bottle: Bottle) -> [EngineStore.OfferedEngine] {EngineStore.offeredEngines(installed: engines, known: Self.knownManifests, current: bottle.settings.engineID)}@@ -2880,6 +2888,11 @@ final class AppState {/// bundled manifest. Licenses accepted on any installed engine carry over.func moveBottle(_ bottle: Bottle, toEngineID id: String, done: DoneState? = nil) {guard !busy else { return }+ if let target = engines.first(where: { $0.id == id })?.manifest ?? Self.knownManifests.first(where: { $0.id == id }),+ !canMove(bottle, to: target) {+ appendLog("\(bottle.name) stays on \(bottle.settings.engineID): \(id) is built for another architecture, and an environment does not move between the two")+ return+ }if let installed = engines.first(where: { $0.id == id }) { moveBottle(bottle, to: installed, done: done); return }guard let manifest = Self.knownManifests.first(where: { $0.id == id }) else { return }let accepted = Set(engines.flatMap { $0.manifest.acceptedLicenses ?? [] })diff --git a/Sources/HighballApp/EngineAsk.swift b/Sources/HighballApp/EngineAsk.swiftindex 816d094..47f2dda 100644--- a/Sources/HighballApp/EngineAsk.swift+++ b/Sources/HighballApp/EngineAsk.swift@@ -10,7 +10,7 @@ extension GamePageCopy {}static func downloadSize(_ m: EngineManifest) -> String {- ByteCountFormatter.string(fromByteCount: Int64(m.components.values.compactMap(\.size).reduce(0, +)), countStyle: .file)+ ByteCountFormatter.string(fromByteCount: Int64(m.downloadBytes), countStyle: .file)}/// The fix names an engine this build does not ship: the database moved ahead of the app.@@ -25,14 +25,27 @@ extension GamePageCopy {/// the hard way when an old revision could not show Steam's window (highball#262)./// `existing` names an environment already on that engine and whether the game is installed/// in it; the ask then offers it first (highball-db#318).+ /// `canMove` is false when the environment's engine is of another architecture than the+ /// recipe's (EngineStore.sameArch): only a new environment is offered then.static func engineAsk(recipe: HighballKit.Recipe, manifest: EngineManifest, installed: Bool, others: Int,- existing: (name: String, holdsGame: Bool)? = nil) -> String {- guard let existing else { return engineAskBody(recipe: recipe, manifest: manifest, installed: installed, others: others) }+ existing: (name: String, holdsGame: Bool)? = nil, canMove: Bool = true) -> String {+ guard let existing else {+ guard canMove else { return engineAskOtherArch(recipe: recipe, manifest: manifest, installed: installed) }+ return engineAskBody(recipe: recipe, manifest: manifest, installed: installed, others: others)+ }return existing.holdsGame? String(format: L("'%@' is already on the %@ engine and has the game installed, so it plays there. This environment stays as it is."), existing.name, shortEngineName(manifest)): String(format: L("'%@' is already on the %@ engine. Using it installs the game there, with what it needs, and this environment stays as it is."), existing.name, shortEngineName(manifest))}+ private static func engineAskOtherArch(recipe: HighballKit.Recipe, manifest: EngineManifest, installed: Bool) -> String {+ let download = installed ? "" : String(format: L(", after a download of about %@"), downloadSize(manifest))+ let text = manifest.isNativeARM64+ ? L("%@ is verified on the %@ engine, which runs natively on Apple silicon. This environment's engine runs through Rosetta, so the environment cannot move to it. A new environment starts empty%@, and the game has to be installed again.")+ : L("%@ is verified on the %@ engine, which runs through Rosetta. This environment's engine runs natively on Apple silicon, so the environment cannot move to it. A new environment starts empty%@, and the game has to be installed again.")+ return String(format: text, recipe.title, shortEngineName(manifest), download)+ }+private static func engineAskBody(recipe: HighballKit.Recipe, manifest: EngineManifest, installed: Bool, others: Int) -> String {let download = installed ? "" : String(format: L(", after a download of about %@"), downloadSize(manifest))if others == 0 {diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swiftindex a44e5bb..e2f0be1 100644--- a/Sources/HighballApp/HighballApp.swift+++ b/Sources/HighballApp/HighballApp.swift@@ -408,6 +408,9 @@ private extension View {Button(String(format: L("Use '%@'"), fit.name)) { state.useEnvironment(fit, for: pending.recipe, item: item) }Button(String(format: L("New environment for %@"), pending.recipe.title)) { state.createEnvironment(for: pending.recipe, on: pending.manifest, item: pending.item) }Button(L("Not now"), role: .cancel) { state.pendingEngine = nil }+ } else if !state.canMove(pending.bottle, to: pending.manifest) {+ Button(String(format: L("New environment for %@"), pending.recipe.title)) { state.createEnvironment(for: pending.recipe, on: pending.manifest, item: pending.item) }+ Button(L("Not now"), role: .cancel) { state.pendingEngine = nil }} else if others > 0 {Button(String(format: L("New environment for %@"), pending.recipe.title)) { state.createEnvironment(for: pending.recipe, on: pending.manifest, item: pending.item) }Button(L("Move this environment")) { state.moveEnvironment(for: pending.recipe, bottle: pending.bottle, to: pending.manifest) }@@ -420,7 +423,8 @@ private extension View {} message: { pending inText(GamePageCopy.engineAsk(recipe: pending.recipe, manifest: pending.manifest, installed: state.engines.contains { $0.id == pending.manifest.id },others: state.otherProgramCount(in: pending.bottle, besides: pending.recipe),- existing: pending.fit.map { ($0.name, pending.item?.otherBottles.contains($0.name) == true) }))+ existing: pending.fit.map { ($0.name, pending.item?.otherBottles.contains($0.name) == true) },+ canMove: state.canMove(pending.bottle, to: pending.manifest)))}}@MainActor func updateAsk(_ state: AppState) -> some View {diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swiftindex cdf2a45..ca9a5ec 100644--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@ -252,6 +252,8 @@ enum L10n {"Creating the %@ environment on %@": "Création de l'environnement %@ sur %@","a download when the engine is new, then a first boot of about 90 seconds": "un téléchargement si le moteur est nouveau, puis un premier démarrage d'environ 90 secondes",", after a download of about %@": ", après un téléchargement d'environ %@",+ "%@ is verified on the %@ engine, which runs natively on Apple silicon. This environment's engine runs through Rosetta, so the environment cannot move to it. A new environment starts empty%@, and the game has to be installed again.": "%@ est vérifié sur le moteur %@, qui tourne nativement sur Apple silicon. Le moteur de cet environnement passe par Rosetta, donc l'environnement ne peut pas y être déplacé. Un nouvel environnement part de zéro%@, et le jeu doit être réinstallé.",+ "%@ is verified on the %@ engine, which runs through Rosetta. This environment's engine runs natively on Apple silicon, so the environment cannot move to it. A new environment starts empty%@, and the game has to be installed again.": "%@ est vérifié sur le moteur %@, qui passe par Rosetta. Le moteur de cet environnement tourne nativement sur Apple silicon, donc l'environnement ne peut pas y être déplacé. Un nouvel environnement part de zéro%@, et le jeu doit être réinstallé.","%@ is verified on the %@ engine, and this environment is not on it. Moving this environment switches it there%@ and keeps everything installed; the Windows setup re-runs when needed, a minute or two. A new environment starts empty, so the game has to be installed again.": "%@ est vérifié sur le moteur %@, et cet environnement n'est pas dessus. Déplacer cet environnement le fait passer dessus%@ et garde tout ce qui est installé ; la configuration Windows se refait au besoin, une minute ou deux. Un nouvel environnement part vide, donc le jeu doit être réinstallé.","%@ is verified on the %@ engine, and this environment is not on it. A new environment keeps %@ where they are and starts empty, so the game has to be installed again. Moving this environment switches it there%@ and keeps everything installed, but %@ then run on that engine too, which suits some games and not others; the Windows setup re-runs when needed, a minute or two.": "%@ est vérifié sur le moteur %@, et cet environnement n'est pas dessus. Un nouvel environnement laisse %@ en place et part vide, donc le jeu doit être réinstallé. Déplacer cet environnement le fait passer dessus%@ et garde tout ce qui est installé, mais %@ tournent alors aussi sur ce moteur, ce qui convient à certains jeux et pas à d'autres ; la configuration Windows se refait au besoin, une minute ou deux.","the other program installed here": "l'autre programme installé ici",diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swiftindex 21f2907..86af13d 100644--- a/Sources/HighballKit/EngineStore.swift+++ b/Sources/HighballKit/EngineStore.swift@@ -151,11 +151,20 @@ public struct EngineStore: Sendable {/// bottle is not on it (the newer one, usually), else the newest other installed engine./// nil with a single engine installed.public static func alternateEngine(for currentID: String, installed: [InstalledEngine], defaultID: String?) -> InstalledEngine? {- if let d = installed.first(where: { $0.id == defaultID }), d.id != currentID { return d }- return installed.filter { $0.id != currentID }+ let arch = installed.first { $0.id == currentID }?.manifest.arch+ let movable = installed.filter { sameArch(current: arch, target: $0.manifest.arch) }+ if let d = movable.first(where: { $0.id == defaultID }), d.id != currentID { return d }+ return movable.filter { $0.id != currentID }.max { $0.id.compare($1.id, options: .numeric) == .orderedAscending }}+ /// Whether an environment on an engine of the `current` architecture may move to an engine of+ /// the `target` one. No prefix has been moved between the Intel engines and the native arm64+ /// line, in either direction, so the picker, the failure advice and a recipe's engine ask+ /// offer a new environment instead. An unknown current architecture (the engine's folder is+ /// gone) keeps every engine offered, as before.+ public static func sameArch(current: String?, target: String) -> Bool { current == nil || current == target }+/// One row per engine the app can put a bottle on: every installed engine, then every/// bundled manifest that is not installed yet (it downloads when chosen). Newest first/// within each group, by numeric-aware id order. When the bottle's own engine is in@@ -170,11 +179,14 @@ public struct EngineStore: Sendable {public static func offeredEngines(installed: [InstalledEngine], known: [EngineManifest], current: String? = nil,macOS: String = EngineManifest.currentMacOS) -> [OfferedEngine] {let newestFirst: (String, String) -> Bool = { $0.compare($1, options: .numeric) == .orderedDescending }- let have = installed.sorted { newestFirst($0.id, $1.id) }.map { OfferedEngine(id: $0.id, installed: true) }- let ids = Set(have.map(\.id))+ let ids = Set(installed.map(\.id))+ let arch = installed.first { $0.id == current }?.manifest.arch ?? known.first { $0.id == current }?.arch+ let have = installed.filter { sameArch(current: arch, target: $0.manifest.arch) }+ .sorted { newestFirst($0.id, $1.id) }.map { OfferedEngine(id: $0.id, installed: true) }// A manifest with a macOS floor above this Mac is not offered: it would download and// then run untested (r6's D3DMetal was measured on 27 only). Installed engines stay listed.- let more = known.filter { !ids.contains($0.id) && $0.runs(onMacOS: macOS) }.sorted { newestFirst($0.id, $1.id) }+ let more = known.filter { !ids.contains($0.id) && $0.runs(onMacOS: macOS) && sameArch(current: arch, target: $0.arch) }+ .sorted { newestFirst($0.id, $1.id) }.map { OfferedEngine(id: $0.id, installed: false) }var rows = have + moreif let current, !rows.contains(where: { $0.id == current }) { rows.append(OfferedEngine(id: current, installed: false, missing: true)) }diff --git a/Sources/HighballKit/Manifest.swift b/Sources/HighballKit/Manifest.swiftindex 430fbf3..b840eb6 100644--- a/Sources/HighballKit/Manifest.swift+++ b/Sources/HighballKit/Manifest.swift@@ -131,6 +131,14 @@ public struct EngineManifest: Codable, Sendable, Identifiable {return "\(id)-\(digest.prefix(8))"}+ /// What installing this engine downloads, each archive once: two components can unpack+ /// different folders of one archive, and the store fetches it once (EngineStore.download).+ public var downloadBytes: Int {+ var seen = Set<URL>()+ return components.values.sorted { $0.url.absoluteString < $1.url.absoluteString }+ .reduce(0) { total, c in seen.insert(c.url).inserted ? total + (c.size ?? 0) : total }+ }+public static func load(from url: URL) throws -> EngineManifest {let data = try Data(contentsOf: url)let decoder = JSONDecoder()diff --git a/Tests/HighballKitTests/EngineArchTests.swift b/Tests/HighballKitTests/EngineArchTests.swiftindex a246069..ba0a7fd 100644--- a/Tests/HighballKitTests/EngineArchTests.swift+++ b/Tests/HighballKitTests/EngineArchTests.swift@@ -25,6 +25,38 @@ final class EngineArchTests: XCTestCase {try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: url.path)}+ // MARK: Environments stay on one architecture++ /// No prefix has been moved between the Intel engines and the arm64 line, so the picker and+ /// the failure advice never offer it; a recipe's engine ask offers a new environment instead.+ func testEnvironmentsMoveOnlyWithinOneArchitecture() {+ let intel = manifest("x86_64"), arm = manifest("arm64")+ var intel2 = intel; intel2.id = "x64-test-r2"+ let root = tempRoot("hb-arch-move")+ let installed = [InstalledEngine(manifest: intel, root: root.appending(path: intel.id)),+ InstalledEngine(manifest: arm, root: root.appending(path: arm.id))]+ XCTAssertEqual(EngineStore.offeredEngines(installed: installed, known: [intel2], current: intel.id, macOS: "27.0").map(\.id),+ ["x64-test-r1", "x64-test-r2"])+ XCTAssertEqual(EngineStore.offeredEngines(installed: installed, known: [intel2], current: arm.id, macOS: "27.0").map(\.id),+ ["arm64-test-r1"])+ XCTAssertEqual(Set(EngineStore.offeredEngines(installed: installed, known: [intel2], current: "gone-r1", macOS: "27.0").map(\.id)),+ ["x64-test-r1", "arm64-test-r1", "x64-test-r2", "gone-r1"], "an environment whose engine is gone keeps every choice")+ XCTAssertNil(EngineStore.alternateEngine(for: arm.id, installed: installed, defaultID: intel.id), "an Intel default is no advice for an arm64 environment")+ XCTAssertNil(EngineStore.alternateEngine(for: intel.id, installed: installed, defaultID: nil))+ XCTAssertTrue(EngineStore.sameArch(current: nil, target: "arm64"))+ XCTAssertFalse(EngineStore.sameArch(current: "x86_64", target: "arm64"))+ XCTAssertFalse(EngineStore.sameArch(current: "arm64", target: "x86_64"))+ }++ func testTheDownloadSizeCountsEachArchiveOnce() {+ var m = manifest("arm64")+ let renderers = URL(string: "https://example.com/renderers-arm64.tar.xz")!+ m.components["vkd3d"] = EngineManifest.Component(kind: "renderer", url: renderers, sha256: "a", size: 100)+ m.components["dxvk"] = EngineManifest.Component(kind: "renderer", url: renderers, sha256: "a", size: 100)+ m.components["wine"] = EngineManifest.Component(kind: "wine", url: URL(string: "https://example.com/wine.tar.xz")!, sha256: "b", size: 50)+ XCTAssertEqual(m.downloadBytes, 150, "two folders of one archive are one download")+ }+func testDirectoriesFollowTheArchitecture() {let intel = manifest("x86_64"), arm = manifest("arm64")XCTAssertEqual(intel.pe64LibDir, "x86_64-windows")