From 3a80a3841b7f01ac7b8a1b028b3e2383ee948fa0 Mon Sep 17 00:00:00 2001 From: MSDarwish2000 Date: Thu, 15 May 2025 06:13:06 +0300 Subject: [PATCH] Fix macOS architecture detection on non-officially supported processors Signed-off-by: MSDarwish2000 --- .../platform/internal/MutableSystemInfo.java | 3 +- .../internal/MutableSystemInfoTest.groovy | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 native-platform/src/test/groovy/net/rubygrapefruit/platform/internal/MutableSystemInfoTest.groovy diff --git a/native-platform/src/main/java/net/rubygrapefruit/platform/internal/MutableSystemInfo.java b/native-platform/src/main/java/net/rubygrapefruit/platform/internal/MutableSystemInfo.java index 460b32c5..d7509c07 100644 --- a/native-platform/src/main/java/net/rubygrapefruit/platform/internal/MutableSystemInfo.java +++ b/native-platform/src/main/java/net/rubygrapefruit/platform/internal/MutableSystemInfo.java @@ -39,8 +39,7 @@ public String getArchitectureName() { // On macOS, the architecture field contains the CPU name, not the architecture if (machineArchitecture.startsWith("Apple")) { return "arm64"; - } - if (machineArchitecture.startsWith("Intel")) { + } else if (machineArchitecture.contains("Intel") || machineArchitecture.startsWith("AMD")) { return "x86_64"; } } diff --git a/native-platform/src/test/groovy/net/rubygrapefruit/platform/internal/MutableSystemInfoTest.groovy b/native-platform/src/test/groovy/net/rubygrapefruit/platform/internal/MutableSystemInfoTest.groovy new file mode 100644 index 00000000..5c721132 --- /dev/null +++ b/native-platform/src/test/groovy/net/rubygrapefruit/platform/internal/MutableSystemInfoTest.groovy @@ -0,0 +1,43 @@ +package net.rubygrapefruit.platform.internal + +import net.rubygrapefruit.platform.NativePlatformSpec +import net.rubygrapefruit.platform.SystemInfo + +class MutableSystemInfoTest extends NativePlatformSpec { + + def "can get architecture on macOS"() { + given: + def systemInfo = new MutableSystemInfo() + systemInfo.osName = "Darwin" + + when: + systemInfo.machineArchitecture = processor + + then: + systemInfo.architecture == expectedArchitecture + + where: + processor | expectedArchitecture + // Officially supported macOS processors + "Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz" | SystemInfo.Architecture.amd64 + "Intel(R) Core(TM) i5-10500 CPU @ 3.10GHz" | SystemInfo.Architecture.amd64 + "Intel(R) Xeon(R) W-3223 CPU @ 3.50GHz" | SystemInfo.Architecture.amd64 + + // Newer Intel processors + "11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz" | SystemInfo.Architecture.amd64 + "12th Gen Intel(R) Core(TM) i7-12650HX" | SystemInfo.Architecture.amd64 + "13th Gen Intel(R) Core(TM) i5-13600K" | SystemInfo.Architecture.amd64 + "Intel(R) Core(TM) Ultra 7 255H" | SystemInfo.Architecture.amd64 + + // AMD processors + "AMD Ryzen 5 2600 Six-Core Processor" | SystemInfo.Architecture.amd64 + "AMD Athlon(tm) II X2 215 Processor" | SystemInfo.Architecture.amd64 + + // Apple processors + "Apple M1" | SystemInfo.Architecture.aarch64 + "Apple M1 Pro" | SystemInfo.Architecture.aarch64 + "Apple M2" | SystemInfo.Architecture.aarch64 + "Apple M3" | SystemInfo.Architecture.aarch64 + "Apple M4" | SystemInfo.Architecture.aarch64 + } +}