Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

fix: fresh engine installs shipped every runtime symlink broken — link relative, heal old installs (#16)

Gauthier Piarrettec719556e3b90
diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swift
index 80f88a3..1d9a0ca 100644
--- a/Sources/HighballKit/EngineStore.swift
+++ b/Sources/HighballKit/EngineStore.swift
@@ -38,6 +38,7 @@ public struct EngineStore: Sendable {
return dirs.compactMap { dir in
let manifest = dir.appending(path: "manifest.json")
guard let m = try? EngineManifest.load(from: manifest) else { return nil }
+ try? linkRuntime(dir) // heals broken runtime links from pre-0.7.9 installs
return InstalledEngine(manifest: m, root: dir)
}.sorted { $0.manifest.id < $1.manifest.id }
}
@@ -45,6 +46,7 @@ public struct EngineStore: Sendable {
public func engine(_ id: String) throws -> InstalledEngine {
let root = paths.engine(id)
let m = try EngineManifest.load(from: root.appending(path: "manifest.json"))
+ try? linkRuntime(root) // heals broken runtime links from pre-0.7.9 installs
return InstalledEngine(manifest: m, root: root)
}
@@ -158,26 +160,38 @@ public struct EngineStore: Sendable {
/// Symlinks the Template's runtime dylibs into engine/lib so Wine binaries resolve
/// @loader_path/../lib/… and @rpath names without any DYLD_* environment (which SIP
/// strips when a restricted binary like /bin/sh sits in the exec chain — winetricks does).
+ ///
+ /// Targets MUST be relative: install() links inside the .partial staging dir and then
+ /// renames it into place, so absolute targets died with the staging path — every fresh
+ /// install shipped broken links until 0.7.9 (caught by the dotnet48 E2E gate; games
+ /// still ran because launches carry DYLD_FALLBACK_LIBRARY_PATH, winetricks did not).
+ /// A link with any other target is replaced, which also heals engines installed by
+ /// older versions when this runs again from installedEngines()/engine(_:).
func linkRuntime(_ root: URL) throws {
let fm = FileManager.default
let engineLib = root.appending(path: "engine/lib", directoryHint: .isDirectory)
guard fm.fileExists(atPath: engineLib.path) else { return }
- var sources = [root.appending(path: "frameworks", directoryHint: .isDirectory)]
- sources.append(root.appending(path: "frameworks/GStreamer.framework/Versions/1.0/lib", directoryHint: .isDirectory))
- for dir in sources {
+ var handled = Set<String>()
+ func link(_ name: String, to relativeTarget: String) {
+ guard handled.insert(name).inserted else { return } // first source dir wins, as before
+ let dest = engineLib.appending(path: name)
+ if let existing = try? fm.destinationOfSymbolicLink(atPath: dest.path) {
+ if existing == relativeTarget { return }
+ try? fm.removeItem(at: dest) // absolute/staging target from a pre-0.7.9 install
+ } else if fm.fileExists(atPath: dest.path) {
+ return // a real file — leave it alone
+ }
+ try? fm.createSymbolicLink(atPath: dest.path, withDestinationPath: relativeTarget)
+ }
+ for sub in ["frameworks", "frameworks/GStreamer.framework/Versions/1.0/lib"] {
+ let dir = root.appending(path: sub, directoryHint: .isDirectory)
guard let entries = try? fm.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil) else { continue }
for entry in entries where entry.pathExtension == "dylib" {
- let dest = engineLib.appending(path: entry.lastPathComponent)
- if !fm.fileExists(atPath: dest.path) {
- try? fm.createSymbolicLink(at: dest, withDestinationURL: entry)
- }
+ link(entry.lastPathComponent, to: "../../\(sub)/\(entry.lastPathComponent)")
}
}
// GStreamer.framework itself, for modules that reference it by framework path.
- let fw = engineLib.appending(path: "GStreamer.framework")
- if !fm.fileExists(atPath: fw.path) {
- try? fm.createSymbolicLink(at: fw, withDestinationURL: root.appending(path: "frameworks/GStreamer.framework"))
- }
+ link("GStreamer.framework", to: "../../frameworks/GStreamer.framework")
}
func stripQuarantine(_ url: URL) throws {
diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swift
index f0a8dbf..fadcf9f 100644
--- a/Tests/HighballKitTests/RegressionTests.swift
+++ b/Tests/HighballKitTests/RegressionTests.swift
@@ -203,6 +203,39 @@ extension RegressionTests {
XCTAssertEqual(Pin.storagePath(for: mixed, driveC: driveC), "Games/g.exe")
}
+ // The dotnet48 E2E gate caught this: install() ran linkRuntime inside the .partial
+ // staging dir with ABSOLUTE symlink targets, then renamed staging into place, so every
+ // fresh engine shipped dead runtime links (winetricks-based installs died in seconds;
+ // games survived on DYLD_FALLBACK_LIBRARY_PATH). Links must be relative, and re-running
+ // linkRuntime must heal a wrong target from an older install.
+ func testRuntimeLinksSurviveStagingRename() throws {
+ let fm = FileManager.default
+ let base = fm.temporaryDirectory.appending(path: "hb-linkrt-\(UUID().uuidString)")
+ let staging = base.appending(path: ".engine.partial")
+ defer { try? fm.removeItem(at: base) }
+ try fm.createDirectory(at: staging.appending(path: "engine/lib"), withIntermediateDirectories: true)
+ try fm.createDirectory(at: staging.appending(path: "frameworks/GStreamer.framework/Versions/1.0/lib"), withIntermediateDirectories: true)
+ try Data("lib".utf8).write(to: staging.appending(path: "frameworks/libinotify.0.dylib"))
+ try Data("gst".utf8).write(to: staging.appending(path: "frameworks/GStreamer.framework/Versions/1.0/lib/libgstreamer.dylib"))
+ // A dead absolute link, as pre-0.7.9 installs left behind — must be healed, not skipped.
+ try Data("st".utf8).write(to: staging.appending(path: "frameworks/libstale.dylib"))
+ try fm.createSymbolicLink(atPath: staging.appending(path: "engine/lib/libstale.dylib").path,
+ withDestinationPath: "/nonexistent/.old.partial/frameworks/libstale.dylib")
+
+ try EngineStore().linkRuntime(staging)
+ let final = base.appending(path: "engine-final")
+ try fm.moveItem(at: staging, to: final) // the rename that killed absolute targets
+
+ for name in ["libinotify.0.dylib", "libgstreamer.dylib", "libstale.dylib"] {
+ let link = final.appending(path: "engine/lib/\(name)")
+ let target = try fm.destinationOfSymbolicLink(atPath: link.path)
+ XCTAssertTrue(target.hasPrefix("../../frameworks/"), "\(name) target must be relative, got \(target)")
+ XCTAssertTrue(fm.fileExists(atPath: link.path), "\(name) must resolve after the rename")
+ }
+ XCTAssertEqual(try fm.destinationOfSymbolicLink(atPath: final.appending(path: "engine/lib/GStreamer.framework").path),
+ "../../frameworks/GStreamer.framework")
+ }
+
// Issues #27/#28: winetricks was sha256-pinned but fetched from .../master/..., so
// upstream's next commit broke every fresh engine install with "checksum mismatch".
// Manifest URLs must be immutable: a commit SHA or a tagged release asset, never a