Skip to content

Commit e42363d

Browse files
committed
unix: move Apple minimum SDK version flags to YAML
1 parent b9207f2 commit e42363d

File tree

2 files changed

+37
-40
lines changed

2 files changed

+37
-40
lines changed

cpython-unix/build.py

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import pathlib
1010
import platform
11+
import re
1112
import subprocess
1213
import sys
1314
import tempfile
@@ -42,18 +43,6 @@
4243
SUPPORT = ROOT / "cpython-unix"
4344
TARGETS_CONFIG = SUPPORT / "targets.yml"
4445

45-
# Target older macOS on x86 for maximum run-time compatibility.
46-
MACOSX_DEPLOYMENT_TARGET_X86 = "10.9"
47-
48-
# ARM macOS only supports 11.0+, so we can use a newer target.
49-
MACOSX_DEPLOYMENT_TARGET_ARM = "11.0"
50-
51-
IPHONEOS_DEPLOYMENT_TARGET = "12.3"
52-
53-
TVOS_DEPLOYMENT_TARGET = "12.3"
54-
55-
WATCHOS_DEPLOYMENT_TARGET = "7.0"
56-
5746

5847
def install_sccache(build_env):
5948
"""Attempt to install sccache into the build environment.
@@ -119,50 +108,35 @@ def add_target_env(env, build_platform, target_triple, build_env):
119108
else:
120109
raise Exception("unhandled macOS machine value: %s" % machine)
121110

111+
# Sniff out the Apple SDK minimum deployment target from cflags and
112+
# export in its own variable. This is used by CPython's configure, as
113+
# it doesn't sniff the cflag.
114+
for flag in extra_target_cflags:
115+
m = re.search("-version-min=(.*)$", flag)
116+
if m:
117+
env["APPLE_MIN_DEPLOYMENT_TARGET"] = m.group(1)
118+
break
119+
else:
120+
raise Exception("could not find minimum Apple SDK version in cflags")
121+
122122
if target_triple == "aarch64-apple-darwin":
123123
sdk_platform = "macosx"
124-
min_version_flags = [
125-
"-mmacosx-version-min=%s" % MACOSX_DEPLOYMENT_TARGET_ARM
126-
]
127-
env["APPLE_MIN_DEPLOYMENT_TARGET"] = MACOSX_DEPLOYMENT_TARGET_ARM
128124
elif target_triple == "aarch64-apple-ios":
129125
# TODO arm64e not supported by open source Clang.
130126
# TODO add arm7 / arm7s?
131127
sdk_platform = "iphoneos"
132-
min_version_flags = ["-mios-version-min=%s" % IPHONEOS_DEPLOYMENT_TARGET]
133-
env["APPLE_MIN_DEPLOYMENT_TARGET"] = IPHONEOS_DEPLOYMENT_TARGET
134128
elif target_triple == "arm64-apple-tvos":
135129
sdk_platform = "appletvos"
136-
min_version_flags = ["-mappletvos-version-min=%s" % TVOS_DEPLOYMENT_TARGET]
137-
env["APPLE_MIN_DEPLOYMENT_TARGET"] = TVOS_DEPLOYMENT_TARGET
138130
elif target_triple == "thumbv7k-apple-watchos":
139131
sdk_platform = "watchos"
140-
min_version_flags = ["-mwatchos-version-min=%s" % WATCHOS_DEPLOYMENT_TARGET]
141-
env["APPLE_MIN_DEPLOYMENT_TARGET"] = WATCHOS_DEPLOYMENT_TARGET
142132
elif target_triple == "x86_64-apple-darwin":
143133
sdk_platform = "macosx"
144-
min_version_flags = [
145-
"-mmacosx-version-min=%s" % MACOSX_DEPLOYMENT_TARGET_X86
146-
]
147-
env["APPLE_MIN_DEPLOYMENT_TARGET"] = MACOSX_DEPLOYMENT_TARGET_X86
148134
elif target_triple == "x86_64-apple-ios":
149135
sdk_platform = "iphonesimulator"
150-
min_version_flags = [
151-
"-mios-simulator-version-min=%s" % IPHONEOS_DEPLOYMENT_TARGET,
152-
]
153-
env["APPLE_MIN_DEPLOYMENT_TARGET"] = IPHONEOS_DEPLOYMENT_TARGET
154136
elif target_triple == "x86_64-apple-tvos":
155137
sdk_platform = "appletvsimulator"
156-
min_version_flags = [
157-
"-mappletvsimulator-version-min=%s" % TVOS_DEPLOYMENT_TARGET
158-
]
159-
env["APPLE_MIN_DEPLOYMENT_TARGET"] = TVOS_DEPLOYMENT_TARGET
160138
elif target_triple == "x86_64-apple-watchos":
161139
sdk_platform = "watchsimulator"
162-
min_version_flags = [
163-
"-mwatchsimulator-version-min=%s" % WATCHOS_DEPLOYMENT_TARGET
164-
]
165-
env["APPLE_MIN_DEPLOYMENT_TARGET"] = WATCHOS_DEPLOYMENT_TARGET
166140
else:
167141
raise ValueError("unhandled target triple: %s" % target_triple)
168142

@@ -207,8 +181,6 @@ def add_target_env(env, build_platform, target_triple, build_env):
207181

208182
extra_target_cflags.extend(["-isysroot", sdk_path])
209183
extra_target_ldflags.extend(["-isysroot", sdk_path])
210-
extra_target_cflags.extend(min_version_flags)
211-
extra_target_ldflags.extend(min_version_flags)
212184

213185
# The host SDK may be for a different platform from the target SDK.
214186
# Resolve that separately.

cpython-unix/targets.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
# Name of OpenSSL platform build target.
3535

3636
---
37+
38+
# Apple silicon macOS.
39+
#
40+
# We target compatibility with macOS 11.0+ because Apple silicon only supports
41+
# 11.0+.
3742
aarch64-apple-darwin:
3843
host_platforms:
3944
- darwin
@@ -43,9 +48,11 @@ aarch64-apple-darwin:
4348
target_cflags:
4449
- '-arch'
4550
- 'arm64'
51+
- '-mmacosx-version-min=11.0'
4652
target_ldflags:
4753
- '-arch'
4854
- 'arm64'
55+
- '-mmacosx-version-min=11.0'
4956
needs:
5057
- bzip2
5158
- libedit
@@ -69,9 +76,11 @@ aarch64-apple-ios:
6976
target_cflags:
7077
- '-arch'
7178
- 'arm64'
79+
- '-mios-version-min=12.3'
7280
target_ldflags:
7381
- '-arch'
7482
- 'arm64'
83+
- '-mios-version-min=12.3'
7584
needs:
7685
- bzip2
7786
- libffi
@@ -117,9 +126,11 @@ arm64-apple-tvos:
117126
target_cflags:
118127
- '-arch'
119128
- 'arm64'
129+
- '-mappletvos-version-min=12.3'
120130
target_ldflags:
121131
- '-arch'
122132
- 'arm64'
133+
- '-mappletvos-version-min=12.3'
123134
needs:
124135
- bzip2
125136
- sqlite
@@ -310,16 +321,22 @@ thumb7k-apple-watchos:
310321
target_cflags:
311322
- '-arch'
312323
- 'armv7k'
324+
- '-mwatchos-version-min-7.0'
313325
target_ldflags:
314326
- '-arch'
315327
- 'armv7k'
328+
- '-mwatchos-version-min-7.0'
316329
needs:
317330
- bzip2
318331
- sqlite
319332
- xz
320333
- zlib
321334
openssl_target: todo
322335

336+
# Intel macOS.
337+
#
338+
# We target compatibility with macOS 10.9+ for compatibility with older Apple
339+
# machines.
323340
x86_64-apple-darwin:
324341
host_platforms:
325342
- darwin
@@ -328,9 +345,11 @@ x86_64-apple-darwin:
328345
target_cflags:
329346
- '-arch'
330347
- 'x86_64'
348+
- '-mmacosx-version-min=10.9'
331349
target_ldflags:
332350
- '-arch'
333351
- 'x86_64'
352+
- '-mmacosx-version-min=10.9'
334353
needs:
335354
- bzip2
336355
- libedit
@@ -354,9 +373,11 @@ x86_64-apple-ios:
354373
target_cflags:
355374
- '-arch'
356375
- 'x86_64'
376+
- '-mios-simulator-version-min=12.3'
357377
target_ldflags:
358378
- '-arch'
359379
- 'x86_64'
380+
- '-mios-simulator-version-min=12.3'
360381
needs:
361382
- bzip2
362383
- libffi
@@ -374,9 +395,11 @@ x86_64-apple-tvos:
374395
target_cflags:
375396
- '-arch'
376397
- 'x86_64'
398+
- '-mappletvsimulator-version-min=12.3'
377399
target_ldflags:
378400
- '-arch'
379401
- 'x86_64'
402+
- '-mappletvsimulator-version-min=12.3'
380403
needs:
381404
- bzip2
382405
- sqlite
@@ -392,9 +415,11 @@ x86_64-apple-watchos:
392415
target_cflags:
393416
- '-arch'
394417
- 'x86_64'
418+
- '-mwatchsimulator-version-min=7.0'
395419
target_ldflags:
396420
- '-arch'
397421
- 'x86_64'
422+
- '-mwatchsimulator-version-min=7.0'
398423
needs:
399424
- bzip2
400425
- sqlite

0 commit comments

Comments
 (0)