From 280ea1aa9f6b755afcf05df6f96e57b172d1cb01 Mon Sep 17 00:00:00 2001 From: Sherzod Mutalov Date: Thu, 26 Jun 2025 14:16:10 +0500 Subject: [PATCH] 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 8e521744a..e8775d187 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 d549e2287..c479bd252 100644 --- a/src-tauri/src/core/utils/mod.rs +++ b/src-tauri/src/core/utils/mod.rs @@ -195,3 +195,18 @@ pub fn is_library_available(library: &str) -> bool { } } } + +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 +}