From c28452cc6c7f061673498832ee9282ed8126a235 Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Thu, 27 Jan 2022 14:16:13 +0100 Subject: [PATCH 1/2] Check target architecture as well --- src/platform.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/platform.rs b/src/platform.rs index 1edf669..b40b456 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -22,10 +22,10 @@ impl ToString for Platform { /// Read the current machine's platform. pub fn platform() -> Platform { - match env::consts::OS { - "linux" => Platform::LinuxAmd64, - "macos" => Platform::MacOsAmd64, - "windows" => Platform::WindowsAmd64, + match (env::consts::OS, env::consts::ARCH) { + ("linux", "x86_64") => Platform::LinuxAmd64, + ("macos", "x86_64") => Platform::MacOsAmd64, + ("windows", "x86_64") => Platform::WindowsAmd64, _ => Platform::Unsupported, } } @@ -35,19 +35,19 @@ mod tests { use super::*; #[test] - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", target_arch = "x86_64"))] fn get_platform() { assert_eq!(platform(), Platform::LinuxAmd64); } #[test] - #[cfg(target_os = "macos")] + #[cfg(all(target_os = "macos", target_arch = "x86_64"))] fn get_platform() { assert_eq!(platform(), Platform::MacOsAmd64); } #[test] - #[cfg(target_os = "windows")] + #[cfg(all(target_os = "windows", target_arch = "x86_64"))] fn get_platform() { assert_eq!(platform(), Platform::WindowsAmd64); } From a03457070bfe470dd9546bb89cf03400ec18f471 Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Fri, 28 Jan 2022 18:01:30 +0100 Subject: [PATCH 2/2] Relax architecture requirements for macOS --- src/platform.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/platform.rs b/src/platform.rs index b40b456..db68437 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -24,7 +24,9 @@ impl ToString for Platform { pub fn platform() -> Platform { match (env::consts::OS, env::consts::ARCH) { ("linux", "x86_64") => Platform::LinuxAmd64, - ("macos", "x86_64") => Platform::MacOsAmd64, + // NOTE: Relaxed requirement on target architecture here + // to support M1 macs with Rosetta + ("macos", _) => Platform::MacOsAmd64, ("windows", "x86_64") => Platform::WindowsAmd64, _ => Platform::Unsupported, } @@ -46,6 +48,12 @@ mod tests { assert_eq!(platform(), Platform::MacOsAmd64); } + #[test] + #[cfg(all(target_os = "macos", target_arch = "aarch64"))] + fn get_platform() { + assert_eq!(platform(), Platform::MacOsAmd64); + } + #[test] #[cfg(all(target_os = "windows", target_arch = "x86_64"))] fn get_platform() {