Skip to content

Commit

Permalink
Don't use default macos/arm64 deployment target in calculating the pl…
Browse files Browse the repository at this point in the history
…atform 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.
  • Loading branch information
ronaldoussoren authored Dec 13, 2020
1 parent 64550e1 commit a717e52
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/wheel/macosx_libfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
- All structures signatures are taken form macosx header files.
- I think that binary format will be more stable than `otool` output.
and if apple introduce some changes both implementation will need to be updated.
- The system compile will set the deployment target no lower than
11.0 for arm64 builds. For "Universal 2" builds use the x86_64 deployment
target when the arm64 target is 11.0.
"""

import ctypes
Expand All @@ -53,6 +56,7 @@
LC_VERSION_MIN_MACOSX = 0x24
LC_BUILD_VERSION = 0x32

CPU_TYPE_ARM64 = 0x0100000c

mach_header_fields = [
("magic", ctypes.c_uint32), ("cputype", ctypes.c_int),
Expand Down Expand Up @@ -271,6 +275,16 @@ class FatArch(BaseClass):
try:
version = read_mach_header(lib_file, el.offset)
if version is not None:
if el.cputype == CPU_TYPE_ARM64 and len(fat_arch_list) != 1:
# Xcode will not set the deployment target below 11.0.0
# for the arm64 architecture. Ignore the arm64 deployment
# in fat binaries when the target is 11.0.0, that way
# the other architetures can select a lower deployment
# target.
# This is safe because there is no arm64 variant for
# macOS 10.15 or earlier.
if version == (11, 0, 0):
continue
versions_list.append(version)
except ValueError:
pass
Expand Down
1 change: 1 addition & 0 deletions tests/test_macosx_libfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_read_from_dylib():
("test_lib_multiple_fat.dylib", "10.14.0"),
("test_lib_10_10_10.dylib", "10.10.10"),
("test_lib_11.dylib", "11.0.0"),
("test_lib_10_9_universal2.dylib", "10.9.0"),
]
for file_name, ver in versions:
extracted = extract_macosx_min_system_version(
Expand Down
Binary file not shown.

0 comments on commit a717e52

Please sign in to comment.