fix: simplify cpu arch detection

This commit is contained in:
Louis 2025-08-21 10:47:26 +07:00
parent 2398c0ab33
commit 973a8dd8cc
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -24,38 +24,11 @@ impl CpuStaticInfo {
CpuStaticInfo {
name,
core_count: System::physical_core_count().unwrap_or(0),
arch: CpuStaticInfo::get_runtime_arch(),
arch: System::cpu_arch(),
extensions: CpuStaticInfo::get_extensions(),
}
}
fn get_runtime_arch() -> String {
// Use sysinfo to get the actual CPU architecture at runtime
let mut system = System::new();
system.refresh_cpu_all();
if let Some(cpu) = system.cpus().first() {
let brand = cpu.brand().to_lowercase();
// Detect architecture based on CPU brand/model
if brand.contains("aarch64") || brand.contains("arm64") || brand.contains("apple m") {
"aarch64".to_string()
} else if brand.contains("x86")
|| brand.contains("amd64")
|| brand.contains("i386")
|| brand.contains("i686")
{
"x86_64".to_string()
} else {
// Fallback to compile-time architecture if we can't detect
std::env::consts::ARCH.to_string()
}
} else {
// Fallback to compile-time architecture if no CPU info available
std::env::consts::ARCH.to_string()
}
}
// TODO: see if we need to check for all CPU extensions
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn get_extensions() -> Vec<String> {