fn detect_platform() -> &'static str {
#[cfg(all(target_os = "ios", target_arch = "aarch64"))]
{
"ios-arm64"
}
#[cfg(all(target_os = "android", target_arch = "aarch64"))]
{
"android-arm64"
}
#[cfg(all(target_os = "android", target_arch = "arm"))]
{
"android-arm"
}
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
{
"macos-arm64"
}
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
{
"macos-x86_64"
}
#[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 = "windows", target_arch = "x86_64"))]
{
"windows-x86_64"
}
#[cfg(not(any(
all(target_os = "ios", target_arch = "aarch64"),
all(target_os = "android", target_arch = "aarch64"),
all(target_os = "android", target_arch = "arm"),
all(target_os = "macos", target_arch = "aarch64"),
all(target_os = "macos", target_arch = "x86_64"),
all(target_os = "linux", target_arch = "x86_64"),
all(target_os = "linux", target_arch = "aarch64"),
all(target_os = "windows", target_arch = "x86_64"),
)))]
{
"unknown"
}
}
pub fn current_platform() -> &'static str {
detect_platform()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_platform_string_not_empty() {
let platform = current_platform();
assert!(!platform.is_empty(), "Platform string should not be empty");
}
#[test]
fn test_platform_format() {
let platform = current_platform();
if platform != "unknown" {
assert!(
platform.contains('-'),
"Platform string should contain a hyphen: {}",
platform
);
}
}
#[test]
fn test_platform_consistency() {
let platform1 = current_platform();
let platform2 = current_platform();
assert_eq!(platform1, platform2);
}
#[test]
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
fn test_macos_arm64() {
assert_eq!(current_platform(), "macos-arm64");
}
#[test]
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
fn test_macos_x86_64() {
assert_eq!(current_platform(), "macos-x86_64");
}
#[test]
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
fn test_linux_x86_64() {
assert_eq!(current_platform(), "linux-x86_64");
}
#[test]
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
fn test_windows_x86_64() {
assert_eq!(current_platform(), "windows-x86_64");
}
}