Skip to content

Commit e2c2cf8

Browse files
committed
Avoid sysctl: unknown oid stderr output and/or non-zero exit code
1 parent 4dfe254 commit e2c2cf8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

rustup-init.sh

+13-2
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,22 @@ get_architecture() {
261261
# get the real answer, but that's hard to ensure, so instead we use
262262
# `sysctl` (which doesn't lie) to check for the actual architecture.
263263
if [ "$_cputype" = i386 ]; then
264-
if sysctl hw.optional.x86_64 | grep -q ': 1'; then
264+
# Handling i386 compatibility mode in older macOS versions (<10.15)
265+
# running on x86_64-based Macs.
266+
# Starting from 10.15, macOS explicitly bans all i386 binaries from running.
267+
# See: <https://support.apple.com/en-us/HT208436>
268+
269+
# Avoid `sysctl: unknown oid` stderr output and/or non-zero exit code.
270+
if sysctl hw.optional.x86_64 2> /dev/null || true | grep -q ': 1'; then
265271
_cputype=x86_64
266272
fi
267273
elif [ "$_cputype" = x86_64 ]; then
268-
if sysctl hw.optional.arm64 | grep -q ': 1'; then
274+
# Handling x86-64 compatibility mode (a.k.a. Rosetta 2)
275+
# in newer macOS versions (>=11) running on arm64-based Macs.
276+
# Rosetta 2 is built exclusively for x86-64 and cannot run i386 binaries.
277+
278+
# Avoid `sysctl: unknown oid` stderr output and/or non-zero exit code.
279+
if sysctl hw.optional.arm64 2> /dev/null || true | grep -q ': 1'; then
269280
_cputype=arm64
270281
fi
271282
fi

0 commit comments

Comments
 (0)