Skip to content

Commit bc620d6

Browse files
committed
unix: parameterize the name of the host compiler
Let's define the name of the host's C compiler in our YAML config file and make it available as an environment variable in builds. This makes the code in build scripts simpler, as it doesn't have to sniff the triple or know much about the environment.
1 parent 7a0c31d commit bc620d6

File tree

5 files changed

+27
-51
lines changed

5 files changed

+27
-51
lines changed

cpython-unix/build-cpython.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ tar -xf pip-${PIP_VERSION}.tar.gz
2828
if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
2929
pushd "Python-${PYTHON_VERSION}"
3030

31-
OLD_CC=${CC}
32-
unset CC
33-
3431
# When cross-compiling, we need to build a host Python that has working zlib
3532
# and ctypes extensions, otherwise various things fail. (`make install` fails
3633
# without zlib and setuptools / pip used by target install fail due to missing
@@ -53,7 +50,7 @@ if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
5350
;;
5451
esac
5552

56-
CFLAGS="${EXTRA_HOST_CFLAGS}" CPPFLAGS="${EXTRA_HOST_CFLAGS}" LDFLAGS="${EXTRA_HOST_LDFLAGS}" ./configure --prefix "${TOOLS_PATH}/pyhost"
53+
CC="${HOST_CC}" CFLAGS="${EXTRA_HOST_CFLAGS}" CPPFLAGS="${EXTRA_HOST_CFLAGS}" LDFLAGS="${EXTRA_HOST_LDFLAGS}" ./configure --prefix "${TOOLS_PATH}/pyhost"
5754

5855
# When building on macOS 10.15 (and possibly earlier) using the 11.0
5956
# SDK, the _ctypes extension fails to import due to a missing symbol on
@@ -73,8 +70,6 @@ if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
7370
# at the front of PATH.
7471
export PATH="${TOOLS_PATH}/pyhost/bin:${PATH}"
7572

76-
export CC="${OLD_CC}"
77-
7873
popd
7974
# Nuke and re-pave the source directory out of paranoia.
8075
rm -rf "Python-${PYTHON_VERSION}"

cpython-unix/build-libX11.sh

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,39 +75,12 @@ if [ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" ]; then
7575
esac
7676
fi
7777

78-
case "${TARGET_TRIPLE}" in
79-
aarch64-unknown-linux-gnu)
80-
CC_FOR_BUILD=gcc
81-
;;
82-
armv7-unknown-linux-gnueabi)
83-
CC_FOR_BUILD=gcc
84-
;;
85-
armv7-unknown-linux-gnueabihf)
86-
CC_FOR_BUILD=gcc
87-
;;
88-
mips-unknown-linux-gnu)
89-
CC_FOR_BUILD=gcc
90-
;;
91-
mipsel-unknown-linux-gnu)
92-
CC_FOR_BUILD=gcc
93-
;;
94-
mips64el-unknown-linux-gnuabi64)
95-
CC_FOR_BUILD=gcc
96-
;;
97-
s390x-unknown-linux-gnu)
98-
CC_FOR_BUILD=gcc
99-
;;
100-
*)
101-
CC_FOR_BUILD=clang
102-
;;
103-
esac
104-
10578
# CC_FOR_BUILD is here because configure doesn't look for `clang` when
10679
# cross-compiling. So we force it.
10780
CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC -I/tools/deps/include" \
10881
CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC -I/tools/deps/include" \
10982
LDFLAGS="${EXTRA_TARGET_LDFLAGS}" \
110-
CC_FOR_BUILD="${CC_FOR_BUILD}" \
83+
CC_FOR_BUILD="${HOST_CC}" \
11184
CFLAGS_FOR_BUILD="-I/tools/deps/include" \
11285
CPPFLAGS_FOR_BUILD="-I/tools/deps/include" \
11386
./configure \

cpython-unix/build-ncurses.sh

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,11 @@ tar -xf ncurses-${NCURSES_VERSION}.tar.gz
1919
if [[ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
2020
echo "building host ncurses to provide modern tic for cross-compile"
2121

22-
OLD_CC=${CC}
23-
unset CC
24-
25-
if [ -e "${TOOLS_PATH}/${TOOLCHAIN}/bin/clang" ]; then
26-
export CC="${TOOLS_PATH}/${TOOLCHAIN}/bin/clang"
27-
fi
28-
2922
pushd ncurses-${NCURSES_VERSION}
30-
./configure --prefix=${TOOLS_PATH}/host --without-cxx --without-tests --without-manpages --enable-widec
23+
CC="${HOST_CC}" ./configure --prefix=${TOOLS_PATH}/host --without-cxx --without-tests --without-manpages --enable-widec
3124
make -j ${NUM_CPUS}
3225
make -j ${NUM_CPUS} install
3326

34-
export CC=${OLD_CC}
35-
3627
popd
3728

3829
# Nuke and re-pave the source directory.
@@ -61,13 +52,7 @@ CONFIGURE_FLAGS="
6152
# and this value not being equal, even though using the same binary with
6253
# different compiler flags is doable!
6354
if [[ "${BUILD_TRIPLE}" != "${TARGET_TRIPLE}" && "${PYBUILD_PLATFORM}" != "macos" ]]; then
64-
# Look for and use our Clang toolchain by default. If not present, fall
65-
# back to likely path to system GCC.
66-
if [ -e "${TOOLS_PATH}/${TOOLCHAIN}/bin/clang" ]; then
67-
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-cc=${TOOLS_PATH}/${TOOLCHAIN}/bin/clang"
68-
else
69-
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-cc=/usr/bin/x86_64-linux-gnu-gcc"
70-
fi
55+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-cc=$(which "${HOST_CC}")"
7156
fi
7257

7358
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then

cpython-unix/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def add_target_env(env, build_platform, target_triple, build_env):
8989

9090
settings = get_target_settings(TARGETS_CONFIG, target_triple)
9191

92+
env["HOST_CC"] = settings["host_cc"]
93+
9294
if settings.get("needs_toolchain"):
9395
if "musl" in target_triple:
9496
env["CC"] = "musl-clang"

cpython-unix/targets.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
# needs
1313
# Packages required to build Python.
1414
#
15+
# host_cc
16+
# Path to C compiler to use when producing binaries targeting the
17+
# current build environment.
18+
#
1519
# openssl_target
1620
# Name of OpenSSL platform build target.
1721

@@ -20,6 +24,7 @@ aarch64-apple-darwin:
2024
host_platforms:
2125
- darwin
2226
needs_toolchain: true
27+
host_cc: clang
2328
needs:
2429
- bzip2
2530
- libedit
@@ -38,6 +43,7 @@ aarch64-apple-ios:
3843
host_platforms:
3944
- darwin
4045
needs_toolchain: true
46+
host_cc: clang
4147
needs:
4248
- bzip2
4349
- libffi
@@ -50,6 +56,7 @@ aarch64-unknown-linux-gnu:
5056
host_platforms:
5157
- linux
5258
docker_image_suffix: .cross
59+
host_cc: /usr/bin/x86_64-linux-gnu-gcc
5360
needs:
5461
- bdb
5562
- binutils
@@ -76,6 +83,7 @@ arm64-apple-tvos:
7683
host_platforms:
7784
- darwin
7885
needs_toolchain: true
86+
host_cc: clang
7987
needs:
8088
- bzip2
8189
- sqlite
@@ -87,6 +95,7 @@ armv7-unknown-linux-gnueabi:
8795
host_platforms:
8896
- linux
8997
docker_image_suffix: .cross
98+
host_cc: /usr/bin/x86_64-linux-gnu-gcc
9099
needs:
91100
- bdb
92101
- binutils
@@ -113,6 +122,7 @@ armv7-unknown-linux-gnueabihf:
113122
host_platforms:
114123
- linux
115124
docker_image_suffix: .cross
125+
host_cc: /usr/bin/x86_64-linux-gnu-gcc
116126
needs:
117127
- bdb
118128
- binutils
@@ -139,6 +149,7 @@ i686-unknown-linux-gnu:
139149
host_platforms:
140150
- linux
141151
needs_toolchain: true
152+
host_cc: clang
142153
needs:
143154
- bdb
144155
- binutils
@@ -167,6 +178,7 @@ mips-unknown-linux-gnu:
167178
host_platforms:
168179
- linux
169180
docker_image_suffix: .cross
181+
host_cc: /usr/bin/x86_64-linux-gnu-gcc
170182
needs:
171183
- bdb
172184
- binutils
@@ -193,6 +205,7 @@ mipsel-unknown-linux-gnu:
193205
host_platforms:
194206
- linux
195207
docker_image_suffix: .cross
208+
host_cc: /usr/bin/x86_64-linux-gnu-gcc
196209
needs:
197210
- bdb
198211
- binutils
@@ -219,6 +232,7 @@ s390x-unknown-linux-gnu:
219232
host_platforms:
220233
- linux
221234
docker_image_suffix: .cross
235+
host_cc: /usr/bin/x86_64-linux-gnu-gcc
222236
needs:
223237
- bdb
224238
- binutils
@@ -245,6 +259,7 @@ thumb7k-apple-watchos:
245259
host_platforms:
246260
- darwin
247261
needs_toolchain: true
262+
host_cc: clang
248263
needs:
249264
- bzip2
250265
- sqlite
@@ -255,6 +270,7 @@ thumb7k-apple-watchos:
255270
x86_64-apple-darwin:
256271
host_platforms:
257272
- darwin
273+
host_cc: clang
258274
needs:
259275
- bzip2
260276
- libedit
@@ -273,6 +289,7 @@ x86_64-apple-ios:
273289
host_platforms:
274290
- darwin
275291
needs_toolchain: true
292+
host_cc: clang
276293
needs:
277294
- bzip2
278295
- libffi
@@ -285,6 +302,7 @@ x86_64-apple-tvos:
285302
host_platforms:
286303
- darwin
287304
needs_toolchain: true
305+
host_cc: clang
288306
needs:
289307
- bzip2
290308
- sqlite
@@ -295,6 +313,7 @@ x86_64-apple-watchos:
295313
host_platforms:
296314
- darwin
297315
needs_toolchain: true
316+
host_cc: clang
298317
needs:
299318
- bzip2
300319
- sqlite
@@ -306,6 +325,7 @@ x86_64-unknown-linux-gnu:
306325
host_platforms:
307326
- linux
308327
needs_toolchain: true
328+
host_cc: clang
309329
needs:
310330
- bdb
311331
- binutils
@@ -333,6 +353,7 @@ x86_64-unknown-linux-musl:
333353
host_platforms:
334354
- linux
335355
needs_toolchain: true
356+
host_cc: clang
336357
needs:
337358
- bdb
338359
- binutils

0 commit comments

Comments
 (0)