Get SDK version dynamically
This commit is contained in:
+23
-7
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -63,6 +64,15 @@ def get_xcode_version() -> Tuple[int, int]:
|
||||
return (int(version_parts[0]), int(version_parts[1]))
|
||||
|
||||
|
||||
def get_macos_sdks() -> List[str]:
|
||||
output = subprocess.check_output(
|
||||
['xcodebuild', '-showsdks'],
|
||||
universal_newlines=True,
|
||||
)
|
||||
|
||||
return [m.group(1) for m in re.finditer(r'-sdk (macosx\S+)', output)]
|
||||
|
||||
|
||||
class PythonConfiguration(NamedTuple):
|
||||
version: str
|
||||
identifier: str
|
||||
@@ -258,16 +268,22 @@ def setup_python(python_configuration: PythonConfiguration,
|
||||
env.setdefault('ARCHFLAGS', '-arch arm64 -arch x86_64')
|
||||
|
||||
if python_configuration.identifier.endswith('arm64') or python_configuration.identifier.endswith('universal2'):
|
||||
if get_macos_version() < (10, 16):
|
||||
if get_macos_version() < (10, 16) and 'SDKROOT' not in env:
|
||||
# xcode 12.2 or higher can build arm64 on macos 10.15 or below, but
|
||||
# needs the correct SDK selected
|
||||
# needs the correct SDK selected.
|
||||
sdks = get_macos_sdks()
|
||||
|
||||
# however, different versions of Xcode contain different SDK
|
||||
# versions...
|
||||
if get_xcode_version() == (12, 2):
|
||||
env.setdefault('SDKROOT', 'macosx11.0')
|
||||
# Different versions of Xcode contain different SDK versions...
|
||||
# we're happy with anything newer than macOS 11.0
|
||||
arm64_compatible_sdks = [s for s in sdks if not s.startswith('macosx10.')]
|
||||
|
||||
if not arm64_compatible_sdks:
|
||||
log.warning(unwrap('''
|
||||
SDK for building arm64-compatible wheels not found. You need Xcode 12.2 or later
|
||||
to build universal2 or arm64 wheels.
|
||||
'''))
|
||||
else:
|
||||
env.setdefault('SDKROOT', 'macosx11.1')
|
||||
env.setdefault('SDKROOT', arm64_compatible_sdks[0])
|
||||
|
||||
log.step('Installing build tools...')
|
||||
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate', *dependency_constraint_flags], env=env)
|
||||
|
||||
Reference in New Issue
Block a user