From 72f00cd64708ba7aeaa6bfdad0e039e5add41e90 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 28 Mar 2023 17:29:44 +0900 Subject: [PATCH] fix: Rosetta environment is falsely detected as ARM architecture --- Utils/PlatformHelper.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Utils/PlatformHelper.cs b/Utils/PlatformHelper.cs index 4fb5ac8..43bcaa7 100644 --- a/Utils/PlatformHelper.cs +++ b/Utils/PlatformHelper.cs @@ -127,10 +127,20 @@ private static void DeterminePlatform() { */ try { string arch; - using (Process uname = Process.Start(new ProcessStartInfo("uname", "-m") { - UseShellExecute = false, - RedirectStandardOutput = true - })) { + ProcessStartInfo processInfo; + if (Is(Platform.MacOS)) { + // on Rosetta environment, `uname -m` shows actual hardware architecture "arm64" + // and `arch` shows current hardware architecture `i386` + // We want to know current architecture so we call arch instead of uname. + processInfo = new ProcessStartInfo("arch") { + UseShellExecute = false, RedirectStandardOutput = true + }; + } else { + processInfo = new ProcessStartInfo("uname", "-m") { + UseShellExecute = false, RedirectStandardOutput = true + }; + } + using (Process uname = Process.Start(processInfo)) { arch = uname.StandardOutput.ReadLine().Trim(); }