From a717e52f66a234cc49802147a6242e6342a90a81 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Sun, 13 Dec 2020 12:02:54 +0100 Subject: [PATCH] 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. --- src/wheel/macosx_libfile.py | 14 ++++++++++++++ tests/test_macosx_libfile.py | 1 + .../test_lib_10_9_universal2.dylib | Bin 0 -> 65936 bytes 3 files changed, 15 insertions(+) create mode 100755 tests/testdata/macosx_minimal_system_version/test_lib_10_9_universal2.dylib diff --git a/src/wheel/macosx_libfile.py b/src/wheel/macosx_libfile.py index f8ad3cab..8918039f 100644 --- a/src/wheel/macosx_libfile.py +++ b/src/wheel/macosx_libfile.py @@ -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 @@ -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), @@ -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 diff --git a/tests/test_macosx_libfile.py b/tests/test_macosx_libfile.py index 337f0e30..614e723c 100644 --- a/tests/test_macosx_libfile.py +++ b/tests/test_macosx_libfile.py @@ -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( diff --git a/tests/testdata/macosx_minimal_system_version/test_lib_10_9_universal2.dylib b/tests/testdata/macosx_minimal_system_version/test_lib_10_9_universal2.dylib new file mode 100755 index 0000000000000000000000000000000000000000..26ab109c9957ee2453ddd94a14a7db02bd3e8689 GIT binary patch literal 65936 zcmeI*Z)jCz9KiAC?vHM6?k+W)XmL>!wcMsHb8qx0UbsV1%Voomhh26@qixsip6fr{ zTFr$+!ATPJCW->zD4C3Ok}?PsBM=KrjKmlH*#e_L!mV)qerM;*y9;SVZ=&zR{hjB} zdCqgr`EcLA97<%YSZXPQ5^MY9P$EG=009ILKmY** z5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0 z009ILKmY**5I_I{1Q0*~fqz-x%INKTlK3Bz#D6nILKFV`a*XLQrQV(9$Z<%*+S+Jc ztv59J;7sm%+Xu){z8|ubSFCjtdtARGRrY$3HRI>r@~3D&@BVb{bY*s}O}FlDYHhGh zt&K@Jk-gqof4!K0k@kaU$y_IB>wD^4Yd6+x+7Mk|6TGYA&&aBEg9I(IM}ik#M-I~^ zR!Nje=((V{iIi)bo8oqPrLC4{Z`ze;Pt`ZCC~w#+qsGiPrmHfT{Gi$yUt8Zr?-7x{ zwjHS#OI;+fMIy5V&zSiCVW6M z&t+&Re4(Iwq&|H3@y!0d@R1VfABx`T9t`zH?+lk`o?RP0?B$#XS8op=DV#K0I^No` ze9ha|n-0G*HZ~^9?f9&(Psirz6e*dt=2~m+e3jH1XZ$>PZEKEyvE*QvO86yYLbf&C zVv~)wIpMmJl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