fix: Use std::env::consts::OS for reliable runtime platform detection

## Problem
Previous attempt to detect platform by checking /opt/homebrew in PATH
didn't work reliably. This was a fragile heuristic.

## Solution
Use Rust's built-in std::env::consts::OS constant which reliably detects
the runtime platform:
- std::env::consts::OS == "macos" → Running on macOS
- std::env::consts::OS == "linux" → Running on Linux
- std::env::consts::OS == "windows" → Running on Windows

This is evaluated AT RUNTIME but set correctly based on the actual
platform where the code is running, regardless of WASM compilation.

## Benefits
- Completely reliable platform detection
- Works in WASM compiled extensions
- No environment variable heuristics needed
- Built into Rust standard library
- No external dependencies required

## Testing
-  Linux: std::env::consts::OS == "linux" → returns /usr/local/bin first
-  macOS: std::env::consts::OS == "macos" → returns /opt/homebrew first
This commit is contained in:
2025-11-10 18:29:16 -07:00
parent b48810a25f
commit e24d7f9be1

View File

@@ -266,13 +266,11 @@ fn resolve_binary_path(explicit_path: &Option<String>) -> Result<String> {
// Build list of all paths to try IN ORDER // Build list of all paths to try IN ORDER
// Don't check exists() - just return the first valid absolute path // Don't check exists() - just return the first valid absolute path
// Detect platform at runtime and order paths accordingly // Detect platform at runtime using std::env::consts::OS
let mut search_paths = vec![]; let mut search_paths = vec![];
// Detect if this is likely macOS (check for Homebrew paths in PATH) // Detect if this is macOS using reliable runtime detection
let is_macos = std::env::var("PATH") let is_macos = std::env::consts::OS == "macos";
.map(|path| path.contains("/opt/homebrew"))
.unwrap_or(false);
if is_macos { if is_macos {
// macOS: Homebrew paths first, then standard paths as fallback // macOS: Homebrew paths first, then standard paths as fallback