Skip to content

Commit cc92ada

Browse files
committed
Rework host platform naming
"host platform" is this concept I invented very early in the project to encode the build machine os and architecture. I chose "linux64" to represent Linux x86-64. And for reasons I can't recall, I never qualified the macOS architecture into the name like I did for Linux. This commit refactors the string so that it is consistently `os_arch`. `linux64` becomes `linux_x86_64`. `macos` becomes `macos_x86_64` and `macos_arm64`. I'm doing this cleanup in service of native ARM Linux builds. `linux64` is ambiguous. And macOS not behaving the same was always wonky. Let's impose some consistency instead of layering hacks upon hacks.
1 parent ae06f31 commit cc92ada

File tree

10 files changed

+113
-86
lines changed

10 files changed

+113
-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: 17 additions & 17 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
@@ -457,7 +457,7 @@ if [ -n "${CPYTHON_OPTIMIZED}" ]; then
457457

458458
# The JIT build is failing on macOS due to compiler errors
459459
# Only enable on Linux / 3.13 until that's fixed upstream
460-
if [[ "${PYBUILD_PLATFORM}" != "macos" ]]; then
460+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
461461
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-experimental-jit=yes-off"
462462
fi
463463

@@ -484,7 +484,7 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then
484484
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-python=${TOOLS_PATH}/host/bin/python${PYTHON_MAJMIN_VERSION}"
485485
fi
486486

487-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
487+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
488488
# Configure may detect libintl from non-system sources, such
489489
# as Homebrew or MacPorts. So nerf the check to prevent this.
490490
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_lib_intl_textdomain=no"
@@ -554,7 +554,7 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
554554
fi
555555

556556
# ptsrname_r is only available in SDK 13.4+, but we target a lower version for compatibility.
557-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
557+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
558558
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_ptsname_r=no"
559559
fi
560560

@@ -566,12 +566,12 @@ fi
566566

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

573573
# We use ndbm on macOS and BerkeleyDB elsewhere.
574-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
574+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
575575
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-dbmliborder=ndbm"
576576
else
577577
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-dbmliborder=bdb"
@@ -599,7 +599,7 @@ if [ -n "${CROSS_COMPILING}" ]; then
599599
# python will end up with the time.tzset function or not. All linux targets,
600600
# however, should have a working tzset function via libc. So we manually
601601
# indicate this to the configure script.
602-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
602+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
603603
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_working_tzset=yes"
604604
fi
605605

@@ -651,7 +651,7 @@ fi
651651
# This ensures we can run the binary in any location without
652652
# LD_LIBRARY_PATH pointing to the directory containing libpython.
653653
if [ "${PYBUILD_SHARED}" = "1" ]; then
654-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
654+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
655655
# There's only 1 dylib produced on macOS and it has the binary suffix.
656656
LIBPYTHON_SHARED_LIBRARY_BASENAME=libpython${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX}.dylib
657657
LIBPYTHON_SHARED_LIBRARY=${ROOT}/out/python/install/lib/${LIBPYTHON_SHARED_LIBRARY_BASENAME}
@@ -1134,7 +1134,7 @@ cp -av ${TOOLS_PATH}/deps/lib/*.a ${ROOT}/out/python/build/lib/
11341134
#
11351135
# We copy the libclang_rt.<platform>.a library from our clang into the
11361136
# distribution so it is available. See documentation in quirks.rst for more.
1137-
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
1137+
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
11381138
cp -av $(dirname $(which clang))/../lib/clang/*/lib/darwin/libclang_rt.osx.a ${ROOT}/out/python/build/lib/
11391139
fi
11401140

@@ -1149,7 +1149,7 @@ if [ -d "${TOOLS_PATH}/deps/lib/tcl8" ]; then
11491149
cp -av $source ${ROOT}/out/python/install/lib/
11501150
done
11511151

1152-
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
1152+
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
11531153
cp -av ${TOOLS_PATH}/deps/lib/Tix8.4.3 ${ROOT}/out/python/install/lib/
11541154
fi
11551155
fi

cpython-unix/build-main.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from pythonbuild.downloads import DOWNLOADS
1616
from pythonbuild.utils import (
1717
compress_python_archive,
18+
current_host_platform,
19+
default_target_triple,
1820
get_target_settings,
1921
release_tag_from_git,
2022
supported_targets,
@@ -28,29 +30,14 @@
2830

2931

3032
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
33+
host_platform = current_host_platform()
4734

4835
# Note these arguments must be synced with `build.py`
4936
parser = argparse.ArgumentParser()
5037

5138
parser.add_argument(
5239
"--target-triple",
53-
default=default_target_triple,
40+
default=default_target_triple(),
5441
choices=supported_targets(TARGETS_CONFIG),
5542
help="Target host triple to build for",
5643
)

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: 11 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,9 @@ 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 platform.startswith("macos_") and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
605605
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
606606

607607
log("adding core system link library: %s" % lib)
@@ -867,7 +867,7 @@ def build_cpython(
867867
extension_module_loading = ["builtin"]
868868
crt_features = []
869869

870-
if host_platform == "linux64":
870+
if host_platform == "linux_x86_64":
871871
if "static" in parsed_build_options:
872872
crt_features.append("static")
873873
else:
@@ -893,7 +893,7 @@ def build_cpython(
893893

894894
python_symbol_visibility = "global-default"
895895

896-
elif host_platform == "macos":
896+
elif host_platform.startswith("macos_"):
897897
python_symbol_visibility = "global-default"
898898
extension_module_loading.append("shared-library")
899899
crt_features.append("libSystem")
@@ -1246,7 +1246,7 @@ def main():
12461246

12471247
elif action == "tk":
12481248
extra_archives = {"tcl"}
1249-
if host_platform != "macos":
1249+
if not host_platform.startswith("macos_"):
12501250
extra_archives |= {
12511251
"libX11",
12521252
"libXau",

0 commit comments

Comments
 (0)