Skip to content

Commit df47920

Browse files
runner: Add GPTK
1 parent 1450b26 commit df47920

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/runner/gptk.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use super::{Runner, RunnerInfo};
2+
use std::path::{Path, PathBuf};
3+
4+
/// GPTK (Game Porting Toolkit) runner for macOS
5+
///
6+
/// GPTK is Apple's translation layer that allows running Windows games on macOS,
7+
/// particularly on Apple Silicon Macs. It combines Wine with Apple's D3DMetal
8+
/// to support DirectX 11 and 12 games.
9+
///
10+
/// # Requirements
11+
/// - macOS 14 Sonoma or later
12+
/// - Apple Silicon Mac (recommended) or Intel Mac with Rosetta 2
13+
/// - Command Line Tools for Xcode 15 or later
14+
/// - Game Porting Toolkit installed via Homebrew
15+
///
16+
/// # Example
17+
/// ```rust
18+
/// use bottles_core::runner::{GPTK, Runner};
19+
/// use std::path::Path;
20+
///
21+
/// // Create a GPTK runner from a path containing the gameportingtoolkit executable
22+
/// let gptk_path = Path::new("/opt/homebrew/bin");
23+
/// match GPTK::try_from(gptk_path) {
24+
/// Ok(gptk) => {
25+
/// println!("GPTK Name: {}", gptk.info().name());
26+
/// println!("GPTK Version: {}", gptk.info().version());
27+
/// println!("GPTK Available: {}", gptk.is_available());
28+
/// }
29+
/// Err(e) => println!("Failed to create GPTK runner: {}", e),
30+
/// }
31+
/// ```
32+
#[derive(Debug)]
33+
pub struct GPTK {
34+
info: RunnerInfo,
35+
}
36+
37+
impl TryFrom<&Path> for GPTK {
38+
type Error = crate::Error;
39+
40+
fn try_from(path: &Path) -> Result<Self, Self::Error> {
41+
let executable = PathBuf::from("./gameportingtoolkit");
42+
let info = RunnerInfo::try_from(path, &executable)?;
43+
Ok(GPTK { info })
44+
}
45+
}
46+
47+
impl Runner for GPTK {
48+
fn wine(&self) -> &super::Wine {
49+
todo!()
50+
}
51+
52+
fn info(&self) -> &RunnerInfo {
53+
&self.info
54+
}
55+
56+
/// GPTK has special availability requirements - it only works on Apple Silicon Macs
57+
/// running macOS 14 Sonoma or later with Rosetta 2
58+
fn is_available(&self) -> bool {
59+
if !self.info().executable_path().exists() {
60+
return false;
61+
}
62+
63+
// Check if running under Rosetta or on Apple Silicon
64+
use std::process::Command;
65+
let arch_output = Command::new("arch")
66+
.output()
67+
.map(|output| String::from_utf8_lossy(&output.stdout).trim().to_string())
68+
.unwrap_or_default();
69+
70+
// GPTK requires either x86_64 (Rosetta) or arm64 (Apple Silicon)
71+
arch_output == "i386" || arch_output == "arm64"
72+
}
73+
}

src/runner/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
#[cfg(target_os = "macos")]
2+
mod gptk;
13
mod proton;
24
mod umu;
35
mod wine;
46

7+
#[cfg(target_os = "macos")]
8+
pub use gptk::GPTK;
59
pub use proton::Proton;
610
pub use umu::UMU;
711
pub use wine::Wine;

0 commit comments

Comments
 (0)