Skip to content

Rework host platform naming #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpython-unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ $(OUTDIR)/$(CLANG_FILENAME):
$(OUTDIR)/musl-$(MUSL_VERSION)-$(HOST_PLATFORM).tar: $(BASE_TOOLCHAIN_DEPENDS) $(HERE)/build-musl.sh
$(RUN_BUILD) --toolchain musl

ifeq ($(HOST_PLATFORM),linux64)
ifeq ($(HOST_PLATFORM),linux_x86_64)
TOOLCHAIN_TARGET := $(OUTDIR)/musl-$(MUSL_VERSION)-$(HOST_PLATFORM).tar
else
TOOLCHAIN_TARGET :=
Expand Down
2 changes: 1 addition & 1 deletion cpython-unix/build-cpython-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export trailer_m4=${TOOLS_PATH}/host/share/autoconf/autoconf/trailer.m4

# The share/autoconf/autom4te.cfg file also hard-codes some paths. Rewrite
# those to the real tools path.
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
sed_args="-i '' -e"
else
sed_args="-i"
Expand Down
32 changes: 16 additions & 16 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export trailer_m4=${TOOLS_PATH}/host/share/autoconf/autoconf/trailer.m4

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

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

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

EXTRA_CONFIGURE_FLAGS=

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

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

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

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

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

Expand All @@ -575,12 +575,12 @@ fi

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

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

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

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

if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
cp -av ${TOOLS_PATH}/deps/lib/Tix8.4.3 ${ROOT}/out/python/install/lib/
fi
fi
Expand Down
22 changes: 4 additions & 18 deletions cpython-unix/build-main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import multiprocessing
import os
import pathlib
import platform
import subprocess
import sys

from pythonbuild.cpython import meets_python_minimum_version
from pythonbuild.downloads import DOWNLOADS
from pythonbuild.utils import (
compress_python_archive,
current_host_platform,
default_target_triple,
get_target_settings,
release_tag_from_git,
supported_targets,
Expand All @@ -28,29 +29,14 @@


def main():
if sys.platform == "linux":
host_platform = "linux64"
default_target_triple = "x86_64-unknown-linux-gnu"
elif sys.platform == "darwin":
host_platform = "macos"
machine = platform.machine()

if machine == "arm64":
default_target_triple = "aarch64-apple-darwin"
elif machine == "x86_64":
default_target_triple = "x86_64-apple-darwin"
else:
raise Exception("unhandled macOS machine value: %s" % machine)
else:
print("Unsupported build platform: %s" % sys.platform)
return 1
host_platform = current_host_platform()

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

parser.add_argument(
"--target-triple",
default=default_target_triple,
default=default_target_triple(),
choices=supported_targets(TARGETS_CONFIG),
help="Target host triple to build for",
)
Expand Down
6 changes: 3 additions & 3 deletions cpython-unix/build-ncurses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tar -xf ncurses-${NCURSES_VERSION}.tar.gz
# ncurses version. Our workaround is to build ncurses for the host when
# cross-compiling then make its `tic` available to the target ncurses
# build.
if [[ -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
if [[ -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != macos* ]]; then
echo "building host ncurses to provide modern tic for cross-compile"

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

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

if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
CONFIGURE_FLAGS="${CONFIGURE_FLAGS}
--datadir=/usr/share
--sysconfdir=/etc
Expand Down
2 changes: 1 addition & 1 deletion cpython-unix/build-tix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if [ "${CC}" = "clang" ]; then
CFLAGS="${CFLAGS} -Wno-error=implicit-function-declaration -Wno-error=incompatible-function-pointer-types"
fi

if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
CFLAGS="${CFLAGS} -I${TOOLS_PATH}/deps/include"
EXTRA_CONFIGURE_FLAGS="--without-x"
else
Expand Down
4 changes: 2 additions & 2 deletions cpython-unix/build-tk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pushd tk*/unix
CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC"
LDFLAGS="${EXTRA_TARGET_LDFLAGS}"

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

# Remove wish, since we don't need it.
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
sed -i 's/all: binaries libraries doc/all: libraries/' Makefile
sed -i 's/install-binaries: $(TK_STUB_LIB_FILE) $(TK_LIB_FILE) ${WISH_EXE}/install-binaries: $(TK_STUB_LIB_FILE) $(TK_LIB_FILE)/' Makefile
fi
Expand Down
25 changes: 14 additions & 11 deletions cpython-unix/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def add_target_env(env, build_platform, target_triple, build_env):
extra_host_cflags = []
extra_host_ldflags = []

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

env["TARGET_TRIPLE"] = (
Expand All @@ -133,7 +133,7 @@ def add_target_env(env, build_platform, target_triple, build_env):
):
env["CROSS_COMPILING"] = "1"

if build_platform == "macos":
if build_platform.startswith("macos_"):
machine = platform.machine()

if machine == "arm64":
Expand Down Expand Up @@ -232,7 +232,7 @@ def toolchain_archive_path(package_name, host_platform):


def install_binutils(platform):
return platform != "macos"
return not platform.startswith("macos_")


def simple_build(
Expand Down Expand Up @@ -410,7 +410,7 @@ def build_tix(
)

depends = {"tcl", "tk"}
if host_platform != "macos":
if not host_platform.startswith("macos_"):
depends |= {"libX11", "xorgproto"}

for p in sorted(depends):
Expand Down Expand Up @@ -516,7 +516,7 @@ def python_build_info(

binary_suffix = ""

if platform == "linux64":
if platform == "linux_x86_64":
bi["core"]["static_lib"] = (
"install/lib/python{version}/config-{version}{binary_suffix}-x86_64-linux-gnu/libpython{version}{binary_suffix}.a".format(
version=version, binary_suffix=binary_suffix
Expand All @@ -539,7 +539,7 @@ def python_build_info(
object_file_format = f"llvm-bitcode:%{llvm_version}"
else:
object_file_format = "elf"
elif platform == "macos":
elif platform.startswith("macos_"):
bi["core"]["static_lib"] = (
"install/lib/python{version}/config-{version}{binary_suffix}-darwin/libpython{version}{binary_suffix}.a".format(
version=version, binary_suffix=binary_suffix
Expand Down Expand Up @@ -599,9 +599,12 @@ def python_build_info(
if lib.startswith("-l"):
lib = lib[2:]

if platform == "linux64" and lib not in linux_allowed_system_libraries:
if platform == "linux_x86_64" and lib not in linux_allowed_system_libraries:
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))
elif platform == "macos" and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES:
elif (
platform.startswith("macos_")
and lib not in MACOS_ALLOW_SYSTEM_LIBRARIES
):
raise Exception("unexpected library in LIBS (%s): %s" % (libs, lib))

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

if host_platform == "linux64":
if host_platform == "linux_x86_64":
if "static" in parsed_build_options:
crt_features.append("static")
else:
Expand All @@ -893,7 +896,7 @@ def build_cpython(

python_symbol_visibility = "global-default"

elif host_platform == "macos":
elif host_platform.startswith("macos_"):
python_symbol_visibility = "global-default"
extension_module_loading.append("shared-library")
crt_features.append("libSystem")
Expand Down Expand Up @@ -1238,7 +1241,7 @@ def main():

elif action == "tk":
extra_archives = {"tcl"}
if host_platform != "macos":
if not host_platform.startswith("macos_"):
extra_archives |= {
"libX11",
"libXau",
Expand Down
Loading