diff --git a/Cargo.toml b/Cargo.toml index e5e7786e4..6f10fbcd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,11 @@ edition = "2021" default-run = "dash-evo-tool" rust-version = "1.81" +[build] +rustflags = [ + "-C", "target-feature=+avx,-avx2,-avx512f,-avx512cd,-avx512er,-avx512pf,-avx512bw,-avx512dq,-avx512vl" +] + [dependencies] bip39 = { version = "2.1.0", features = ["all-languages", "rand"] } derive_more = "1.0.0" @@ -59,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 000000000..20a736284 --- /dev/null +++ b/src/cpu_compatibility.rs @@ -0,0 +1,55 @@ +#[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() { + if !feature_info.has_avx() { + MessageDialog::new() + .set_type(native_dialog::MessageType::Error) + .set_title("Compatibility Error") + .set_text("Your CPU does not support AVX instructions. Please use a compatible CPU.") + .show_alert() + .unwrap(); + std::process::exit(1); + } + let avx2_supported = cpuid + .get_extended_feature_info() + .map_or(false, |ext_info| ext_info.has_avx2()); + if !avx2_supported { + MessageDialog::new() + .set_type(native_dialog::MessageType::Error) + .set_title("Compatibility Error") + .set_text("Your CPU does not support AVX2 instructions. Please use a compatible CPU.") + .show_alert() + .unwrap(); + std::process::exit(1); + } + let avx512_supported = cpuid + .get_extended_feature_info() + .map_or(false, |ext_info| ext_info.has_avx512f()); // AVX-512 Foundation + if !avx512_supported { + MessageDialog::new() + .set_type(native_dialog::MessageType::Error) + .set_title("Compatibility Error") + .set_text("Your CPU does not support 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 7b6b5a6a0..75e33a991 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)