Skip to content

Commit 49e2750

Browse files
committed
unix: define the list of supported build targets in YAML config
1 parent 905565e commit 49e2750

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

cpython-unix/build-main.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@
1414
from pythonbuild.utils import (
1515
compress_python_archive,
1616
release_tag_from_git,
17+
supported_targets,
1718
)
1819

1920
ROOT = pathlib.Path(os.path.abspath(__file__)).parent.parent
2021
BUILD = ROOT / "build"
2122
DIST = ROOT / "dist"
23+
SUPPORT = ROOT / "cpython-unix"
24+
TARGETS_CONFIG = SUPPORT / "targets.yml"
2225

2326

2427
def main():
2528
if sys.platform == "linux":
2629
host_platform = "linux64"
2730
default_target_triple = "x86_64-unknown-linux-gnu"
28-
targets = {
29-
"x86_64-unknown-linux-gnu",
30-
"x86_64-unknown-linux-musl",
31-
}
3231
elif sys.platform == "darwin":
3332
host_platform = "macos"
3433
machine = platform.machine()
@@ -39,17 +38,6 @@ def main():
3938
default_target_triple = "x86_64-apple-darwin"
4039
else:
4140
raise Exception("unhandled macOS machine value: %s" % machine)
42-
43-
targets = {
44-
"aarch64-apple-darwin",
45-
"aarch64-apple-ios",
46-
"arm64-apple-tvos",
47-
"thumbv7k-apple-watchos",
48-
"x86_64-apple-darwin",
49-
"x86_64-apple-ios",
50-
"x86_64-apple-tvos",
51-
"x86_64-apple-watchos",
52-
}
5341
else:
5442
print("unsupport build platform: %s" % sys.platform)
5543
return 1
@@ -59,7 +47,7 @@ def main():
5947
parser.add_argument(
6048
"--target-triple",
6149
default=default_target_triple,
62-
choices=targets,
50+
choices=supported_targets(TARGETS_CONFIG),
6351
help="Target host triple to build for",
6452
)
6553

cpython-unix/build.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import tempfile
1414

1515
import docker
16-
import yaml
1716

1817
from pythonbuild.buildenv import build_environment
1918
from pythonbuild.cpython import (
@@ -29,6 +28,7 @@
2928
add_env_common,
3029
add_licenses_to_extension_entry,
3130
download_entry,
31+
get_targets,
3232
validate_python_json,
3333
write_package_versions,
3434
write_triples_makefiles,
@@ -53,12 +53,6 @@
5353
WATCHOS_DEPLOYMENT_TARGET = "7.0"
5454

5555

56-
def get_targets():
57-
"""Obtain the parsed targets YAML file."""
58-
with TARGETS_CONFIG.open("rb") as fh:
59-
return yaml.load(fh, Loader=yaml.SafeLoader)
60-
61-
6256
def install_sccache(build_env):
6357
"""Attempt to install sccache into the build environment.
6458
@@ -1080,7 +1074,7 @@ def main():
10801074
with log_path.open("wb") as log_fh:
10811075
set_logger(action, log_fh)
10821076
if action == "makefiles":
1083-
write_triples_makefiles(get_targets(), BUILD)
1077+
write_triples_makefiles(get_targets(TARGETS_CONFIG), BUILD)
10841078
write_package_versions(BUILD / "versions")
10851079

10861080
elif action.startswith("image-"):

cpython-unix/targets.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
# This file defines configurations for each supported build target/triple.
2+
#
3+
# host_platform
4+
# Defines the Python sys.platform value where this configuration
5+
# can be built from.
6+
#
7+
# needs
8+
# Packages required to build Python.
9+
110
---
211
aarch64-apple-darwin:
12+
host_platforms:
13+
- darwin
314
needs:
415
- libedit
516
- libffi
@@ -9,18 +20,26 @@ aarch64-apple-darwin:
920
- uuid
1021

1122
aarch64-apple-ios:
23+
host_platforms:
24+
- darwin
1225
needs:
1326
- sqlite
1427

1528
arm64-apple-tvos:
29+
host_platforms:
30+
- darwin
1631
needs:
1732
- sqlite
1833

1934
thumb7k-apple-watchos:
35+
host_platforms:
36+
- darwin
2037
needs:
2138
- sqlite
2239

2340
x86_64-apple-darwin:
41+
host_platforms:
42+
- darwin
2443
needs:
2544
- libedit
2645
- libffi
@@ -30,18 +49,26 @@ x86_64-apple-darwin:
3049
- uuid
3150

3251
x86_64-apple-ios:
52+
host_platforms:
53+
- darwin
3354
needs:
3455
- sqlite
3556

3657
x86_64-apple-tvos:
58+
host_platforms:
59+
- darwin
3760
needs:
3861
- sqlite
3962

4063
x86_64-apple-watchos:
64+
host_platforms:
65+
- darwin
4166
needs:
4267
- sqlite
4368

4469
x86_64-unknown-linux-gnu:
70+
host_platforms:
71+
- linux
4572
needs:
4673
- bdb
4774
- binutils
@@ -57,6 +84,8 @@ x86_64-unknown-linux-gnu:
5784
- uuid
5885

5986
x86_64-unknown-linux-musl:
87+
host_platforms:
88+
- linux
6089
needs:
6190
- bdb
6291
- binutils

pythonbuild/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
from .logging import log
2121

2222

23+
def get_targets(yaml_path: pathlib.Path):
24+
"""Obtain the parsed targets YAML file."""
25+
with yaml_path.open("rb") as fh:
26+
return yaml.load(fh, Loader=yaml.SafeLoader)
27+
28+
29+
def supported_targets(yaml_path: pathlib.Path):
30+
"""Obtain a set of named targets that we can build."""
31+
targets = set()
32+
33+
for target, settings in get_targets(yaml_path).items():
34+
for platform in settings["host_platforms"]:
35+
if sys.platform == platform:
36+
targets.add(target)
37+
38+
return targets
39+
40+
2341
def release_tag_from_git():
2442
return (
2543
subprocess.check_output(

0 commit comments

Comments
 (0)