From: Josef Schlehofer Date: Mon, 8 Jun 2026 07:05:18 +0000 (+0200) Subject: python3: fix host python extension compilation on macOS X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=ea541f48b5b32d28b54de8ca30541c60f01ebde0;p=openwrt-packages.git python3: fix host python extension compilation on macOS On macOS (Darwin) hosts, building host Python C extensions (such as Cython) using the '-shared' flag and linking against '-lpython3.x' causes the host Python interpreter to load a duplicate copy of the Python runtime. This leads to type checking mismatches and segmentation faults (SIGSEGV) when importing the compiled extension. For example, running: ./staging_dir/hostpkg/bin/python3 -c "import Cython.Utils" crashes with: Segmentation fault: 11 To build shared modules correctly on macOS, they must be compiled as bundles using the '-bundle -undefined dynamic_lookup' flags instead of '-shared', and they should not link against the Python library (no '-lpython3.x' in LDFLAGS). Fix this by dynamically adjusting LDSHARED and LDFLAGS in python3-host.mk when the host OS is Darwin. Signed-off-by: Josef Schlehofer --- diff --git a/lang/python/python3-host.mk b/lang/python/python3-host.mk index 64d4e373e..7c16703ee 100644 --- a/lang/python/python3-host.mk +++ b/lang/python/python3-host.mk @@ -74,10 +74,10 @@ HOST_PYTHON3_VARS = \ CCSHARED="$(HOSTCC) $(HOST_FPIC)" \ CXX="$(HOSTCXX)" \ LD="$(HOSTCC)" \ - LDSHARED="$(HOSTCC) -shared" \ + LDSHARED="$(HOSTCC) $(if $(findstring Darwin,$(HOST_OS)),-bundle -undefined dynamic_lookup,-shared)" \ CFLAGS="$(HOST_CFLAGS)" \ CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \ - LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION)" \ + LDFLAGS="$(HOST_LDFLAGS)$(if $(findstring Darwin,$(HOST_OS)),, -lpython$(PYTHON3_VERSION))" \ $(CARGO_HOST_CONFIG_VARS) \ SETUPTOOLS_RUST_CARGO_PROFILE="$(CARGO_HOST_PROFILE)"