Skip to content

Commit

Permalink
Avoid sysctl: unknown oid stderr output and/or non-zero exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Aug 15, 2023
1 parent 4dfe254 commit 067a784
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,22 @@ get_architecture() {
# 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
# Handling i386 compatibility mode in older macOS versions (<=10.14)
# running on x86_64-based Macs.
# Starting from 10.15, macOS explicitly bans all i386 binaries from running.
# See: <https://support.apple.com/en-us/HT208436>

# Avoid `sysctl: unknown oid` stderr output and/or non-zero exit code.
if sysctl hw.optional.x86_64 2> /dev/null || true | grep -q ': 1'; then
_cputype=x86_64
fi
elif [ "$_cputype" = x86_64 ]; then
if sysctl hw.optional.arm64 | grep -q ': 1'; then
# Handling x86-64 compatibility mode (a.k.a. Rosetta 2)
# in newer macOS versions (>=11) running on arm64-based Macs.
# Rosetta 2 is built exclusively for x86-64 and cannot run i386 binaries.

# Avoid `sysctl: unknown oid` stderr output and/or non-zero exit code.
if sysctl hw.optional.arm64 2> /dev/null || true | grep -q ': 1'; then
_cputype=arm64
fi
fi
Expand Down

0 comments on commit 067a784

Please sign in to comment.