Skip to content

Commit 8c6a024

Browse files
committed
unix: define and use CROSS_COMPILING environment variable
This will help pave the road for x86-64 triple variants.
1 parent 58a38b4 commit 8c6a024

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

cpython-unix/build-cpython.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ rm -rf pip-tmp
6262

6363
# If we are cross-compiling, we need to build a host Python to use during
6464
# the build.
65-
if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
65+
if [ -n "${CROSS_COMPILING}" ]; then
6666
pushd "Python-${PYTHON_VERSION}"
6767

6868
# Same patch as below. See comment there.
@@ -312,7 +312,7 @@ fi
312312

313313
# Configure nerfs RUNSHARED when cross-compiling, which prevents i386 PGO from
314314
# running from an x86_64 environment. Undo that, as we can run i386 from x86_64.
315-
if [[ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" && "${TARGET_TRIPLE}" = "i686-unknown-linux-gnu" ]]; then
315+
if [[ -n "${CROSS_COMPILING}" && "${TARGET_TRIPLE}" = "i686-unknown-linux-gnu" ]]; then
316316
patch -p1 << "EOF"
317317
diff --git a/configure b/configure
318318
index 1252335472..33c11fbade 100755
@@ -719,7 +719,7 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
719719
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_func_pwritev=no"
720720
fi
721721

722-
if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
722+
if [ -n "${CROSS_COMPILING}" ]; then
723723
# Python's configure doesn't support cross-compiling on macOS. So we need
724724
# to explicitly set MACHDEP to avoid busted checks. The code for setting
725725
# MACHDEP also sets ac_sys_system/ac_sys_release, so we have to set
@@ -764,7 +764,7 @@ if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
764764
export MACOSX_DEPLOYMENT_TARGET="${APPLE_MIN_DEPLOYMENT_TARGET}"
765765
fi
766766

767-
if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
767+
if [ -n "${CROSS_COMPILING}" ]; then
768768
# configure doesn't like a handful of scenarios when cross-compiling.
769769
#
770770
# getaddrinfo buggy test fails for some reason. So we short-circuit it.
@@ -851,7 +851,7 @@ fi
851851
# we have the Makefile emit a script which sets some environment
852852
# variables that force the invoked Python to pick up the configuration
853853
# of the target Python but invoke the host binary.
854-
if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
854+
if [ -n "${CROSS_COMPILING}" ]; then
855855
make write-python-for-build
856856
BUILD_PYTHON=$(pwd)/python-for-build
857857
else

cpython-unix/build-libX11.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fi
4343

4444
# configure doesn't support cross-compiling in malloc(0) returns null test.
4545
# So we have to force a value.
46-
if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
46+
if [ -n "${CROSS_COMPILING}" ]; then
4747
case "${TARGET_TRIPLE}" in
4848
aarch64-unknown-linux-gnu)
4949
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"

cpython-unix/build-ncurses.sh

Lines changed: 2 additions & 2 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 [[ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" && "${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}
@@ -51,7 +51,7 @@ CONFIGURE_FLAGS="
5151
# ncurses wants --with-build-cc when cross-compiling. But it insists on CC
5252
# and this value not being equal, even though using the same binary with
5353
# different compiler flags is doable!
54-
if [[ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
54+
if [[ -n "${CROSS_COMPILING}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
5555
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-cc=$(which "${HOST_CC}")"
5656
fi
5757

cpython-unix/build.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ def add_target_env(env, build_platform, target_triple, build_env):
9999
env["BUILD_TRIPLE"] = "x86_64-unknown-linux-gnu"
100100

101101
# TODO should the musl target be normalized?
102-
if target_triple == "x86_64-unknown-linux-musl":
103-
env["TARGET_TRIPLE"] = "x86_64-unknown-linux-gnu"
104-
else:
105-
env["TARGET_TRIPLE"] = target_triple
102+
env["TARGET_TRIPLE"] = target_triple.replace(
103+
"-unknown-linux-musl", "-unknown-linux-gnu"
104+
)
105+
106+
if env["BUILD_TRIPLE"] != target_triple or target_triple.endswith(
107+
"-unknown-linux-musl"
108+
):
109+
env["CROSS_COMPILING"] = "1"
106110

107111
if build_platform == "macos":
108112
machine = platform.machine()
@@ -130,6 +134,9 @@ def add_target_env(env, build_platform, target_triple, build_env):
130134

131135
env["TARGET_TRIPLE"] = target_triple
132136

137+
if env["BUILD_TRIPLE"] != env["TARGET_TRIPLE"]:
138+
env["CROSS_COMPILING"] = "1"
139+
133140
# We don't have build isolation on macOS. We nerf PATH to prevent
134141
# non-system (e.g. Homebrew) executables from being used.
135142
env["PATH"] = "/usr/bin:/bin"

0 commit comments

Comments
 (0)