Skip to content

Commit 3384daa

Browse files
authored
Fix bundled Python crashing on macOS 26 and older when built with Xcode 27 (#16035)
# Description With Xcode 27, building deps on macOS 26 fails at the Python install step with a segfault, and a libpython built with Xcode 27 crashes on macOS 12–26 the first time anything calls `os.pipe()`, which every plugin `subprocess` call does. The macOS 27 SDK declares `pipe2()` and `dup3()` as macOS 27-only, and CPython 3.12 calls them without a runtime check once configure finds them, so on older systems they resolve to NULL. This keeps CPython on the `pipe()`/`dup2()` fallbacks it already uses with older SDKs; upstream fixed it in 3.13+ ([python/cpython#153711](python/cpython#153711)) but not in 3.12. No change for builds with Xcode 26 or older, or on Linux and Windows. # Screenshots/Recordings/Graphs <!-- > Please attach relevant screenshots to showcase the UI changes. > Please attach images that can help explain the changes. --> ## Tests Rebuilt deps with Xcode 27 on macOS 26.6: the Python install step now completes, the installed libpython no longer imports `pipe2`/`dup3`, and CPython's `test_os`, `test_subprocess` and `test_posix` pass, apart from one test that needs `_testcapi`, which `--disable-test-modules` leaves out. Running CPython's configure against the macOS 26.5 and 27.0 SDKs gives a byte-identical `pyconfig.h` for 26.5 with and without this change, and for 27.0 with it. The x86_64 cross-build path was configured on arm64 to confirm both of its configure runs pick up the change. <!-- > A guide for users on how to download the artifacts from this PR. --> [How to Download Pull Requests Artifacts for Testing](https://www.orcaslicer.com/wiki/how_to_download_pr_artifacts)
2 parents 6842d9c + 2a9cb32 commit 3384daa

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎deps/python3/python3.cmake‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ elseif(APPLE)
151151
# the post-install -add_rpath below.
152152
set(_python_ldflags "${_python_arch_flags} -Wl,-headerpad_max_install_names")
153153

154+
# The macOS 27 SDK declares pipe2() and dup3() as available from macOS 27, so
155+
# configure finds them and CPython 3.12 calls them without a runtime check.
156+
# Below a macOS 27 deployment target they are weak-linked and resolve to NULL
157+
# on older systems, where os.pipe() then segfaults -- in `make install`
158+
# (compileall, ensurepip) and in the shipped app alike. Every configure below
159+
# keeps the pipe()/dup2() fallbacks (python/cpython#153711).
154160
if(IS_CROSS_COMPILE)
155161
set(_python_build_tgt --build=${_python_build_arch}-apple-darwin --host=${_python_host_arch}-apple-darwin)
156162
set(_python_build_arch_flags "-arch ${_python_build_arch_flag} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
@@ -174,7 +180,8 @@ elseif(APPLE)
174180
--enable-shared \
175181
--without-static-libpython \
176182
--disable-test-modules \
177-
--build=${_python_build_arch}-apple-darwin && \
183+
--build=${_python_build_arch}-apple-darwin \
184+
ac_cv_func_pipe2=no ac_cv_func_dup3=no && \
178185
make -j${NPROC} python && \
179186
cd '<SOURCE_DIR>' && \
180187
env \
@@ -191,6 +198,7 @@ elseif(APPLE)
191198
--without-static-libpython \
192199
--with-openssl='${DESTDIR}' \
193200
--disable-test-modules \
201+
ac_cv_func_pipe2=no ac_cv_func_dup3=no \
194202
${_python_build_tgt} \
195203
--with-build-python='${_python_build_python}' \
196204
py_cv_module__tkinter=n/a"
@@ -213,6 +221,8 @@ elseif(APPLE)
213221
--with-openssl=${DESTDIR}
214222
--disable-test-modules
215223
${_python_build_tgt}
224+
ac_cv_func_pipe2=no
225+
ac_cv_func_dup3=no
216226
# Tcl/Tk 9.0 (e.g. from Homebrew) is incompatible with CPython 3.12's
217227
# _tkinter; OrcaSlicer's embedded Python does not need tkinter anyway.
218228
py_cv_module__tkinter=n/a

0 commit comments

Comments
 (0)