From e24d7f9be1fccb739c6a5e977b65a5cbbe67788e Mon Sep 17 00:00:00 2001 From: Ryan Parmeter Date: Mon, 10 Nov 2025 18:29:16 -0700 Subject: [PATCH] fix: Use std::env::consts::OS for reliable runtime platform detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 --- src/mcp_server_gitea.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/mcp_server_gitea.rs b/src/mcp_server_gitea.rs index e34faee..28812b4 100644 --- a/src/mcp_server_gitea.rs +++ b/src/mcp_server_gitea.rs @@ -266,13 +266,11 @@ fn resolve_binary_path(explicit_path: &Option) -> Result { // Build list of all paths to try IN ORDER // 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![]; - // Detect if this is likely macOS (check for Homebrew paths in PATH) - let is_macos = std::env::var("PATH") - .map(|path| path.contains("/opt/homebrew")) - .unwrap_or(false); + // Detect if this is macOS using reliable runtime detection + let is_macos = std::env::consts::OS == "macos"; if is_macos { // macOS: Homebrew paths first, then standard paths as fallback