diff --git a/Cargo.toml b/Cargo.toml index 5cdec6f..6f10fbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,4 +64,8 @@ regex = "1.11" zmq = "0.10" [target.'cfg(target_os = "windows")'.dependencies] -zeromq = "0.4.1" \ No newline at end of file +zeromq = "0.4.1" + +[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies] +native-dialog = "0.7.0" +raw-cpuid = "11.2.0" \ No newline at end of file diff --git a/src/cpu_compatibility.rs b/src/cpu_compatibility.rs new file mode 100644 index 0000000..bc8cf60 --- /dev/null +++ b/src/cpu_compatibility.rs @@ -0,0 +1,38 @@ +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +use native_dialog::MessageDialog; + +pub fn check_cpu_compatibility() { + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + { + use raw_cpuid::CpuId; + + let cpuid = CpuId::new(); + + if let Some(feature_info) = cpuid.get_feature_info() { + let avx_supported = feature_info.has_avx(); + let avx2_supported = cpuid + .get_extended_feature_info() + .map_or(false, |ext_info| ext_info.has_avx2()); + let avx512_supported = cpuid + .get_extended_feature_info() + .map_or(false, |ext_info| ext_info.has_avx512f()); // AVX-512 Foundation + if (!avx_supported || !avx2_supported) || !avx512_supported { + MessageDialog::new() + .set_type(native_dialog::MessageType::Error) + .set_title("Compatibility Error") + .set_text("Your CPU does not support AVX/AVX2/AVX512 instructions. Please use a compatible CPU.") + .show_alert() + .unwrap(); + std::process::exit(1); + } + } else { + MessageDialog::new() + .set_type(native_dialog::MessageType::Error) + .set_title("Compatibility Error") + .set_text("Unable to determine CPU features.") + .show_alert() + .unwrap(); + std::process::exit(1); + } + } +} diff --git a/src/main.rs b/src/main.rs index 7b6b5a6..75e33a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use crate::cpu_compatibility::check_cpu_compatibility; + mod app; mod app_dir; mod backend_task; @@ -5,6 +7,7 @@ mod components; mod config; mod context; mod context_provider; +mod cpu_compatibility; mod database; mod logging; mod model; @@ -12,6 +15,7 @@ mod sdk_wrapper; mod ui; fn main() -> eframe::Result<()> { + check_cpu_compatibility(); // Initialize the Tokio runtime let runtime = tokio::runtime::Builder::new_multi_thread() .worker_threads(40)