Skip to content

Commit 2b90ff7

Browse files
committed
unix: conditionally install toolchain
Upcoming commits will introduce Docker images where the cross toolchain is part of the Docker image. In preparation, this commit teaches the build to conditionally install toolchains. There should be no functional change in behavior as a result of this commits.
1 parent d49e9ea commit 2b90ff7

File tree

3 files changed

+80
-38
lines changed

3 files changed

+80
-38
lines changed

cpython-unix/build.py

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
add_licenses_to_extension_entry,
3030
download_entry,
3131
get_targets,
32+
get_target_settings,
3233
target_needs,
3334
validate_python_json,
3435
write_package_versions,
@@ -263,6 +264,7 @@ def install_binutils(platform):
263264

264265

265266
def simple_build(
267+
settings,
266268
client,
267269
image,
268270
entry,
@@ -275,13 +277,14 @@ def simple_build(
275277
archive = download_entry(entry, DOWNLOADS_PATH)
276278

277279
with build_environment(client, image) as build_env:
278-
build_env.install_toolchain(
279-
BUILD,
280-
host_platform,
281-
binutils=install_binutils(host_platform),
282-
clang=True,
283-
musl="musl" in target_triple,
284-
)
280+
if settings.get("needs_toolchain"):
281+
build_env.install_toolchain(
282+
BUILD,
283+
host_platform,
284+
binutils=install_binutils(host_platform),
285+
clang=True,
286+
musl="musl" in target_triple,
287+
)
285288

286289
for a in extra_archives or []:
287290
build_env.install_artifact_archive(BUILD, a, target_triple, optimizations)
@@ -448,18 +451,19 @@ def build_musl(client, image, host_platform):
448451

449452

450453
def build_libedit(
451-
client, image, host_platform, target_triple, optimizations, dest_archive
454+
settings, client, image, host_platform, target_triple, optimizations, dest_archive
452455
):
453456
libedit_archive = download_entry("libedit", DOWNLOADS_PATH)
454457

455458
with build_environment(client, image) as build_env:
456-
build_env.install_toolchain(
457-
BUILD,
458-
host_platform,
459-
binutils=install_binutils(host_platform),
460-
clang=True,
461-
musl="musl" in target_triple,
462-
)
459+
if settings.get("needs_toolchain"):
460+
build_env.install_toolchain(
461+
BUILD,
462+
host_platform,
463+
binutils=install_binutils(host_platform),
464+
clang=True,
465+
musl="musl" in target_triple,
466+
)
463467

464468
build_env.install_artifact_archive(
465469
BUILD, "ncurses", target_triple, optimizations
@@ -483,18 +487,19 @@ def build_libedit(
483487

484488

485489
def build_readline(
486-
client, image, host_platform, target_triple, optimizations, dest_archive
490+
settings, client, image, host_platform, target_triple, optimizations, dest_archive
487491
):
488492
readline_archive = download_entry("readline", DOWNLOADS_PATH)
489493

490494
with build_environment(client, image) as build_env:
491-
build_env.install_toolchain(
492-
BUILD,
493-
host_platform,
494-
binutils=True,
495-
clang=True,
496-
musl="musl" in target_triple,
497-
)
495+
if settings.get("needs_toolchain"):
496+
build_env.install_toolchain(
497+
BUILD,
498+
host_platform,
499+
binutils=True,
500+
clang=True,
501+
musl="musl" in target_triple,
502+
)
498503

499504
build_env.install_artifact_archive(
500505
BUILD, "ncurses", target_triple, optimizations
@@ -517,19 +522,22 @@ def build_readline(
517522
build_env.get_tools_archive(dest_archive, "deps")
518523

519524

520-
def build_tix(client, image, host_platform, target_triple, optimizations, dest_archive):
525+
def build_tix(
526+
settings, client, image, host_platform, target_triple, optimizations, dest_archive
527+
):
521528
tcl_archive = download_entry("tcl", DOWNLOADS_PATH)
522529
tk_archive = download_entry("tk", DOWNLOADS_PATH)
523530
tix_archive = download_entry("tix", DOWNLOADS_PATH)
524531

525532
with build_environment(client, image) as build_env:
526-
build_env.install_toolchain(
527-
BUILD,
528-
host_platform,
529-
binutils=install_binutils(host_platform),
530-
clang=True,
531-
musl="musl" in target_triple,
532-
)
533+
if settings.get("needs_toolchain"):
534+
build_env.install_toolchain(
535+
BUILD,
536+
host_platform,
537+
binutils=install_binutils(host_platform),
538+
clang=True,
539+
musl="musl" in target_triple,
540+
)
533541

534542
depends = {"tcl", "tk"}
535543
if host_platform != "macos":
@@ -794,6 +802,7 @@ def get_target_support_file(prefix, python_version, host_platform, target_triple
794802

795803

796804
def build_cpython(
805+
settings,
797806
client,
798807
image,
799808
host_platform,
@@ -838,13 +847,14 @@ def build_cpython(
838847
extra_make_content = setup["make_data"]
839848

840849
with build_environment(client, image) as build_env:
841-
build_env.install_toolchain(
842-
BUILD,
843-
host_platform,
844-
binutils=install_binutils(host_platform),
845-
clang=True,
846-
musl="musl" in target_triple,
847-
)
850+
if settings.get("needs_toolchain"):
851+
build_env.install_toolchain(
852+
BUILD,
853+
host_platform,
854+
binutils=install_binutils(host_platform),
855+
clang=True,
856+
musl="musl" in target_triple,
857+
)
848858

849859
packages = target_needs(TARGETS_CONFIG, target_triple)
850860
# Toolchain packages are handled specially.
@@ -1044,6 +1054,8 @@ def main():
10441054
dest_archive = pathlib.Path(args.dest_archive)
10451055
docker_image = args.docker_image
10461056

1057+
settings = get_target_settings(TARGETS_CONFIG, target_triple)
1058+
10471059
if args.action == "makefiles":
10481060
log_name = "makefiles"
10491061
elif args.action.startswith("image-"):
@@ -1088,6 +1100,7 @@ def main():
10881100

10891101
elif action == "libedit":
10901102
build_libedit(
1103+
settings,
10911104
client,
10921105
get_image(client, ROOT, BUILD, docker_image),
10931106
host_platform=host_platform,
@@ -1098,6 +1111,7 @@ def main():
10981111

10991112
elif action == "readline":
11001113
build_readline(
1114+
settings,
11011115
client,
11021116
get_image(client, ROOT, BUILD, docker_image),
11031117
host_platform=host_platform,
@@ -1130,6 +1144,7 @@ def main():
11301144
"zlib",
11311145
):
11321146
simple_build(
1147+
settings,
11331148
client,
11341149
get_image(client, ROOT, BUILD, docker_image),
11351150
action,
@@ -1141,6 +1156,7 @@ def main():
11411156

11421157
elif action == "libX11":
11431158
simple_build(
1159+
settings,
11441160
client,
11451161
get_image(client, ROOT, BUILD, docker_image),
11461162
action,
@@ -1164,6 +1180,7 @@ def main():
11641180

11651181
elif action == "libXau":
11661182
simple_build(
1183+
settings,
11671184
client,
11681185
get_image(client, ROOT, BUILD, docker_image),
11691186
action,
@@ -1176,6 +1193,7 @@ def main():
11761193

11771194
elif action == "xcb-proto":
11781195
simple_build(
1196+
settings,
11791197
client,
11801198
get_image(client, ROOT, BUILD, docker_image),
11811199
action,
@@ -1187,6 +1205,7 @@ def main():
11871205

11881206
elif action == "libxcb":
11891207
simple_build(
1208+
settings,
11901209
client,
11911210
get_image(client, ROOT, BUILD, docker_image),
11921211
action,
@@ -1199,6 +1218,7 @@ def main():
11991218

12001219
elif action == "tix":
12011220
build_tix(
1221+
settings,
12021222
client,
12031223
get_image(client, ROOT, BUILD, docker_image),
12041224
host_platform=host_platform,
@@ -1219,6 +1239,7 @@ def main():
12191239
}
12201240

12211241
simple_build(
1242+
settings,
12221243
client,
12231244
get_image(client, ROOT, BUILD, docker_image),
12241245
action,
@@ -1231,6 +1252,7 @@ def main():
12311252

12321253
elif action in ("cpython-3.8", "cpython-3.9", "cpython-3.10"):
12331254
build_cpython(
1255+
settings,
12341256
client,
12351257
get_image(client, ROOT, BUILD, docker_image),
12361258
host_platform=host_platform,

cpython-unix/targets.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
# Defines the Python sys.platform value where this configuration
55
# can be built from.
66
#
7+
# needs_toolchain
8+
# Whether this build requires the presence of a custom compiled toolchain.
9+
# If not defined, it is assumed the toolchain is present in the build
10+
# environment already.
11+
#
712
# needs
813
# Packages required to build Python.
914
#
@@ -14,6 +19,7 @@
1419
aarch64-apple-darwin:
1520
host_platforms:
1621
- darwin
22+
needs_toolchain: true
1723
needs:
1824
- bzip2
1925
- libedit
@@ -31,6 +37,7 @@ aarch64-apple-darwin:
3137
aarch64-apple-ios:
3238
host_platforms:
3339
- darwin
40+
needs_toolchain: true
3441
needs:
3542
- bzip2
3643
- libffi
@@ -42,6 +49,7 @@ aarch64-apple-ios:
4249
arm64-apple-tvos:
4350
host_platforms:
4451
- darwin
52+
needs_toolchain: true
4553
needs:
4654
- bzip2
4755
- sqlite
@@ -52,6 +60,7 @@ arm64-apple-tvos:
5260
i686-unknown-linux-gnu:
5361
host_platforms:
5462
- linux
63+
needs_toolchain: true
5564
needs:
5665
- bdb
5766
- binutils
@@ -79,6 +88,7 @@ i686-unknown-linux-gnu:
7988
thumb7k-apple-watchos:
8089
host_platforms:
8190
- darwin
91+
needs_toolchain: true
8292
needs:
8393
- bzip2
8494
- sqlite
@@ -106,6 +116,7 @@ x86_64-apple-darwin:
106116
x86_64-apple-ios:
107117
host_platforms:
108118
- darwin
119+
needs_toolchain: true
109120
needs:
110121
- bzip2
111122
- libffi
@@ -117,6 +128,7 @@ x86_64-apple-ios:
117128
x86_64-apple-tvos:
118129
host_platforms:
119130
- darwin
131+
needs_toolchain: true
120132
needs:
121133
- bzip2
122134
- sqlite
@@ -126,6 +138,7 @@ x86_64-apple-tvos:
126138
x86_64-apple-watchos:
127139
host_platforms:
128140
- darwin
141+
needs_toolchain: true
129142
needs:
130143
- bzip2
131144
- sqlite
@@ -136,6 +149,7 @@ x86_64-apple-watchos:
136149
x86_64-unknown-linux-gnu:
137150
host_platforms:
138151
- linux
152+
needs_toolchain: true
139153
needs:
140154
- bdb
141155
- binutils
@@ -162,6 +176,7 @@ x86_64-unknown-linux-gnu:
162176
x86_64-unknown-linux-musl:
163177
host_platforms:
164178
- linux
179+
needs_toolchain: true
165180
needs:
166181
- bdb
167182
- binutils

pythonbuild/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def get_targets(yaml_path: pathlib.Path):
2626
return yaml.load(fh, Loader=yaml.SafeLoader)
2727

2828

29+
def get_target_settings(yaml_path: pathlib.Path, target: str):
30+
"""Obtain the settings for a named target."""
31+
return get_targets(yaml_path)[target]
32+
33+
2934
def supported_targets(yaml_path: pathlib.Path):
3035
"""Obtain a set of named targets that we can build."""
3136
targets = set()

0 commit comments

Comments
 (0)