-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before, we built a host CPython inside build-cpython.sh for build configurations that required it. This commit extracts the host CPython build to its own build script and make target. The impetus for this is that iterating on changes to the main CPython build script is slow due to having to recompile the host CPython all the time. I've been wanting to make this change for a while to speed up that common development workflow. As part of this refactor we now sometimes compile the host CPython when we don't need to. But since we always the host CPython for 3.11+, eventually that waste is reduced to 0. So I'm fine with the overhead.
- Loading branch information
Showing
4 changed files
with
178 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env bash | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
set -ex | ||
|
||
export ROOT=`pwd` | ||
|
||
export PATH=${TOOLS_PATH}/${TOOLCHAIN}/bin:${TOOLS_PATH}/host/bin:${TOOLS_PATH}/deps/bin:$PATH | ||
|
||
# autoconf has some paths hardcoded into scripts. These paths just work in | ||
# the containerized build environment. But from macOS the paths are wrong. | ||
# Explicitly point to the proper path via environment variable overrides. | ||
export AUTOCONF=${TOOLS_PATH}/host/bin/autoconf | ||
export AUTOHEADER=${TOOLS_PATH}/host/bin/autoheader | ||
export AUTOM4TE=${TOOLS_PATH}/host/bin/autom4te | ||
export autom4te_perllibdir=${TOOLS_PATH}/host/share/autoconf | ||
export AC_MACRODIR=${TOOLS_PATH}/host/share/autoconf | ||
export M4=${TOOLS_PATH}/host/bin/m4 | ||
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 | ||
sed_args="-i '' -e" | ||
else | ||
sed_args="-i" | ||
fi | ||
|
||
sed ${sed_args} "s|/tools/host|${TOOLS_PATH}/host|g" ${TOOLS_PATH}/host/share/autoconf/autom4te.cfg | ||
|
||
tar -xf Python-${PYTHON_VERSION}.tar.xz | ||
|
||
pushd "Python-${PYTHON_VERSION}" | ||
|
||
# Clang 13 actually prints something with --print-multiarch, confusing CPython's | ||
# configure. This is reported as https://bugs.python.org/issue45405. We nerf the | ||
# check since we know what we're doing. | ||
if [ "${CC}" = "clang" ]; then | ||
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_9}" ]; then | ||
patch -p1 -i ${ROOT}/patch-disable-multiarch.patch | ||
else | ||
patch -p1 -i ${ROOT}/patch-disable-multiarch-legacy.patch | ||
fi | ||
fi | ||
|
||
autoconf | ||
|
||
# When cross-compiling, we need to build a host Python that has working zlib | ||
# and ctypes extensions, otherwise various things fail. (`make install` fails | ||
# without zlib and setuptools / pip used by target install fail due to missing | ||
# ctypes.) | ||
# | ||
# On Apple, the dependencies are present in the Apple SDK and missing extensions | ||
# are built properly by setup.py. However, on other platforms, we need to teach | ||
# the host build system where to find things. | ||
# | ||
# Adding /usr paths on Linux is a bit funky. This is a side-effect or our | ||
# custom Clang purposefully omitting default system search paths to help | ||
# prevent unwanted dependencies from sneaking in. | ||
case "${BUILD_TRIPLE}" in | ||
x86_64-unknown-linux-gnu) | ||
EXTRA_HOST_CFLAGS="${EXTRA_HOST_CFLAGS} -I/usr/include/x86_64-linux-gnu" | ||
EXTRA_HOST_CPPFLAGS="${EXTRA_HOST_CPPFLAGS} -I/usr/include/x86_64-linux-gnu" | ||
EXTRA_HOST_LDFLAGS="${EXTRA_HOST_LDFLAGS} -L/usr/lib/x86_64-linux-gnu" | ||
;; | ||
*) | ||
;; | ||
esac | ||
|
||
CC="${HOST_CC}" CXX="${HOST_CXX}" CFLAGS="${EXTRA_HOST_CFLAGS}" CPPFLAGS="${EXTRA_HOST_CFLAGS}" LDFLAGS="${EXTRA_HOST_LDFLAGS}" ./configure \ | ||
--prefix /tools/host \ | ||
--without-ensurepip | ||
|
||
make -j "${NUM_CPUS}" install DESTDIR=${ROOT}/out | ||
|
||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters