Skip to content

Commit 0e60154

Browse files
committed
unix: start to define target flags in YAML config
As part of moving static configs out of code so things are easier to reason about.
1 parent 604907a commit 0e60154

File tree

2 files changed

+64
-19
lines changed

2 files changed

+64
-19
lines changed

cpython-unix/build.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def add_target_env(env, build_platform, target_triple, build_env):
9595
env["PYBUILD_PLATFORM"] = build_platform
9696
env["TOOLS_PATH"] = build_env.tools_path
9797

98-
extra_target_cflags = []
99-
extra_target_ldflags = []
98+
extra_target_cflags = list(settings.get("target_cflags", []))
99+
extra_target_ldflags = list(settings.get("target_ldflags", []))
100100
extra_host_cflags = []
101101
extra_host_ldflags = []
102102

@@ -109,10 +109,6 @@ def add_target_env(env, build_platform, target_triple, build_env):
109109
else:
110110
env["TARGET_TRIPLE"] = target_triple
111111

112-
if target_triple == "i686-unknown-linux-gnu":
113-
extra_target_cflags.append("-m32")
114-
extra_target_ldflags.append("-m32")
115-
116112
if build_platform == "macos":
117113
machine = platform.machine()
118114

@@ -125,7 +121,6 @@ def add_target_env(env, build_platform, target_triple, build_env):
125121

126122
if target_triple == "aarch64-apple-darwin":
127123
env["TARGET_TRIPLE"] = "aarch64-apple-darwin"
128-
arches = ["arm64"]
129124
sdk_platform = "macosx"
130125
min_version_flags = [
131126
"-mmacosx-version-min=%s" % MACOSX_DEPLOYMENT_TARGET_ARM
@@ -135,49 +130,42 @@ def add_target_env(env, build_platform, target_triple, build_env):
135130
env["TARGET_TRIPLE"] = "aarch64-apple-ios"
136131
# TODO arm64e not supported by open source Clang.
137132
# TODO add arm7 / arm7s?
138-
arches = ["arm64"]
139133
sdk_platform = "iphoneos"
140134
min_version_flags = ["-mios-version-min=%s" % IPHONEOS_DEPLOYMENT_TARGET]
141135
env["APPLE_MIN_DEPLOYMENT_TARGET"] = IPHONEOS_DEPLOYMENT_TARGET
142136
elif target_triple == "arm64-apple-tvos":
143137
env["TARGET_TRIPLE"] = "arm64-apple-tvos"
144-
arches = ["arm64"]
145138
sdk_platform = "appletvos"
146139
min_version_flags = ["-mappletvos-version-min=%s" % TVOS_DEPLOYMENT_TARGET]
147140
env["APPLE_MIN_DEPLOYMENT_TARGET"] = TVOS_DEPLOYMENT_TARGET
148141
elif target_triple == "thumbv7k-apple-watchos":
149142
env["TARGET_TRIPLE"] = "thumbv7k-apple-watchos"
150-
arches = ["armv7k"]
151143
sdk_platform = "watchos"
152144
min_version_flags = ["-mwatchos-version-min=%s" % WATCHOS_DEPLOYMENT_TARGET]
153145
env["APPLE_MIN_DEPLOYMENT_TARGET"] = WATCHOS_DEPLOYMENT_TARGET
154146
elif target_triple == "x86_64-apple-darwin":
155147
env["TARGET_TRIPLE"] = "x86_64-apple-darwin"
156-
arches = ["x86_64"]
157148
sdk_platform = "macosx"
158149
min_version_flags = [
159150
"-mmacosx-version-min=%s" % MACOSX_DEPLOYMENT_TARGET_X86
160151
]
161152
env["APPLE_MIN_DEPLOYMENT_TARGET"] = MACOSX_DEPLOYMENT_TARGET_X86
162153
elif target_triple == "x86_64-apple-ios":
163154
env["TARGET_TRIPLE"] = "x86_64-apple-ios"
164-
arches = ["x86_64"]
165155
sdk_platform = "iphonesimulator"
166156
min_version_flags = [
167157
"-mios-simulator-version-min=%s" % IPHONEOS_DEPLOYMENT_TARGET,
168158
]
169159
env["APPLE_MIN_DEPLOYMENT_TARGET"] = IPHONEOS_DEPLOYMENT_TARGET
170160
elif target_triple == "x86_64-apple-tvos":
171161
env["TARGET_TRIPLE"] = "x86_64-apple-tvos"
172-
arches = ["x86_64"]
173162
sdk_platform = "appletvsimulator"
174163
min_version_flags = [
175164
"-mappletvsimulator-version-min=%s" % TVOS_DEPLOYMENT_TARGET
176165
]
177166
env["APPLE_MIN_DEPLOYMENT_TARGET"] = TVOS_DEPLOYMENT_TARGET
178167
elif target_triple == "x86_64-apple-watchos":
179168
env["TARGET_TRIPLE"] = "x86_64-apple-watchos"
180-
arches = ["x86_64"]
181169
sdk_platform = "watchsimulator"
182170
min_version_flags = [
183171
"-mwatchsimulator-version-min=%s" % WATCHOS_DEPLOYMENT_TARGET
@@ -203,10 +191,6 @@ def add_target_env(env, build_platform, target_triple, build_env):
203191
]
204192
)
205193

206-
for arch in arches:
207-
extra_target_cflags.extend(["-arch", arch])
208-
extra_target_ldflags.extend(["-arch", arch])
209-
210194
if "APPLE_SDK_PATH" in os.environ:
211195
sdk_path = os.environ["APPLE_SDK_PATH"]
212196
else:

cpython-unix/targets.yml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@
1717
# current build environment.
1818
#
1919
# target_cc
20-
#
2120
# Path to C compiler to use for building binaries targeting the
2221
# target architecture.
2322
#
23+
# target_cflags
24+
# List of extra compiler flags to use when building for the target.
25+
#
26+
# Values will be added to CPPFLAGS and CFLAGS.
27+
#
28+
# target_ldflags
29+
# List of extra linker flags to use when building for the target.
30+
#
31+
# Values will be added to LDFLAGS.
32+
#
2433
# openssl_target
2534
# Name of OpenSSL platform build target.
2635

@@ -31,6 +40,12 @@ aarch64-apple-darwin:
3140
needs_toolchain: true
3241
host_cc: clang
3342
target_cc: clang
43+
target_cflags:
44+
- '-arch'
45+
- 'arm64'
46+
target_ldflags:
47+
- '-arch'
48+
- 'arm64'
3449
needs:
3550
- bzip2
3651
- libedit
@@ -51,6 +66,12 @@ aarch64-apple-ios:
5166
needs_toolchain: true
5267
host_cc: clang
5368
target_cc: clang
69+
target_cflags:
70+
- '-arch'
71+
- 'arm64'
72+
target_ldflags:
73+
- '-arch'
74+
- 'arm64'
5475
needs:
5576
- bzip2
5677
- libffi
@@ -93,6 +114,12 @@ arm64-apple-tvos:
93114
needs_toolchain: true
94115
host_cc: clang
95116
target_cc: clang
117+
target_cflags:
118+
- '-arch'
119+
- 'arm64'
120+
target_ldflags:
121+
- '-arch'
122+
- 'arm64'
96123
needs:
97124
- bzip2
98125
- sqlite
@@ -162,6 +189,10 @@ i686-unknown-linux-gnu:
162189
needs_toolchain: true
163190
host_cc: clang
164191
target_cc: clang
192+
target_cflags:
193+
- '-m32'
194+
target_ldflags:
195+
- '-m32'
165196
needs:
166197
- bdb
167198
- binutils
@@ -276,6 +307,12 @@ thumb7k-apple-watchos:
276307
needs_toolchain: true
277308
host_cc: clang
278309
target_cc: clang
310+
target_cflags:
311+
- '-arch'
312+
- 'armv7k'
313+
target_ldflags:
314+
- '-arch'
315+
- 'armv7k'
279316
needs:
280317
- bzip2
281318
- sqlite
@@ -288,6 +325,12 @@ x86_64-apple-darwin:
288325
- darwin
289326
host_cc: clang
290327
target_cc: clang
328+
target_cflags:
329+
- '-arch'
330+
- 'x86_64'
331+
target_ldflags:
332+
- '-arch'
333+
- 'x86_64'
291334
needs:
292335
- bzip2
293336
- libedit
@@ -308,6 +351,12 @@ x86_64-apple-ios:
308351
needs_toolchain: true
309352
host_cc: clang
310353
target_cc: clang
354+
target_cflags:
355+
- '-arch'
356+
- 'x86_64'
357+
target_ldflags:
358+
- '-arch'
359+
- 'x86_64'
311360
needs:
312361
- bzip2
313362
- libffi
@@ -322,6 +371,12 @@ x86_64-apple-tvos:
322371
needs_toolchain: true
323372
host_cc: clang
324373
target_cc: clang
374+
target_cflags:
375+
- '-arch'
376+
- 'x86_64'
377+
target_ldflags:
378+
- '-arch'
379+
- 'x86_64'
325380
needs:
326381
- bzip2
327382
- sqlite
@@ -334,6 +389,12 @@ x86_64-apple-watchos:
334389
needs_toolchain: true
335390
host_cc: clang
336391
target_cc: clang
392+
target_cflags:
393+
- '-arch'
394+
- 'x86_64'
395+
target_ldflags:
396+
- '-arch'
397+
- 'x86_64'
337398
needs:
338399
- bzip2
339400
- sqlite

0 commit comments

Comments
 (0)