python3: fix host python extension compilation on macOS
authorJosef Schlehofer <redacted>
Mon, 8 Jun 2026 07:05:18 +0000 (09:05 +0200)
committerAlexandru Ardelean <redacted>
Mon, 8 Jun 2026 11:34:58 +0000 (14:34 +0300)
commitea541f48b5b32d28b54de8ca30541c60f01ebde0
treec9b9b9ea4f4aadf04fa607044e02f890739eb537
parentd373e0ec7d600ba31c0d5b16a0f7ac4234a63047
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 <redacted>
lang/python/python3-host.mk
git clone https://git.99rst.org/PROJECT