Skip to content

Commit 612e59b

Browse files
authored
bpo-45950: Fix macOS framework builds of _bootstrap_python (GH-29936)
1 parent 98fac8b commit 612e59b

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

Makefile.pre.in

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,9 @@ BOOTSTRAP_HEADERS = \
954954

955955
Programs/_bootstrap_python.o: Programs/_bootstrap_python.c $(BOOTSTRAP_HEADERS) $(PYTHON_HEADERS)
956956

957-
_bootstrap_python: $(LIBRARY_OBJS_OMIT_FROZEN) Programs/_bootstrap_python.o Modules/getpath.o Modules/Setup.local
957+
_bootstrap_python: $(LIBRARY_OBJS_OMIT_FROZEN) Programs/_bootstrap_python.o Modules/getpath_bootstrap.o Modules/Setup.local
958958
$(LINKCC) $(PY_LDFLAGS_NOLTO) -o $@ $(LIBRARY_OBJS_OMIT_FROZEN) \
959-
Programs/_bootstrap_python.o Modules/getpath.o $(LIBS) $(MODLIBS) $(SYSLIBS)
959+
Programs/_bootstrap_python.o Modules/getpath_bootstrap.o $(LIBS) $(MODLIBS) $(SYSLIBS)
960960

961961
############################################################################
962962
# Deepfreeze targets
@@ -1205,6 +1205,18 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Python/frozen_modules/getpath.h M
12051205
-DPLATLIBDIR='"$(PLATLIBDIR)"' \
12061206
-o $@ $(srcdir)/Modules/getpath.c
12071207

1208+
# like getpath.o with additional -DPY_BOOTSTRAP_PYTHON=1
1209+
Modules/getpath_bootstrap.o: $(srcdir)/Modules/getpath.c Python/frozen_modules/getpath.h Makefile $(PYTHON_HEADERS)
1210+
$(CC) -c $(PY_CORE_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
1211+
-DPREFIX='"$(prefix)"' \
1212+
-DEXEC_PREFIX='"$(exec_prefix)"' \
1213+
-DVERSION='"$(VERSION)"' \
1214+
-DVPATH='"$(VPATH)"' \
1215+
-DPLATLIBDIR='"$(PLATLIBDIR)"' \
1216+
-DPY_BOOTSTRAP_PYTHON=1 \
1217+
-o $@ $(srcdir)/Modules/getpath.c
1218+
1219+
12081220
Programs/python.o: $(srcdir)/Programs/python.c
12091221
$(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Programs/python.c
12101222

Modules/getpath.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ library_to_dict(PyObject *dict, const char *key)
754754
if (PyWin_DLLhModule) {
755755
return winmodule_to_dict(dict, key, PyWin_DLLhModule);
756756
}
757-
#elif defined(WITH_NEXT_FRAMEWORK)
757+
#elif defined(WITH_NEXT_FRAMEWORK) && !defined(PY_BOOTSTRAP_PYTHON)
758+
// _bootstrap_python does not use framework and crashes
758759
static const char modPath[MAXPATHLEN + 1];
759760
static int modPathInitialized = -1;
760761
if (modPathInitialized < 0) {

configure

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ Optional Packages:
17361736
path to _freeze_module binary for cross compiling
17371737
--with-build-python=python3.11
17381738
path to build python binary for cross compiling
1739-
(default: python3.11)
1739+
(default: _bootstrap_python or python3.11)
17401740
--with-pkg-config=[yes|no|check]
17411741
use pkg-config to detect build options (default is
17421742
check)
@@ -3243,14 +3243,11 @@ if test "${with_build_python+set}" = set; then :
32433243
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-build-python" >&5
32443244
$as_echo_n "checking for --with-build-python... " >&6; }
32453245

3246-
if test "x$cross_compiling" = xno; then :
3247-
as_fn_error $? "--with-build-python only applies to cross compiling" "$LINENO" 5
3248-
fi
32493246
if test "x$with_build_python" = xyes; then :
32503247
with_build_python=python$PACKAGE_VERSION
32513248
fi
32523249
if test "x$with_build_python" = xno; then :
3253-
as_fn_error $? "invalid --with-build-python option: expected path, not \"no\"" "$LINENO" 5
3250+
as_fn_error $? "invalid --with-build-python option: expected path or \"yes\", not \"no\"" "$LINENO" 5
32543251
fi
32553252

32563253
if ! $(command -v "$with_build_python" >/dev/null 2>&1); then

configure.ac

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ AC_ARG_WITH(
125125
)
126126
AC_SUBST([FREEZE_MODULE])
127127

128+
dnl build-python is used for cross compiling and macOS framework builds.
128129
AC_ARG_WITH(
129130
[build-python],
130131
[AS_HELP_STRING([--with-build-python=python]PYTHON_VERSION,
131-
[path to build python binary for cross compiling (default: python]PYTHON_VERSION[)])],
132+
[path to build python binary for cross compiling (default: _bootstrap_python or python]PYTHON_VERSION[)])],
132133
[
133134
AC_MSG_CHECKING([for --with-build-python])
134135
135-
AS_VAR_IF([cross_compiling], [no], AC_MSG_ERROR([--with-build-python only applies to cross compiling]))
136136
AS_VAR_IF([with_build_python], [yes], [with_build_python=python$PACKAGE_VERSION])
137-
AS_VAR_IF([with_build_python], [no], [AC_MSG_ERROR([invalid --with-build-python option: expected path, not "no"])])
137+
AS_VAR_IF([with_build_python], [no], [AC_MSG_ERROR([invalid --with-build-python option: expected path or "yes", not "no"])])
138138
139139
if ! $(command -v "$with_build_python" >/dev/null 2>&1); then
140140
AC_MSG_ERROR([invalid or missing build python binary "$with_build_python"])

0 commit comments

Comments
 (0)