Skip to content

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

Bottles: verify the 32-bit half exists instead of trusting wineboot's exit code (#37)

Gauthier Piarrettef57bfbfac3f2
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index e9d84ee..9730596 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -478,6 +478,8 @@ final class AppState {
guard r.exitStatus == 0 else {
throw HighballError.processFailed(command: "wineboot -u", status: r.exitStatus, output: "see \(r.log.path)")
}
+ // Repair is the escape hatch for a bottle whose 32-bit half never got built (#37).
+ try await BottleStore.ensureWoW64(runner: runner, bottle: bottle, log: r.log)
try? await runner.setGpuIdentity()
try? await runner.setServiceTimeout()
await MainActor.run { self.appendLog("bottle repaired — Windows environment refreshed") }
diff --git a/Sources/HighballKit/BottleStore.swift b/Sources/HighballKit/BottleStore.swift
index bd1e1fc..2764722 100644
--- a/Sources/HighballKit/BottleStore.swift
+++ b/Sources/HighballKit/BottleStore.swift
@@ -62,12 +62,54 @@ public struct BottleStore: Sendable {
guard result.exitStatus == 0 else {
throw HighballError.processFailed(command: "wineboot -u", status: result.exitStatus, output: "see \(result.log.path)")
}
+ do {
+ try await Self.ensureWoW64(runner: runner, bottle: bottle, log: result.log)
+ } catch {
+ // Don't strand a half-built bottle: it can never run a 32-bit installer, and leaving
+ // it behind means retrying with the same name hits "bottle already exists".
+ try? runner.kill()
+ try? FileManager.default.removeItem(at: url)
+ throw error
+ }
if windowsVersion != .win10 { try await runner.setWindowsVersion(windowsVersion) }
try? await runner.setGpuIdentity()
try? await runner.setServiceTimeout()
return bottle
}
+ /// The 32-bit half of a prefix, and whether it is actually there.
+ ///
+ /// Wine populates `syswow64` by launching a 32-bit rundll32 for the inf's Wow64Install
+ /// section; if that launch fails, wineboot's loop skips the wait and **still exits 0**
+ /// (verified in wineboot.c). So an exit-code check cannot tell a working bottle from one
+ /// with no 32-bit support — which is exactly issue #37: bottles create "fine", then every
+ /// installer dies with `could not load kernel32.dll, status c0000135`, because Wine will
+ /// not fall back to the engine's i386-windows dlls outside prefix bootstrap. Most Windows
+ /// installers are 32-bit, so such a bottle can install nothing at all.
+ public static func woW64Kernel32(in bottle: Bottle) -> URL {
+ bottle.driveC.appending(path: "windows/syswow64/kernel32.dll")
+ }
+
+ /// Verifies the 32-bit half exists, retrying wineboot once before giving up. A failure
+ /// here is reported at bottle creation, where it is actionable, instead of surfacing later
+ /// as an opaque error on every install.
+ public static func ensureWoW64(runner: WineRunner, bottle: Bottle, log: URL) async throws {
+ if FileManager.default.fileExists(atPath: woW64Kernel32(in: bottle).path) { return }
+ _ = try? await runner.wineboot(force: true)
+ guard FileManager.default.fileExists(atPath: woW64Kernel32(in: bottle).path) else {
+ // Wine only falls back to the engine's 32-bit builtins while a prefix is
+ // bootstrapping, so a prefix that missed this step cannot be repaired in place
+ // (verified: re-running wineboot, forced or not, leaves syswow64 empty). A fresh
+ // bottle is the fix, which is why creation fails here rather than later.
+ throw HighballError.invalid("""
+ Windows 32-bit support didn't finish setting up in this bottle, so most \
+ installers can't run in it (they fail with "could not load kernel32.dll"). \
+ Please create the bottle again. If it happens every time, report it with this \
+ log attached and we'll dig in: \(log.path)
+ """)
+ }
+ }
+
/// Copies a bottle under a new name (default "<name> copy", uniquified). Callers should stop
/// the bottle's wineserver first so the registry files on disk are flushed and consistent.
public func duplicate(_ name: String, as newName: String? = nil) throws -> Bottle {
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index daa5aa6..6522a48 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -153,8 +153,10 @@ public struct WineRunner: Sendable {
return (result, true)
}
- public func wineboot() async throws -> LaunchResult {
- try await run(["wineboot", "-u"], renderer: .wined3d, label: "wineboot")
+ /// `force` adds -f: re-runs the inf installs even when the prefix looks current, which is
+ /// how a prefix missing its 32-bit half gets a second chance (issue #37).
+ public func wineboot(force: Bool = false) async throws -> LaunchResult {
+ try await run(["wineboot", force ? "-fu" : "-u"], renderer: .wined3d, label: "wineboot")
}
public func kill() throws {
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index 0b50476..6ea3e9b 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -180,6 +180,9 @@ struct Bottle: AsyncParsableCommand {
let r = try await runner.wineboot()
try? await runner.setGpuIdentity()
try? await runner.setServiceTimeout()
+ // Same 32-bit check the app and bottle creation use (#37): wineboot exits 0 even
+ // when it skipped building syswow64, so the exit code alone means little.
+ try await BottleStore.ensureWoW64(runner: runner, bottle: b, log: r.log)
print(r.exitStatus == 0 ? "repaired \(name)" : "wineboot exited with \(r.exitStatus) — see \(r.log.path)")
}
}
diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swift
index c0e4cb4..dc70e68 100644
--- a/Tests/HighballKitTests/RegressionTests.swift
+++ b/Tests/HighballKitTests/RegressionTests.swift
@@ -333,6 +333,28 @@ extension RegressionTests {
"drive_c itself counts as inside")
}
+ // Issue #37: "Can't install anything". Wine builds a prefix's 32-bit half by launching a
+ // 32-bit rundll32; when that fails, wineboot skips it and STILL exits 0, so an exit-code
+ // check reports a healthy bottle in which every 32-bit installer dies with
+ // "could not load kernel32.dll, status c0000135". The 32-bit half must be checked by
+ // its files, not by the exit code.
+ func testWoW64PresenceIsCheckedByFileNotExitCode() throws {
+ let tmp = FileManager.default.temporaryDirectory.appending(path: "hb-wow64-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: tmp) }
+ let bottle = Bottle(url: tmp, settings: BottleSettings(name: "b", engineID: "e"))
+ let marker = BottleStore.woW64Kernel32(in: bottle)
+ XCTAssertTrue(marker.path.hasSuffix("drive_c/windows/syswow64/kernel32.dll"),
+ "the 32-bit half is proven by syswow64's kernel32, the dll Wine dies without")
+ XCTAssertFalse(FileManager.default.fileExists(atPath: marker.path), "absent on a bare prefix")
+ try FileManager.default.createDirectory(at: marker.deletingLastPathComponent(),
+ withIntermediateDirectories: true)
+ // An empty syswow64 directory is exactly the broken state — the folder existing is not
+ // enough, which is why the check names the file.
+ XCTAssertFalse(FileManager.default.fileExists(atPath: marker.path))
+ try Data("pe".utf8).write(to: marker)
+ XCTAssertTrue(FileManager.default.fileExists(atPath: marker.path))
+ }
+
// Issue #36: "Visual C++ Failed to install". The exit code Swift sees is twice-truncated —
// WiX Burn returns HRESULT_CODE (0x80070666 → 1638), then POSIX keeps 8 bits (1638 → 102).
// A strict `== 0` guard therefore failed the VC++ recipe at step 1 of 14 whenever a newer