Skip to content

Commit

Permalink
MacOS uname -m can lie due to Rosetta shenanigans
Browse files Browse the repository at this point in the history
This uses sysctl instead, which is more trustworthy
  • Loading branch information
StefanKarpinski committed Jul 26, 2023
1 parent 998e412 commit dd45084
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions deploy/shellscript/juliaup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dd45084

Please sign in to comment.