Skip to content

Commit e5c3843

Browse files
committed
macOS uname -m can lie due to Rosetta shenanigans
Fix originally provided in JuliaLang/juliaup#701
1 parent c8e9284 commit e5c3843

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

rustup-init.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,19 @@ get_architecture() {
255255
fi
256256
fi
257257

258-
if [ "$_ostype" = Darwin ] && [ "$_cputype" = i386 ]; then
259-
# Darwin `uname -m` lies
260-
if sysctl hw.optional.x86_64 | grep -q ': 1'; then
261-
_cputype=x86_64
258+
if [ "$_ostype" = Darwin ]; then
259+
# Darwin `uname -m` can lie due to Rosetta shenanigans. If you manage to
260+
# invoke a native shell binary and then a native uname binary, you can
261+
# get the real answer, but that's hard to ensure, so instead we use
262+
# `sysctl` (which doesn't lie) to check for the actual architecture.
263+
if [ "$_cputype" = i386 ]; then
264+
if sysctl hw.optional.x86_64 | grep -q ': 1'; then
265+
_cputype=x86_64
266+
fi
267+
elif [ "$_cputype" = x86_64 ]; then
268+
if sysctl hw.optional.arm64 | grep -q ': 1'; then
269+
_cputype=arm64
270+
fi
262271
fi
263272
fi
264273

0 commit comments

Comments
 (0)