Skip to content

Commit a717e52

Browse files
Don't use default macos/arm64 deployment target in calculating the platform tag for fat binaries (#390)
The system compiler in Xcode 12 will not set the deployment target for arm64 below 11.0.0 (which is the first version of macOS supporting arm64). To allow building wheels that target an earlier version of macOS (by way of the x86_64 part of fat binaries) ignore the deployment target in the arm64 part of fat binaries when that's 11.0.0.
1 parent 64550e1 commit a717e52

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/wheel/macosx_libfile.py

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
- All structures signatures are taken form macosx header files.
3434
- I think that binary format will be more stable than `otool` output.
3535
and if apple introduce some changes both implementation will need to be updated.
36+
- The system compile will set the deployment target no lower than
37+
11.0 for arm64 builds. For "Universal 2" builds use the x86_64 deployment
38+
target when the arm64 target is 11.0.
3639
"""
3740

3841
import ctypes
@@ -53,6 +56,7 @@
5356
LC_VERSION_MIN_MACOSX = 0x24
5457
LC_BUILD_VERSION = 0x32
5558

59+
CPU_TYPE_ARM64 = 0x0100000c
5660

5761
mach_header_fields = [
5862
("magic", ctypes.c_uint32), ("cputype", ctypes.c_int),
@@ -271,6 +275,16 @@ class FatArch(BaseClass):
271275
try:
272276
version = read_mach_header(lib_file, el.offset)
273277
if version is not None:
278+
if el.cputype == CPU_TYPE_ARM64 and len(fat_arch_list) != 1:
279+
# Xcode will not set the deployment target below 11.0.0
280+
# for the arm64 architecture. Ignore the arm64 deployment
281+
# in fat binaries when the target is 11.0.0, that way
282+
# the other architetures can select a lower deployment
283+
# target.
284+
# This is safe because there is no arm64 variant for
285+
# macOS 10.15 or earlier.
286+
if version == (11, 0, 0):
287+
continue
274288
versions_list.append(version)
275289
except ValueError:
276290
pass

tests/test_macosx_libfile.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_read_from_dylib():
2323
("test_lib_multiple_fat.dylib", "10.14.0"),
2424
("test_lib_10_10_10.dylib", "10.10.10"),
2525
("test_lib_11.dylib", "11.0.0"),
26+
("test_lib_10_9_universal2.dylib", "10.9.0"),
2627
]
2728
for file_name, ver in versions:
2829
extracted = extract_macosx_min_system_version(
Binary file not shown.

0 commit comments

Comments
 (0)