Skip to content

fix(cmake): skip interpreter for free-threaded cross builds without CMP0190 - #6284

Open
henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:fix/cross-free-threaded
Open

henryiii wants to merge 1 commit into
pybind:masterfrom
henryiii:fix/cross-free-threaded

Conversation

@henryiii

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

When cross-compiling with CMP0190 OLD (for example cmake_minimum_required(VERSION 3.15...4.0)), pybind11 asks FindPython for Interpreter. If the interpreter can run on the build machine (conda's cross-python), FindPython finds it. It does not query the interpreter in a cross build, so it sets the ABI flags to <none>. This overrides a free-threaded Python_FIND_ABI (ANY;ANY;ANY;ON, which scikit-build-core sets). FindPython then searches only for names without t and rejects include/python3.Xt, so it fails with Could NOT find Python (missing: Development.Module).

This broke the conda-forge linux-ppc64le cp314t/cp315t builds of iminuit (conda-forge/iminuit-feedstock#121). The cause is a FindPython bug. This PR adds a workaround: when cross-compiling with no emulator, PYBIND11_USE_CROSSCOMPILING now also defaults to ON if Python_FIND_ABI requests the free-threaded ABI. Before, it did this only with CMP0190 NEW. An explicit value is still kept. Builds with the GIL are not changed.

A broader option is to default to ON for all cross builds with no emulator, whatever the policy. That would also cover free-threaded builds that don't set Python_FIND_ABI (they fail anyway, because of FindPython's default ABI), but it changes the behavior for current cross builds with the GIL.

I checked this with CMake 4.5, the conda-forge linux-ppc64le python-3.14.10 cp314t package, and a local 3.14t interpreter that acts as the cross-python wrapper. Before this change, Development.Module was not found. After it, Python is found.

Suggested changelog entry:

  • Fixed cross-compiling for free-threaded Python with CMake policy CMP0190 unset, when Python_FIND_ABI requests the free-threaded ABI (as scikit-build-core does).

@henryiii
henryiii marked this pull request as ready for review November 17, 2026 13:58
@rwgk

rwgk commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

— codex on behalf of Ralf —

Keep the free-threaded workaround active on reconfigure. In a vendored add_subdirectory cross build using CMake 4.0.3, CPython 3.14.10t, Python_FIND_ABI=ANY;ANY;ANY;ON, and no emulator, the first configure succeeded and the identical second configure failed with Could NOT find Python (missing: Development.Module). The first run sets the internal mode in the current directory while caching the public option as OFF. On the second run the marker guard skips the workaround. Please include the free-threaded predicate in the cached default, as #6267 does for the CMP0190 path, and exercise two configures in the same build directory. Workaround and option default

Generated by Codex. Ralf has yet to review these findings.

@henryiii
henryiii force-pushed the fix/cross-free-threaded branch 2 times, most recently from fb1487c to a376a13 Compare November 21, 2026 18:11
@henryiii

Copy link
Copy Markdown
Collaborator Author

🤖 AI text below 🤖

Confirmed and fixed in a376a13.

The branch now contains the commit from #6267 (98be134), and the free-threaded predicate is part of the PYBIND11_USE_CROSSCOMPILING option default in CMakeLists.txt. tools/pybind11Common.cmake keeps the same predicate for find_package() consumers. This PR must merge after #6267; until then its diff also shows that commit.

I did two configures in the same build directory with a vendored add_subdirectory project, a toolchain file that sets CMAKE_SYSTEM_NAME, no emulator, and Python_FIND_ABI=ANY;ANY;ANY;ON. This checks the value of _PYBIND11_CROSSCOMPILING only (PYBIND11_NOPYTHON=ON); it is not a full cross build with free-threaded headers.

Commit CMake Run 1 Run 2
fa8a4ae (before) 4.0.3 ON OFF
a376a13 3.31.6 ON ON
a376a13 4.0.3 ON ON
a376a13 4.5.1 ON ON

With a376a13, an explicit -DPYBIND11_USE_CROSSCOMPILING=OFF or a defined CMAKE_CROSSCOMPILING_EMULATOR gives OFF on both runs. Without Python_FIND_ABI, the result is OFF on both runs with CMake 3.31.6 and 4.0.3.

No two-configure test is added to the test suite; tests/test_cmake_build has no cross-compile setup to extend.

…MP0190

Without CMP0190 NEW, FindPython finds the interpreter when cross-compiling
but cannot query its ABI flags. It then drops the free-threaded ABI
requested with Python_FIND_ABI and rejects the python3.Xt headers.

The default is part of the PYBIND11_USE_CROSSCOMPILING option default, so
the cache keeps it on a second configure.

Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-fable-5-2
@henryiii
henryiii force-pushed the fix/cross-free-threaded branch from a376a13 to 476ce78 Compare November 21, 2026 18:17

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants