pub const SUPPORTED_TARGETS: &[&str] =
&["linux-x86_64", "linux-arm64", "macos-x86_64", "macos-arm64"];
pub fn detect_current_platform() -> &'static str {
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
{
"linux-x86_64"
}
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
{
"linux-arm64"
}
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
{
"macos-x86_64"
}
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
{
"macos-arm64"
}
#[cfg(not(any(
all(target_os = "linux", target_arch = "x86_64"),
all(target_os = "linux", target_arch = "aarch64"),
all(target_os = "macos", target_arch = "x86_64"),
all(target_os = "macos", target_arch = "aarch64"),
)))]
{
"unknown"
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_detect_current_platform_is_known() {
let platform = detect_current_platform();
assert_ne!(platform, "unknown", "Running on unsupported platform");
assert!(SUPPORTED_TARGETS.contains(&platform));
}
#[test]
fn test_supported_targets_not_empty() {
assert!(!SUPPORTED_TARGETS.is_empty());
}
}