Skip to content

Commit b2c1f89

Browse files
committed
chore: added Apple Silicon M1 host arch _LP64 to the arch mapping
Fixes: #40302
1 parent 7f2cb44 commit b2c1f89

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

configure.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,34 @@ def cc_macros(cc=None):
10221022
key = lst[1]
10231023
val = lst[2]
10241024
k[key] = val
1025+
1026+
try:
1027+
p = subprocess.Popen(shlex.split('uname') + ['-v'],
1028+
stdin=subprocess.PIPE,
1029+
stdout=subprocess.PIPE,
1030+
stderr=subprocess.PIPE)
1031+
except OSError:
1032+
pass # ignore on systems not supporting uname
1033+
1034+
out = to_utf8(p.communicate()[0])
1035+
1036+
# edge-case check: trying to compile on Apple Silicon M1
1037+
# using a toolchain that is dual-arch (arm64e and x86_64)
1038+
# (transpiled by Rosetta 2) will set __x86_64__ = 1
1039+
# however the true host arch is indeed arm64 instead
1040+
# uname -v reveals the kernel version string
1041+
# which includes the version ARM64 tag which
1042+
# gives us certainty that this script is running
1043+
# on an ARM platform in reality.
1044+
# Handling this edge case is important because
1045+
# false-positive cross-compilation would lead v8
1046+
# to assume an x86_64 host which breaks the compilation
1047+
# as v8 will try to compile the wrong inline
1048+
# assembly code branch for the actual ARM based host CPU.
1049+
if 'Darwin' in out and 'ARM64' in out:
1050+
k['__x86_64__'] = '0'
1051+
k['__aarch64__'] = '1'
1052+
10251053
return k
10261054

10271055

0 commit comments

Comments
 (0)