@@ -58,6 +58,13 @@ cat Makefile.extra
5858
5959pushd " Python-${PYTHON_VERSION} "
6060
61+ # PYSTANDALONE: extract pystandalone tar, copy source and apply patches
62+ tar -xf ${ROOT} /pystandalone.tar -C ${ROOT}
63+ cp -a ${ROOT} /pystandalone/src/. .
64+ for file in ${ROOT} /pystandalone/patch/* .patch; do
65+ patch -p1 -i $file
66+ done
67+
6168# configure doesn't support cross-compiling on Apple. Teach it.
6269if [[ " ${PYBUILD_PLATFORM} " = macos* && -n " ${PYTHON_MEETS_MAXIMUM_VERSION_3_13} " ]]; then
6370 if [ " ${PYTHON_MAJMIN_VERSION} " = " 3.12" ]; then
151158# linked modules. But those libraries should only get linked into libpython, not the
152159# executable. This behavior is kinda suspect on all platforms, as it could be adding
153160# library dependencies that shouldn't need to be there.
154- if [[ " ${PYBUILD_PLATFORM} " = macos* ]]; then
155- if [ -n " ${PYTHON_MEETS_MINIMUM_VERSION_3_15} " ]; then
156- patch -p1 -i " ${ROOT} /patch-python-link-modules-3.15.patch"
157- elif [ -n " ${PYTHON_MEETS_MINIMUM_VERSION_3_11} " ]; then
158- patch -p1 -i " ${ROOT} /patch-python-link-modules-3.11.patch"
159- elif [ " ${PYTHON_MAJMIN_VERSION} " = " 3.10" ]; then
160- patch -p1 -i " ${ROOT} /patch-python-link-modules-3.10.patch"
161- fi
162- fi
161+ # PYSTANDALONE: skip this patch.
163162
164163# The macOS code for sniffing for _dyld_shared_cache_contains_path falls back on a
165164# possibly inappropriate code path if a configure time check fails. This is not
@@ -342,7 +341,8 @@ if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
342341 LDFLAGS=" ${LDFLAGS} -Wl,--exclude-libs,ALL"
343342fi
344343
345- EXTRA_CONFIGURE_FLAGS=
344+ # PYSTANDALONE: additional configure flags
345+ EXTRA_CONFIGURE_FLAGS=" --without-doc-strings"
346346
347347if [[ " ${PYBUILD_PLATFORM} " = macos* ]]; then
348348 CFLAGS=" ${CFLAGS} -I${TOOLS_PATH} /deps/include/uuid"
@@ -389,6 +389,15 @@ if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
389389 LDFLAGS=" ${LDFLAGS} -Wl,-headerpad,40"
390390fi
391391
392+ # PYSTANDALONE: move the static mapping to a different base offset that's rare.
393+ # This is useful for when we need to manually map an ELF, we need to avoid
394+ # address conflicts with the executable we're mapping from.
395+ # Also add a custom loading script to the default script to move our
396+ # our payload section to the end of the binary.
397+ if [[ " ${PYBUILD_PLATFORM} " != macos* ]]; then
398+ LDFLAGS=" ${LDFLAGS} -Wl,-Ttext-segment=0x1000000,-Tpystandalone.ld"
399+ fi
400+
392401CPPFLAGS=$CFLAGS
393402
394403CONFIGURE_FLAGS="
@@ -454,12 +463,17 @@ if [ -n "${CPYTHON_STATIC}" ]; then
454463 CFLAGS=" ${CFLAGS} -static"
455464 CPPFLAGS=" ${CPPFLAGS} -static"
456465 LDFLAGS=" ${LDFLAGS} -static"
457- PYBUILD_SHARED=0
466+ PYBUILD_SHARED=0
458467else
459468 CONFIGURE_FLAGS=" ${CONFIGURE_FLAGS} --enable-shared"
460469 PYBUILD_SHARED=1
461470fi
462471
472+ if [[ " ${PYBUILD_PLATFORM} " = macos* ]]; then
473+ # PYSTANDALONE: we can't build completely statically on macOS, but at least disable shared building
474+ PYBUILD_SHARED=0
475+ fi
476+
463477if [ -n " ${CPYTHON_DEBUG} " ]; then
464478 CONFIGURE_FLAGS=" ${CONFIGURE_FLAGS} --with-pydebug"
465479fi
@@ -716,6 +730,25 @@ CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS CFLAGS_JIT=$CFLAGS_JIT LDFLAGS=$LDFLAGS \
716730# Supplement produced Makefile with our modifications.
717731cat ../Makefile.extra >> Makefile
718732
733+ # PYSTANDALONE: do a silly dance to temporarily disable the _pystandalone module to avoid compilation issues during regen
734+ sed -E " ${sed_args[@]} " ' s/^(_pystandalone .+)/#\1/g' Modules/Setup.local
735+ rm Modules/config.c
736+ make -j " ${NUM_CPUS} " Modules/config.c
737+ cat ../Makefile.extra >> Makefile
738+
739+ # PYSTANDALONE: regenerate files (clinic, global objects, importlib because of changes to zipimport.py, etc.)
740+ make -j " ${NUM_CPUS} " clinic
741+ if [ -n " ${PYTHON_MEETS_MINIMUM_VERSION_3_11} " ]; then
742+ make -j ${NUM_CPUS} regen-global-objects
743+ fi
744+ make -j " ${NUM_CPUS} " regen-importlib
745+
746+ # PYSTANDALONE: re-enable the _pystandalone module
747+ sed -E " ${sed_args[@]} " ' s/^#(_pystandalone .+)/\1/g' Modules/Setup.local
748+ rm Modules/config.c
749+ make -j " ${NUM_CPUS} " Modules/config.c
750+ cat ../Makefile.extra >> Makefile
751+
719752make -j " ${NUM_CPUS} "
720753make -j " ${NUM_CPUS} " sharedinstall DESTDIR=" ${ROOT} /out/python"
721754make -j " ${NUM_CPUS} " install DESTDIR=" ${ROOT} /out/python"
0 commit comments