Skip to content

Commit 784ea01

Browse files
authoredMay 21, 2025
Rework host platform naming (#617)
1 parent 7c83f65 commit 784ea01

File tree

10 files changed

+117
-86
lines changed

10 files changed

+117
-86
lines changed
 

‎cpython-unix/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ $(OUTDIR)/$(CLANG_FILENAME):
8686
$(OUTDIR)/musl-$(MUSL_VERSION)-$(HOST_PLATFORM).tar: $(BASE_TOOLCHAIN_DEPENDS) $(HERE)/build-musl.sh
8787
$(RUN_BUILD) --toolchain musl
8888

89-
ifeq ($(HOST_PLATFORM),linux64)
89+
ifeq ($(HOST_PLATFORM),linux_x86_64)
9090
TOOLCHAIN_TARGET := $(OUTDIR)/musl-$(MUSL_VERSION)-$(HOST_PLATFORM).tar
9191
else
9292
TOOLCHAIN_TARGET :=

‎cpython-unix/build-cpython-host.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export trailer_m4=${TOOLS_PATH}/host/share/autoconf/autoconf/trailer.m4
2222

2323
# The share/autoconf/autom4te.cfg file also hard-codes some paths. Rewrite
2424
# those to the real tools path.
25-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
25+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
2626
sed_args="-i '' -e"
2727
else
2828
sed_args="-i"

‎cpython-unix/build-cpython.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export trailer_m4=${TOOLS_PATH}/host/share/autoconf/autoconf/trailer.m4
3333

3434
# The share/autoconf/autom4te.cfg file also hard-codes some paths. Rewrite
3535
# those to the real tools path.
36-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
36+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
3737
sed_args=(-i '' -e)
3838
else
3939
sed_args=(-i)
@@ -59,7 +59,7 @@ cat Makefile.extra
5959
pushd Python-${PYTHON_VERSION}
6060

6161
# configure doesn't support cross-compiling on Apple. Teach it.
62-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
62+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
6363
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
6464
patch -p1 -i ${ROOT}/patch-apple-cross-3.13.patch
6565
elif [ "${PYTHON_MAJMIN_VERSION}" = "3.12" ]; then
@@ -159,7 +159,7 @@ fi
159159
# linked modules. But those libraries should only get linked into libpython, not the
160160
# executable. This behavior is kinda suspect on all platforms, as it could be adding
161161
# library dependencies that shouldn't need to be there.
162-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
162+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
163163
if [ "${PYTHON_MAJMIN_VERSION}" = "3.9" ]; then
164164
patch -p1 -i ${ROOT}/patch-python-link-modules-3.9.patch
165165
elif [ "${PYTHON_MAJMIN_VERSION}" = "3.10" ]; then
@@ -214,7 +214,7 @@ fi
214214
# macOS. On older versions, we need to hack up readline.c to build against
215215
# libedit. This patch breaks older libedit (as seen on macOS) so don't apply
216216
# on macOS.
217-
if [[ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_9}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
217+
if [[ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_9}" && "${PYBUILD_PLATFORM}" != macos* ]]; then
218218
# readline.c assumes that a modern readline API version has a free_history_entry().
219219
# but libedit does not. Change the #ifdef accordingly.
220220
#
@@ -317,13 +317,13 @@ CFLAGS=${CFLAGS//-fvisibility=hidden/}
317317

318318
# But some symbols from some dependency libraries are still non-hidden for some
319319
# reason. We force the linker to do our bidding.
320-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
320+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
321321
LDFLAGS="${LDFLAGS} -Wl,--exclude-libs,ALL"
322322
fi
323323

324324
EXTRA_CONFIGURE_FLAGS=
325325

326-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
326+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
327327
CFLAGS="${CFLAGS} -I${TOOLS_PATH}/deps/include/uuid"
328328

329329
# Prevent using symbols not supported by current macOS SDK target.
@@ -332,7 +332,7 @@ fi
332332

333333
# Always build against libedit instead of the default of readline.
334334
# macOS always uses the system libedit, so no tweaks are needed.
335-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
335+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
336336
# CPython 3.10 introduced proper configure support for libedit, so add configure
337337
# flag there.
338338
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_10}" ]; then
@@ -381,7 +381,7 @@ CONFIGURE_FLAGS="
381381
# this patch mildly conflicts with the macos-only patch-python-link-modules
382382
# applied above, so you will need to resolve that conflict if you re-enable
383383
# this for macos.
384-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
384+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
385385
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then
386386
patch -p1 -i "${ROOT}/patch-python-configure-add-enable-static-libpython-for-interpreter.patch"
387387
else
@@ -493,7 +493,7 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then
493493
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-python=${TOOLS_PATH}/host/bin/python${PYTHON_MAJMIN_VERSION}"
494494
fi
495495

496-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
496+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
497497
# Configure may detect libintl from non-system sources, such
498498
# as Homebrew or MacPorts. So nerf the check to prevent this.
499499
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_lib_intl_textdomain=no"
@@ -563,7 +563,7 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
563563
fi
564564

565565
# ptsrname_r is only available in SDK 13.4+, but we target a lower version for compatibility.
566-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
566+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
567567
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_ptsname_r=no"
568568
fi
569569

@@ -575,12 +575,12 @@ fi
575575

576576
# On 3.14+ `test_strftime_y2k` fails when cross-compiling for `x86_64_v2` and `x86_64_v3` targets on
577577
# Linux, so we ignore it. See https://github.com/python/cpython/issues/128104
578-
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" && -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
578+
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" && -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != macos* ]]; then
579579
export PROFILE_TASK='-m test --pgo --ignore test_strftime_y2k'
580580
fi
581581

582582
# We use ndbm on macOS and BerkeleyDB elsewhere.
583-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
583+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
584584
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-dbmliborder=ndbm"
585585
else
586586
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-dbmliborder=bdb"
@@ -608,7 +608,7 @@ if [ -n "${CROSS_COMPILING}" ]; then
608608
# python will end up with the time.tzset function or not. All linux targets,
609609
# however, should have a working tzset function via libc. So we manually
610610
# indicate this to the configure script.
611-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
611+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
612612
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_working_tzset=yes"
613613
fi
614614

@@ -660,7 +660,7 @@ fi
660660
# This ensures we can run the binary in any location without
661661
# LD_LIBRARY_PATH pointing to the directory containing libpython.
662662
if [ "${PYBUILD_SHARED}" = "1" ]; then
663-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
663+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
664664
# There's only 1 dylib produced on macOS and it has the binary suffix.
665665
LIBPYTHON_SHARED_LIBRARY_BASENAME=libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX}.dylib
666666
LIBPYTHON_SHARED_LIBRARY=${ROOT}/out/python/install/lib/${LIBPYTHON_SHARED_LIBRARY_BASENAME}
@@ -1143,7 +1143,7 @@ cp -av ${TOOLS_PATH}/deps/lib/*.a ${ROOT}/out/python/build/lib/
11431143
#
11441144
# We copy the libclang_rt.<platform>.a library from our clang into the
11451145
# distribution so it is available. See documentation in quirks.rst for more.
1146-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
1146+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
11471147
cp -av $(dirname $(which clang))/../lib/clang/*/lib/darwin/libclang_rt.osx.a ${ROOT}/out/python/build/lib/
11481148
fi
11491149

@@ -1158,7 +1158,7 @@ if [ -d "${TOOLS_PATH}/deps/lib/tcl8" ]; then
11581158
cp -av $source ${ROOT}/out/python/install/lib/
11591159
done
11601160

1161-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
1161+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
11621162
cp -av ${TOOLS_PATH}/deps/lib/Tix8.4.3 ${ROOT}/out/python/install/lib/
11631163
fi
11641164
fi

‎cpython-unix/build-main.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
import multiprocessing
88
import os
99
import pathlib
10-
import platform
1110
import subprocess
1211
import sys
1312

1413
from pythonbuild.cpython import meets_python_minimum_version
1514
from pythonbuild.downloads import DOWNLOADS
1615
from pythonbuild.utils import (
1716
compress_python_archive,
17+
current_host_platform,
18+
default_target_triple,
1819
get_target_settings,
1920
release_tag_from_git,
2021
supported_targets,
@@ -28,29 +29,14 @@
2829

2930

3031
def main():
31-
if sys.platform == "linux":
32-
host_platform = "linux64"
33-
default_target_triple = "x86_64-unknown-linux-gnu"
34-
elif sys.platform == "darwin":
35-
host_platform = "macos"
36-
machine = platform.machine()
37-
38-
if machine == "arm64":
39-
default_target_triple = "aarch64-apple-darwin"
40-
elif machine == "x86_64":
41-
default_target_triple = "x86_64-apple-darwin"
42-
else:
43-
raise Exception("unhandled macOS machine value: %s" % machine)
44-
else:
45-
print("Unsupported build platform: %s" % sys.platform)
46-
return 1
32+
host_platform = current_host_platform()
4733

4834
# Note these arguments must be synced with `build.py`
4935
parser = argparse.ArgumentParser()
5036

5137
parser.add_argument(
5238
"--target-triple",
53-
default=default_target_triple,
39+
default=default_target_triple(),
5440
choices=supported_targets(TARGETS_CONFIG),
5541
help="Target host triple to build for",
5642
)

‎cpython-unix/build-ncurses.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tar -xf ncurses-${NCURSES_VERSION}.tar.gz
1616
# ncurses version. Our workaround is to build ncurses for the host when
1717
# cross-compiling then make its `tic` available to the target ncurses
1818
# build.
19-
if [[ -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
19+
if [[ -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != macos* ]]; then
2020
echo "building host ncurses to provide modern tic for cross-compile"
2121

2222
pushd ncurses-${NCURSES_VERSION}
@@ -65,7 +65,7 @@ CONFIGURE_FLAGS="
6565
# ncurses wants --with-build-cc when cross-compiling. But it insists on CC
6666
# and this value not being equal, even though using the same binary with
6767
# different compiler flags is doable!
68-
if [[ -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
68+
if [[ -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != macos* ]]; then
6969
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-cc=$(which "${HOST_CC}")"
7070
fi
7171

@@ -91,7 +91,7 @@ fi
9191
# binary. So we provide a suitable runtime value and then move files at install
9292
# time.
9393

94-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
94+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
9595
CONFIGURE_FLAGS="${CONFIGURE_FLAGS}
9696
--datadir=/usr/share
9797
--sysconfdir=/etc

‎cpython-unix/build-tix.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if [ "${CC}" = "clang" ]; then
2828
CFLAGS="${CFLAGS} -Wno-error=implicit-function-declaration -Wno-error=incompatible-function-pointer-types"
2929
fi
3030

31-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
31+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
3232
CFLAGS="${CFLAGS} -I${TOOLS_PATH}/deps/include"
3333
EXTRA_CONFIGURE_FLAGS="--without-x"
3434
else

‎cpython-unix/build-tk.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pushd tk*/unix
1717
CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC"
1818
LDFLAGS="${EXTRA_TARGET_LDFLAGS}"
1919

20-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
20+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
2121
CFLAGS="${CFLAGS} -I${TOOLS_PATH}/deps/include -Wno-availability"
2222
CFLAGS="${CFLAGS} -Wno-deprecated-declarations -Wno-unknown-attributes -Wno-typedef-redefinition"
2323
LDFLAGS="-L${TOOLS_PATH}/deps/lib"
@@ -36,7 +36,7 @@ CFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure \
3636
${EXTRA_CONFIGURE_FLAGS}
3737

3838
# Remove wish, since we don't need it.
39-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
39+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
4040
sed -i 's/all: binaries libraries doc/all: libraries/' Makefile
4141
sed -i 's/install-binaries: $(TK_STUB_LIB_FILE) $(TK_LIB_FILE) ${WISH_EXE}/install-binaries: $(TK_STUB_LIB_FILE) $(TK_LIB_FILE)/' Makefile
4242
fi

‎cpython-unix/build.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def add_target_env(env, build_platform, target_triple, build_env):
116116
extra_host_cflags = []
117117
extra_host_ldflags = []
118118

119-
if build_platform == "linux64":
119+
if build_platform == "linux_x86_64":
120120
env["BUILD_TRIPLE"] = "x86_64-unknown-linux-gnu"
121121

122122
env["TARGET_TRIPLE"] = (
@@ -133,7 +133,7 @@ def add_target_env(env, build_platform, target_triple, build_env):
133133
):
134134
env["CROSS_COMPILING"] = "1"
135135

136-
if build_platform == "macos":
136+
if build_platform.startswith("macos_"):
137137
machine = platform.machine()
138138

139139
if machine == "arm64":
@@ -232,7 +232,7 @@ def toolchain_archive_path(package_name, host_platform):
232232

233233

234234
def install_binutils(platform):
235-
return platform != "macos"
235+
return not platform.startswith("macos_")
236236

237237

238238
def simple_build(
@@ -410,7 +410,7 @@ def build_tix(
410410
)
411411

412412
depends = {"tcl", "tk"}
413-
if host_platform != "macos":
413+
if not host_platform.startswith("macos_"):
414414
depends |= {"libX11", "xorgproto"}
415415

416416
for p in sorted(depends):
@@ -516,7 +516,7 @@ def python_build_info(
516516

517517
binary_suffix = ""
518518

519-
if platform == "linux64":
519+
if platform == "linux_x86_64":
520520
bi["core"]["static_lib"] = (
521521
"install/lib/python{version}/config-{version}{binary_suffix}-x86_64-linux-gnu/libpython{version}{binary_suffix}.a".format(
522522
version=version, binary_suffix=binary_suffix
@@ -539,7 +539,7 @@ def python_build_info(
539539
object_file_format = f"llvm-bitcode:%{llvm_version}"
540540
else:
541541
object_file_format = "elf"
542-
elif platform == "macos":
542+
elif platform.startswith("macos_"):
543543
bi["core"]["static_lib"] = (
544544
"install/lib/python{version}/config-{version}{binary_suffix}-darwin/libpython{version}{binary_suffix}.a".format(
545545
version=version, binary_suffix=binary_suffix
@@ -599,9 +599,12 @@ def python_build_info(
599599
if lib.startswith("-l"):
600600
lib = lib[2:]
601601

602-
if platform == "linux64" and lib not in linux_allowed_system_libraries:
602+
if platform == "linux_x86_64" and lib not in linux_allowed_system_libraries:
603603
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
604-
elif platform == "macos" and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
604+
elif (
605+
platform.startswith("macos_")
606+
and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES
607+
):
605608
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
606609

607610
log("adding core system link library: %s" % lib)
@@ -867,7 +870,7 @@ def build_cpython(
867870
extension_module_loading = ["builtin"]
868871
crt_features = []
869872

870-
if host_platform == "linux64":
873+
if host_platform == "linux_x86_64":
871874
if "static" in parsed_build_options:
872875
crt_features.append("static")
873876
else:
@@ -893,7 +896,7 @@ def build_cpython(
893896

894897
python_symbol_visibility = "global-default"
895898

896-
elif host_platform == "macos":
899+
elif host_platform.startswith("macos_"):
897900
python_symbol_visibility = "global-default"
898901
extension_module_loading.append("shared-library")
899902
crt_features.append("libSystem")
@@ -1238,7 +1241,7 @@ def main():
12381241

12391242
elif action == "tk":
12401243
extra_archives = {"tcl"}
1241-
if host_platform != "macos":
1244+
if not host_platform.startswith("macos_"):
12421245
extra_archives |= {
12431246
"libX11",
12441247
"libXau",

0 commit comments

Comments
 (0)