Skip to content

Commit 90a9247

Browse files
authored
statically link libpython on macOS (#1105)
Statically link `python` to `libpython` on macOS. A dynamic `libpython` is still built and included in the distribution for embedded use. Remove patches that disable linking the libraries in statically linked Python stdlib modules to python as these are now needed. closes #636
1 parent 8887794 commit 90a9247

4 files changed

Lines changed: 5 additions & 64 deletions

File tree

cpython-unix/build-cpython.sh

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,6 @@ else
147147
patch -p1 -i "${ROOT}/patch-macos-link-extension-modules.patch"
148148
fi
149149

150-
# Also on macOS, the `python` executable is linked against libraries defined by statically
151-
# linked modules. But those libraries should only get linked into libpython, not the
152-
# executable. This behavior is kinda suspect on all platforms, as it could be adding
153-
# 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
163-
164150
# The macOS code for sniffing for _dyld_shared_cache_contains_path falls back on a
165151
# possibly inappropriate code path if a configure time check fails. This is not
166152
# appropriate for certain cross-compiling scenarios. See discussion at
@@ -429,19 +415,12 @@ CONFIGURE_FLAGS="
429415

430416
# Build a libpython3.x.so, but statically link the interpreter against
431417
# libpython.
432-
#
433-
# For now skip this on macos, because it causes some linker failures. Note that
434-
# this patch mildly conflicts with the macos-only patch-python-link-modules
435-
# applied above, so you will need to resolve that conflict if you re-enable
436-
# this for macos.
437-
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
438-
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then
439-
patch -p1 -i "${ROOT}/patch-python-configure-add-enable-static-libpython-for-interpreter.patch"
440-
else
441-
patch -p1 -i "${ROOT}/patch-python-configure-add-enable-static-libpython-for-interpreter-${PYTHON_MAJMIN_VERSION}.patch"
442-
fi
443-
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-static-libpython-for-interpreter"
418+
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then
419+
patch -p1 -i "${ROOT}/patch-python-configure-add-enable-static-libpython-for-interpreter.patch"
420+
else
421+
patch -p1 -i "${ROOT}/patch-python-configure-add-enable-static-libpython-for-interpreter-${PYTHON_MAJMIN_VERSION}.patch"
444422
fi
423+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-static-libpython-for-interpreter"
445424

446425
if [ "${CC}" = "musl-clang" ]; then
447426
# In order to build the _blake2 extension module with SSE3+ instructions, we need

cpython-unix/patch-python-link-modules-3.10.patch

Lines changed: 0 additions & 12 deletions
This file was deleted.

cpython-unix/patch-python-link-modules-3.11.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.

cpython-unix/patch-python-link-modules-3.15.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)