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
Fix originally provided in JuliaLang/juliaup#701
  • Loading branch information
rami3l committed Aug 14, 2023
1 parent c8e9284 commit e5c3843
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,19 @@ get_architecture() {
fi
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 e5c3843

Please sign in to comment.