Skip to content

Commit c297200

Browse files
committed
unix: always build and use host Python when building 3.11
See inline comment. I'm running into a lot of pain with `_bootstrap_python` and `Programs/_freeze_module`. CPython's build system makes a lot of assumptions that certain modules / symbols won't be in the bootstrap Python. We invalidate that by statically linking everything. The path of least resistance is to build and use a host Python for freezing as it avoids building the half-complete binaries altogether.
1 parent 45ad84e commit c297200

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

cpython-unix/build-cpython.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ rm -rf pip-tmp
6565

6666
# If we are cross-compiling, we need to build a host Python to use during
6767
# the build.
68-
if [ -n "${CROSS_COMPILING}" ]; then
68+
#
69+
# We also build a host Python for 3.11+ to avoid complexity with building a
70+
# bootstrap Python during regular build.
71+
if [[ -n "${CROSS_COMPILING}" || -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]]; then
6972
pushd "Python-${PYTHON_VERSION}"
7073

7174
# Same patch as below. See comment there.
@@ -159,6 +162,14 @@ if [ "${CC}" = "clang" ]; then
159162
fi
160163
fi
161164

165+
# Python 3.11 supports using a provided Python to use during bootstrapping
166+
# (e.g. freezing). Normally it only uses this Python during cross-compiling.
167+
# This patch forces always using it. See comment related to
168+
# `--with-build-python` for more.
169+
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then
170+
patch -p1 -i ${ROOT}/patch-always-build-python-for-freeze.patch
171+
fi
172+
162173
# Add a make target to write the PYTHON_FOR_BUILD variable so we can
163174
# invoke the host Python on our own.
164175
patch -p1 -i ${ROOT}/patch-write-python-for-build.patch
@@ -347,6 +358,13 @@ if [ -n "${CPYTHON_LTO}" ]; then
347358
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-lto"
348359
fi
349360

361+
# Python 3.11 introduces a --with-build-python to denote the host Python.
362+
# It is required when cross-compiling. But we always build a host Python
363+
# to avoid complexity with the bootstrap Python binary.
364+
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then
365+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-python=${TOOLS_PATH}/pyhost/bin/python${PYTHON_MAJMIN_VERSION}"
366+
fi
367+
350368
if [ "${PYBUILD_PLATFORM}" = "macos" ]; then
351369
# Configure may detect libintl from non-system sources, such
352370
# as Homebrew or MacPorts. So nerf the check to prevent this.
@@ -429,11 +447,6 @@ else
429447
fi
430448

431449
if [ -n "${CROSS_COMPILING}" ]; then
432-
# Python 3.11 require a --with-build-python to denote the host Python.
433-
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then
434-
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --with-build-python=${TOOLS_PATH}/pyhost/bin/python${PYTHON_MAJMIN_VERSION}"
435-
fi
436-
437450
# configure doesn't like a handful of scenarios when cross-compiling.
438451
#
439452
# getaddrinfo buggy test fails for some reason. So we short-circuit it.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
diff --git a/configure.ac b/configure.ac
2+
index c62a565eb6..5a5a076f06 100644
3+
--- a/configure.ac
4+
+++ b/configure.ac
5+
@@ -178,24 +178,13 @@ AC_MSG_CHECKING([for Python interpreter freezing])
6+
AC_MSG_RESULT([$PYTHON_FOR_FREEZE])
7+
AC_SUBST([PYTHON_FOR_FREEZE])
8+
9+
-AS_VAR_IF([cross_compiling], [yes],
10+
- [
11+
- dnl external build Python, freezing depends on Programs/_freeze_module.py
12+
- FREEZE_MODULE_BOOTSTRAP='$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py'
13+
- FREEZE_MODULE_BOOTSTRAP_DEPS='$(srcdir)/Programs/_freeze_module.py'
14+
- FREEZE_MODULE='$(FREEZE_MODULE_BOOTSTRAP)'
15+
- FREEZE_MODULE_DEPS='$(FREEZE_MODULE_BOOTSTRAP_DEPS)'
16+
- PYTHON_FOR_BUILD_DEPS=''
17+
- ],
18+
- [
19+
- dnl internal build tools also depend on Programs/_freeze_module and _bootstrap_python.
20+
- FREEZE_MODULE_BOOTSTRAP='./Programs/_freeze_module'
21+
- FREEZE_MODULE_BOOTSTRAP_DEPS="Programs/_freeze_module"
22+
- FREEZE_MODULE='$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py'
23+
- FREEZE_MODULE_DEPS="_bootstrap_python \$(srcdir)/Programs/_freeze_module.py"
24+
- PYTHON_FOR_BUILD_DEPS='$(BUILDPYTHON)'
25+
- ]
26+
-)
27+
+dnl external build Python, freezing depends on Programs/_freeze_module.py
28+
+FREEZE_MODULE_BOOTSTRAP='$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py'
29+
+FREEZE_MODULE_BOOTSTRAP_DEPS='$(srcdir)/Programs/_freeze_module.py'
30+
+FREEZE_MODULE='$(FREEZE_MODULE_BOOTSTRAP)'
31+
+FREEZE_MODULE_DEPS='$(FREEZE_MODULE_BOOTSTRAP_DEPS)'
32+
+PYTHON_FOR_BUILD_DEPS=''
33+
+
34+
AC_SUBST([FREEZE_MODULE_BOOTSTRAP])
35+
AC_SUBST([FREEZE_MODULE_BOOTSTRAP_DEPS])
36+
AC_SUBST([FREEZE_MODULE])

0 commit comments

Comments
 (0)