|
| 1 | +$NetBSD: patch-Lib___osx__support.py,v 1.1 2020/11/17 19:33:26 sjmulder Exp $ |
| 2 | + |
| 3 | +Support for macOS 11 and Apple Silicon (ARM). Mostly backported from: |
| 4 | +https://github.com/python/cpython/pull/22855 |
| 5 | + |
| 6 | +--- Lib/_osx_support.py.orig 2020-08-15 05:20:16.000000000 +0000 |
| 7 | ++++ Lib/_osx_support.py |
| 8 | +@@ -110,6 +110,25 @@ def _get_system_version(): |
| 9 | + |
| 10 | + return _SYSTEM_VERSION |
| 11 | + |
| 12 | ++_SYSTEM_VERSION_TUPLE = None |
| 13 | ++def _get_system_version_tuple(): |
| 14 | ++ """ |
| 15 | ++ Return the macOS system version as a tuple |
| 16 | ++ |
| 17 | ++ The return value is safe to use to compare |
| 18 | ++ two version numbers. |
| 19 | ++ """ |
| 20 | ++ global _SYSTEM_VERSION_TUPLE |
| 21 | ++ if _SYSTEM_VERSION_TUPLE is None: |
| 22 | ++ osx_version = _get_system_version() |
| 23 | ++ if osx_version: |
| 24 | ++ try: |
| 25 | ++ _SYSTEM_VERSION_TUPLE = tuple(int(i) for i in osx_version.split('.')) |
| 26 | ++ except ValueError: |
| 27 | ++ _SYSTEM_VERSION_TUPLE = () |
| 28 | ++ |
| 29 | ++ return _SYSTEM_VERSION_TUPLE |
| 30 | ++ |
| 31 | + def _remove_original_values(_config_vars): |
| 32 | + """Remove original unmodified values for testing""" |
| 33 | + # This is needed for higher-level cross-platform tests of get_platform. |
| 34 | +@@ -132,14 +151,18 @@ def _supports_universal_builds(): |
| 35 | + # builds, in particular -isysroot and -arch arguments to the compiler. This |
| 36 | + # is in support of allowing 10.4 universal builds to run on 10.3.x systems. |
| 37 | + |
| 38 | +- osx_version = _get_system_version() |
| 39 | +- if osx_version: |
| 40 | +- try: |
| 41 | +- osx_version = tuple(int(i) for i in osx_version.split('.')) |
| 42 | +- except ValueError: |
| 43 | +- osx_version = '' |
| 44 | ++ osx_version = _get_system_version_tuple() |
| 45 | + return bool(osx_version >= (10, 4)) if osx_version else False |
| 46 | + |
| 47 | ++def _supports_arm64_builds(): |
| 48 | ++ """Returns True if arm64 builds are supported on this system""" |
| 49 | ++ # There are two sets of systems supporting macOS/arm64 builds: |
| 50 | ++ # 1. macOS 11 and later, unconditionally |
| 51 | ++ # 2. macOS 10.15 with Xcode 12.2 or later |
| 52 | ++ # For now the second category is ignored. |
| 53 | ++ osx_version = _get_system_version_tuple() |
| 54 | ++ return osx_version >= (11, 0) if osx_version else False |
| 55 | ++ |
| 56 | + |
| 57 | + def _find_appropriate_compiler(_config_vars): |
| 58 | + """Find appropriate C compiler for extension module builds""" |
| 59 | +@@ -331,6 +354,12 @@ def compiler_fixup(compiler_so, cc_args) |
| 60 | + except ValueError: |
| 61 | + break |
| 62 | + |
| 63 | ++ elif not _supports_arm64_builds(): |
| 64 | ++ # Look for "-arch arm64" and drop that |
| 65 | ++ for idx in range(len(compiler_so)): |
| 66 | ++ if compiler_so[idx] == '-arch' and compiler_so[idx+1] == "arm64": |
| 67 | ++ del compiler_so[idx:idx+2] |
| 68 | ++ |
| 69 | + if 'ARCHFLAGS' in os.environ and not stripArch: |
| 70 | + # User specified different -arch flags in the environ, |
| 71 | + # see also distutils.sysconfig |
| 72 | +@@ -481,6 +510,8 @@ def get_platform_osx(_config_vars, osnam |
| 73 | + |
| 74 | + if len(archs) == 1: |
| 75 | + machine = archs[0] |
| 76 | ++ elif archs == ('arm64', 'x86_64'): |
| 77 | ++ machine = 'universal2' |
| 78 | + elif archs == ('i386', 'ppc'): |
| 79 | + machine = 'fat' |
| 80 | + elif archs == ('i386', 'x86_64'): |
0 commit comments