Skip to content

chore: added Apple M1 platform detection when compiling with Rosetta 2 #40315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,34 @@ def cc_macros(cc=None):
key = lst[1]
val = lst[2]
k[key] = val

try:
p = subprocess.Popen(shlex.split('uname') + ['-v'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except OSError:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could someone check if other types of error/exception could happen in other environments when uname is not available? I tried with different command names that are def. not available and the catch/forget code works well

pass # ignore on systems not supporting uname

out = to_utf8(p.communicate()[0])

# edge-case check: trying to compile on Apple Silicon M1
# using a toolchain that is dual-arch (arm64e and x86_64)
# (transpiled by Rosetta 2) will set __x86_64__ = 1
# however the true host arch is indeed arm64 instead
# uname -v reveals the kernel version string
# which includes the version ARM64 tag which
# gives us certainty that this script is running
# on an ARM platform in reality.
# Handling this edge case is important because
# false-positive cross-compilation would lead v8
# to assume an x86_64 host which breaks the compilation
# as v8 will try to compile the wrong inline
# assembly code branch for the actual ARM based host CPU.
if 'Darwin' in out and 'ARM64' in out:
k['__x86_64__'] = '0'
k['__aarch64__'] = '1'

return k


Expand Down