Skip to content

Commit 47d9283

Browse files
committed
feat: add vendor platform detection and binary discovery
- Implemented functions to determine the vendor platform directory and binary name based on the operating system and architecture. - Enhanced the discover_codex_command function to search for the codex binary in multiple vendor locations, improving compatibility across different environments.
1 parent ca7b080 commit 47d9283

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src-tauri/src/utils/codex_discovery.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ fn get_platform_binary_name() -> &'static str {
1313
}
1414
}
1515

16+
fn get_vendor_platform_dir() -> Option<&'static str> {
17+
let os = std::env::consts::OS;
18+
let arch = std::env::consts::ARCH;
19+
match (os, arch) {
20+
("macos", "aarch64") => Some("aarch64-apple-darwin"),
21+
("macos", "x86_64") => Some("x86_64-apple-darwin"),
22+
("linux", "x86_64") => Some("x86_64-unknown-linux-musl"),
23+
("linux", "aarch64") => Some("aarch64-unknown-linux-musl"),
24+
("windows", "x86_64") => Some("x86_64-pc-windows-msvc"),
25+
("windows", "aarch64") => Some("aarch64-pc-windows-msvc"),
26+
_ => None,
27+
}
28+
}
29+
30+
fn get_vendor_binary_name() -> &'static str {
31+
if cfg!(windows) {
32+
"codex.exe"
33+
} else {
34+
"codex"
35+
}
36+
}
37+
1638
pub fn discover_codex_command() -> Option<PathBuf> {
1739
let home = if cfg!(windows) {
1840
std::env::var("USERPROFILE")
@@ -56,6 +78,40 @@ pub fn discover_codex_command() -> Option<PathBuf> {
5678
}
5779
}
5880

81+
if let Some(vendor_dir) = get_vendor_platform_dir() {
82+
let vendor_binary = get_vendor_binary_name();
83+
let vendor_locations = [
84+
PathBuf::from(&home)
85+
.join(".bun/install/global/node_modules/@openai/codex/vendor")
86+
.join(vendor_dir)
87+
.join("codex")
88+
.join(vendor_binary),
89+
PathBuf::from(&home)
90+
.join(".local/share/npm/lib/node_modules/@openai/codex/vendor")
91+
.join(vendor_dir)
92+
.join("codex")
93+
.join(vendor_binary),
94+
PathBuf::from("/usr/local/lib/node_modules/@openai/codex/vendor")
95+
.join(vendor_dir)
96+
.join("codex")
97+
.join(vendor_binary),
98+
PathBuf::from("/opt/homebrew/lib/node_modules/@openai/codex/vendor")
99+
.join(vendor_dir)
100+
.join("codex")
101+
.join(vendor_binary),
102+
];
103+
104+
for path_buf in &vendor_locations {
105+
if path_buf.exists() {
106+
log::debug!(
107+
"Found codex vendor binary at {}",
108+
path_buf.display()
109+
);
110+
return Some(path_buf.clone());
111+
}
112+
}
113+
}
114+
59115
// Windows npm global installation paths
60116
if cfg!(windows) {
61117
if let Ok(appdata) = std::env::var("APPDATA") {

0 commit comments

Comments
 (0)