From 685ae14467c59934e16704f4856e4ab5dd0defbe Mon Sep 17 00:00:00 2001 From: Sherzod Mutalov Date: Wed, 25 Jun 2025 23:13:59 +0500 Subject: [PATCH 1/5] fix: use system npx on old mac's --- src-tauri/src/core/mcp.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/core/mcp.rs b/src-tauri/src/core/mcp.rs index e340a9aaa..0fdf6a4b0 100644 --- a/src-tauri/src/core/mcp.rs +++ b/src-tauri/src/core/mcp.rs @@ -513,7 +513,16 @@ async fn schedule_mcp_start_task( let mut cmd = Command::new(command.clone()); - if command == "npx" { + let mut is_macos_without_avx2 = false; + #[cfg(all(target_os="macos", any(target_arch = "x86", target_arch = "x86_64"))) ] + { + is_macos_without_avx2 = !is_x86_feature_detected!("avx2"); + if is_macos_without_avx2 { + log::warn!("Your CPU doesn't support AVX2 instruction"); + } + } + + if command == "npx" && !is_macos_without_avx2 { let mut cache_dir = app_path.clone(); cache_dir.push(".npx"); let bun_x_path = format!("{}/bun", bin_path.display()); From 6c0855851278cd24cf9267cd6800537ce6a78f4e Mon Sep 17 00:00:00 2001 From: Sherzod Mutalov Date: Thu, 26 Jun 2025 01:01:12 +0500 Subject: [PATCH 2/5] chore: replaced with macros call to remove warning --- src-tauri/src/core/mcp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/src/core/mcp.rs b/src-tauri/src/core/mcp.rs index 0fdf6a4b0..8734dd1c8 100644 --- a/src-tauri/src/core/mcp.rs +++ b/src-tauri/src/core/mcp.rs @@ -514,7 +514,7 @@ async fn schedule_mcp_start_task( let mut cmd = Command::new(command.clone()); let mut is_macos_without_avx2 = false; - #[cfg(all(target_os="macos", any(target_arch = "x86", target_arch = "x86_64"))) ] + if cfg!(all(target_os="macos", any(target_arch = "x86", target_arch = "x86_64"))) { is_macos_without_avx2 = !is_x86_feature_detected!("avx2"); if is_macos_without_avx2 { From fd5ca5a2154e365bc41f811b211fe817add6f682 Mon Sep 17 00:00:00 2001 From: Sherzod Mutalov Date: Thu, 26 Jun 2025 01:16:55 +0500 Subject: [PATCH 3/5] chore: added comments --- src-tauri/src/core/mcp.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/core/mcp.rs b/src-tauri/src/core/mcp.rs index 8734dd1c8..8f5fe77c8 100644 --- a/src-tauri/src/core/mcp.rs +++ b/src-tauri/src/core/mcp.rs @@ -513,12 +513,15 @@ async fn schedule_mcp_start_task( let mut cmd = Command::new(command.clone()); + // we need to check CPU for the AVX2 instruction if we are running under the MacOS + // with Intel CPU. We can replace `npx` command with `bun` only if CPU is + // supporting AVX2, otherwise we need to use default `npx` binary let mut is_macos_without_avx2 = false; if cfg!(all(target_os="macos", any(target_arch = "x86", target_arch = "x86_64"))) { is_macos_without_avx2 = !is_x86_feature_detected!("avx2"); - if is_macos_without_avx2 { - log::warn!("Your CPU doesn't support AVX2 instruction"); + if is_macos_without_avx2 && command == "npx" { + log::warn!("Your CPU doesn't support AVX2 instruction, default npx binary will be used"); } } From 0e28916f8afcf00b6b08ef1cc82e39d7b8d115cb Mon Sep 17 00:00:00 2001 From: Sherzod Mutalov Date: Thu, 26 Jun 2025 14:16:10 +0500 Subject: [PATCH 4/5] chore: extracted macos avx2 check code to the utility function --- src-tauri/src/core/mcp.rs | 20 ++++++-------------- src-tauri/src/core/utils/mod.rs | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src-tauri/src/core/mcp.rs b/src-tauri/src/core/mcp.rs index 8f5fe77c8..fc9037a60 100644 --- a/src-tauri/src/core/mcp.rs +++ b/src-tauri/src/core/mcp.rs @@ -10,7 +10,11 @@ use tokio::{ time::{sleep, timeout}, }; -use super::{cmd::get_jan_data_folder_path, state::AppState}; +use super::{ + cmd::get_jan_data_folder_path, + state::AppState, + utils::can_override_npx, +}; const DEFAULT_MCP_CONFIG: &str = r#"{ "mcpServers": { @@ -512,20 +516,8 @@ async fn schedule_mcp_start_task( .ok_or_else(|| format!("Failed to extract command args from config for {name}"))?; let mut cmd = Command::new(command.clone()); - - // we need to check CPU for the AVX2 instruction if we are running under the MacOS - // with Intel CPU. We can replace `npx` command with `bun` only if CPU is - // supporting AVX2, otherwise we need to use default `npx` binary - let mut is_macos_without_avx2 = false; - if cfg!(all(target_os="macos", any(target_arch = "x86", target_arch = "x86_64"))) - { - is_macos_without_avx2 = !is_x86_feature_detected!("avx2"); - if is_macos_without_avx2 && command == "npx" { - log::warn!("Your CPU doesn't support AVX2 instruction, default npx binary will be used"); - } - } - if command == "npx" && !is_macos_without_avx2 { + if command == "npx" && can_override_npx() { let mut cache_dir = app_path.clone(); cache_dir.push(".npx"); let bun_x_path = format!("{}/bun", bin_path.display()); diff --git a/src-tauri/src/core/utils/mod.rs b/src-tauri/src/core/utils/mod.rs index 04bfd12b0..c25cd4ef7 100644 --- a/src-tauri/src/core/utils/mod.rs +++ b/src-tauri/src/core/utils/mod.rs @@ -76,3 +76,18 @@ pub fn normalize_path(path: &Path) -> PathBuf { } ret } + +pub fn can_override_npx() -> bool { + // we need to check the CPU for the AVX2 instruction support if we are running under the MacOS + // with Intel CPU. We can override `npx` command with `bun` only if CPU is + // supporting AVX2, otherwise we need to use default `npx` binary + if cfg!(all(target_os="macos", any(target_arch = "x86", target_arch = "x86_64"))) + { + if !is_x86_feature_detected!("avx2") { + log::warn!("Your CPU doesn't support AVX2 instruction, default npx binary will be used"); + return false; // we cannot override npx with bun binary + } + } + + true // by default, we can override npx with bun binary +} \ No newline at end of file From 9ce7527d580d8dec3a1ad82938ab230456b72f6b Mon Sep 17 00:00:00 2001 From: Sherzod Mutalov Date: Sun, 3 Aug 2025 11:12:37 +0500 Subject: [PATCH 5/5] fix: use attributes to check the feature existence --- src-tauri/src/core/utils/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/src/core/utils/mod.rs b/src-tauri/src/core/utils/mod.rs index 094cb2608..d6e658633 100644 --- a/src-tauri/src/core/utils/mod.rs +++ b/src-tauri/src/core/utils/mod.rs @@ -107,7 +107,7 @@ pub fn can_override_npx() -> bool { // we need to check the CPU for the AVX2 instruction support if we are running under the MacOS // with Intel CPU. We can override `npx` command with `bun` only if CPU is // supporting AVX2, otherwise we need to use default `npx` binary - if cfg!(all(target_os="macos", any(target_arch = "x86", target_arch = "x86_64"))) + #[cfg(all(target_os = "macos", any(target_arch = "x86", target_arch = "x86_64")))] { if !is_x86_feature_detected!("avx2") { log::warn!("Your CPU doesn't support AVX2 instruction, default npx binary will be used");