From dd45084a6caf3bfda2dc9e8958b965697aab004c Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 26 Jul 2023 15:46:56 -0400 Subject: [PATCH] MacOS uname -m can lie due to Rosetta shenanigans This uses sysctl instead, which is more trustworthy --- deploy/shellscript/juliaup-init.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/deploy/shellscript/juliaup-init.sh b/deploy/shellscript/juliaup-init.sh index 61e74eab..0439be90 100644 --- a/deploy/shellscript/juliaup-init.sh +++ b/deploy/shellscript/juliaup-init.sh @@ -217,10 +217,19 @@ get_architecture() { _clibtype="musl" fi - if [ "$_ostype" = Darwin ] && [ "$_cputype" = i386 ]; then - # Darwin `uname -m` lies - if sysctl hw.optional.x86_64 | grep -q ': 1'; then - _cputype=x86_64 + if [ "$_ostype" = Darwin ]; then + # Darwin `uname -m` can lie due to Rosetta shenanigans. If you manage to + # invoke a native shell binary and then a native uname binary, you can + # get the real answer, but that's hard to ensure, so instead we use + # `sysctl` (which doesn't lie) to check for the actual architecture. + if [ "$_cputype" = i386 ]; then + if sysctl hw.optional.x86_64 | grep -q ': 1'; then + _cputype=x86_64 + fi + elif [ "$_cputype" = x86_64 ]; then + if sysctl hw.optional.arm64 | grep -q ': 1'; then + _cputype=arm64 + fi fi fi