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
winetricks' wine gets the engine's library paths back. winetricks runs under /bin/bash, which drops every DYLD_* variable under SIP, so the wine processes it started had no library path. The Wine 10 engines find their libraries through their own search path and never showed it; the Wine 11 engines open FreeType by name through that path, so every winetricks install on them ran without fonts. A player's .NET 4.8 install on r23 printed that error over a thousand times while it crashed in a loop until the Mac stopped answering (highball#241); on the M4 the same install finished on r23 and r25 even without fonts (1,758 and 586 errors, no crash), so the loop's own cause is not settled. Measured on the M4: a cmd /c echo on x64-crossover26.3-r25 printed 'cannot find the FreeType font library' 12 times through /bin/sh and never when the variable reached wine, and the winetricks win10 verb 3 times the old way and none through this change. The paths now travel as HB_KEEP_* and a script under Highball's tools folder exports them and starts the engine's wine, in the app's recipe path and the CLI. dotnet48 through the app's recipe code on r25 in an isolated home: installed in 236 s, no FreeType error. 589 tests pass on the M4.
Gauthier Piarrette761456bd2b17
diff --git a/Sources/HighballKit/Recipe.swift b/Sources/HighballKit/Recipe.swiftindex 631da29..e6b8322 100644--- a/Sources/HighballKit/Recipe.swift+++ b/Sources/HighballKit/Recipe.swift@@ -587,6 +587,8 @@ public struct RecipeRunner: Sendable {let joined = WineRunner.joiningLiveServer(env, prefix: bottle.url)if joined != env { log?("[\(recipe.id)] the environment runs with sync \(SyncMode(environment: joined).rawValue), so winetricks uses it too") }env = joined+ // The library paths reach winetricks' wine through a script, past bash (see WinetricksWine).+ env = WinetricksWine.environment(env, wine: engine.wineBinary, script: try WinetricksWine.installScript(in: paths))// winetricks shells out to cabextract for Microsoft's cabinet installers (the core// fonts among them) and macOS does not ship it, so the app bundles one under// Resources/tools (highball#96). HIGHBALL_TOOLS names another directory, for the CLI.diff --git a/Sources/HighballKit/WinetricksWine.swift b/Sources/HighballKit/WinetricksWine.swiftnew file mode 100644index 0000000..d036ff9--- /dev/null+++ b/Sources/HighballKit/WinetricksWine.swift@@ -0,0 +1,58 @@+import Foundation++/// The wine winetricks starts. winetricks runs under /bin/bash, and with SIP on macOS drops every+/// DYLD_* variable before bash starts, so each wine process winetricks started had no library path.+/// The Wine 10 engines find their libraries without one and never showed it. The Wine 11 engines+/// open FreeType by name through that path, so every winetricks install on them ran without fonts.+/// A player's .NET 4.8 install on r23 printed that error over a thousand times while it crashed in+/// a loop until the Mac stopped answering (highball#241). On the M4 the same install finished on+/// r23 and r25 even without fonts (1,758 and 586 of those errors, no crash), so the loop's own+/// cause is not settled. Measured on the M4, 2026-10-23: one `cmd /c echo` on+/// x64-crossover26.3-r25 printed "cannot find the FreeType font library" 12 times started through+/// /bin/sh, and never when the variable reached wine.+///+/// The library paths travel under other names, and a small script puts them back right before it+/// starts the engine's wine: a variable the script sets itself reaches its child, since SIP only+/// drops the ones a protected program inherits.+public enum WinetricksWine {+ /// What a launch hands wine and winetricks lost on the way.+ static let carried = ["DYLD_FALLBACK_LIBRARY_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH", "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH"]+ static let keptPrefix = "HB_KEEP_"++ static let script = """+ #!/bin/sh+ # Highball: winetricks runs under /bin/bash, where SIP drops the DYLD_* variables. Put the+ # engine's library paths back, then start the engine's wine.+ for name in \(carried.joined(separator: " ")); do+ eval "value=\\${\(keptPrefix)$name-}"+ if [ -n "$value" ]; then export "$name=$value"; fi+ done+ exec "$HB_WINE" "$@"++ """++ /// The script, written under Highball's tools folder when it is missing or out of date.+ public static func installScript(in paths: HighballPaths) throws -> URL {+ let dir = paths.home.appending(path: "tools/winetricks-wine", directoryHint: .isDirectory)+ // Named wine in a folder of its own, so winetricks' name-based guesses (wine64 beside wine) still read it as wine.+ let file = dir.appending(path: "wine")+ let fm = FileManager.default+ if (try? String(contentsOf: file, encoding: .utf8)) != script {+ try fm.createDirectory(at: dir, withIntermediateDirectories: true)+ try Data(script.utf8).write(to: file, options: .atomic)+ }+ try fm.setAttributes([.posixPermissions: 0o755], ofItemAtPath: file.path)+ return file+ }++ /// The environment for a winetricks run: WINE is the script, HB_WINE the engine's wine, and each+ /// library path is also under its HB_KEEP_ name. WINE_BIN stays the engine's wine, which+ /// winetricks only reads to tell the binary's architecture.+ public static func environment(_ env: [String: String], wine: URL, script: URL) -> [String: String] {+ var out = env+ for name in carried { if let value = env[name] { out[keptPrefix + name] = value } }+ out["HB_WINE"] = wine.path+ out["WINE"] = script.path+ return out+ }+}diff --git a/Sources/highball/main.swift b/Sources/highball/main.swiftindex 047aa89..f36254b 100644--- a/Sources/highball/main.swift+++ b/Sources/highball/main.swift@@ -538,8 +538,9 @@ struct Tricks: AsyncParsableCommand {env["WINE_BINDIR"] = eng.wineBinary.deletingLastPathComponent().pathenv["WINESERVER"] = eng.wineserverBinary.pathenv["PATH"] = "\(eng.engineDir.appending(path: "bin").path):/usr/bin:/bin:/usr/sbin:/sbin"- // bash, not sh: same as the recipe path — winetricks' macOS guidance, and sh strips- // the DYLD vars winetricks' children need (issue #16 fix said "both paths"; this one lagged).+ // bash, as the recipe path runs it (winetricks' macOS guidance). bash drops the DYLD vars+ // under SIP like sh does, so they reach wine through WinetricksWine's script.+ env = WinetricksWine.environment(env, wine: eng.wineBinary, script: try WinetricksWine.installScript(in: HighballPaths()))let out = try Shell.capture("/bin/bash", [wt.path, "--unattended"] + verbs, env: env)print(out.split(separator: "\n").suffix(12).joined(separator: "\n"))}diff --git a/Tests/HighballKitTests/WinetricksWineTests.swift b/Tests/HighballKitTests/WinetricksWineTests.swiftnew file mode 100644index 0000000..764f943--- /dev/null+++ b/Tests/HighballKitTests/WinetricksWineTests.swift@@ -0,0 +1,61 @@+import XCTest+@testable import HighballKit++/// winetricks runs under /bin/bash, which drops the DYLD_* variables under SIP, and the Wine 11+/// engines then found no FreeType during every winetricks install (highball#241).+final class WinetricksWineTests: XCTestCase {+ func testTheLibraryPathsTravelUnderOtherNames() {+ let wine = URL(fileURLWithPath: "/engines/x/engine/bin/wine"), script = URL(fileURLWithPath: "/hb/tools/winetricks-wine/wine")+ let env = WinetricksWine.environment(["DYLD_FALLBACK_LIBRARY_PATH": "/a b/frameworks:/c", "WINE": wine.path,+ "WINE_BIN": wine.path, "WINEPREFIX": "/p"], wine: wine, script: script)+ XCTAssertEqual(env["WINE"], script.path, "winetricks starts the script")+ XCTAssertEqual(env["HB_WINE"], wine.path, "the script starts the engine's wine")+ XCTAssertEqual(env["WINE_BIN"], wine.path, "winetricks reads the architecture off the real binary")+ XCTAssertEqual(env["HB_KEEP_DYLD_FALLBACK_LIBRARY_PATH"], "/a b/frameworks:/c")+ XCTAssertEqual(env["DYLD_FALLBACK_LIBRARY_PATH"], "/a b/frameworks:/c", "a run where DYLD gets through keeps it")+ XCTAssertNil(env["HB_KEEP_DYLD_LIBRARY_PATH"], "nothing is invented for a variable the environment does not set")+ XCTAssertEqual(env["WINEPREFIX"], "/p")+ }++ /// The script's loop, run by /bin/sh the way winetricks reaches it: a path with spaces comes back+ /// whole, and a variable with nothing kept stays unset.+ func testTheScriptPutsThePathsBack() throws {+ let body = WinetricksWine.script.replacingOccurrences(of: "exec \"$HB_WINE\" \"$@\"", with: "export -p")+ XCTAssertNotEqual(body, WinetricksWine.script)+ let out = try run(["-c", body], env: ["HB_KEEP_DYLD_FALLBACK_LIBRARY_PATH": "/Users/x/Library/Application Support/Highball/engines/r/frameworks:/y"])+ // export -p quotes the way the shell likes (bash double, dash single), so the quotes are left out.+ let exported = out.split(separator: "\n").map { line -> String in+ var s = String(line)+ for prefix in ["export ", "declare -x "] where s.hasPrefix(prefix) { s.removeFirst(prefix.count) }+ return s.replacingOccurrences(of: "\"", with: "").replacingOccurrences(of: "'", with: "")+ }+ XCTAssertTrue(exported.contains("DYLD_FALLBACK_LIBRARY_PATH=/Users/x/Library/Application Support/Highball/engines/r/frameworks:/y"), out)+ XCTAssertFalse(exported.contains { $0.hasPrefix("DYLD_LIBRARY_PATH") }, out)+ }++ func testTheScriptStartsWineWithItsArguments() throws {+ let dir = FileManager.default.temporaryDirectory.appending(path: "hb-wtw-\(UUID().uuidString)", directoryHint: .isDirectory)+ defer { try? FileManager.default.removeItem(at: dir) }+ let script = try WinetricksWine.installScript(in: HighballPaths(home: dir))+ XCTAssertEqual(try WinetricksWine.installScript(in: HighballPaths(home: dir)), script, "a second call keeps the same file")+ let stub = dir.appending(path: "stub-wine")+ try Data("#!/bin/sh\necho \"wine got: $*\"\n".utf8).write(to: stub)+ try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: stub.path)+ let out = try run(["-c", "\"$0\" cmd.exe /c 'echo %AppData%'", script.path], env: ["HB_WINE": stub.path])+ XCTAssertEqual(out.trimmingCharacters(in: .whitespacesAndNewlines), "wine got: cmd.exe /c echo %AppData%")+ }++ private func run(_ args: [String], env: [String: String]) throws -> String {+ let p = Process()+ p.executableURL = URL(fileURLWithPath: "/bin/sh")+ p.arguments = args+ p.environment = ["PATH": "/usr/bin:/bin"].merging(env) { $1 }+ let pipe = Pipe()+ p.standardOutput = pipe+ p.standardError = pipe+ try p.run()+ let data = pipe.fileHandleForReading.readDataToEndOfFile()+ p.waitUntilExit()+ return String(decoding: data, as: UTF8.self)+ }+}