Skip to content

Conversation

@mhsmith
Copy link
Contributor

@mhsmith mhsmith commented Sep 5, 2025

Description

This PR updates the Android linking workaround in pybind11NewTools.cmake to be compatible with vcpkg, as discussed at #5733 (review). I've also submitted an upstream fix to CMake, so this workaround can eventually be removed.

However, most of the PR is about CMake policy CMP0190, which prohibits calling FindPython with both the Interpreter and Development components at the same time when cross-compiling:

  • Enabled PYBIND11_USE_CROSSCOMPILING whenever CMP0190 is in effect.

  • Updated pybind11NewTools.cmake so it no longer requires the Interpreter component, whether cross-compiling or not. This allows packages to use the same configuration for both cases.

  • Improved pybind11GuessPythonExtSuffix.cmake:

    • Added SKBUILD_SOABI as another possible source of the Python module suffix.
    • Set result variables to the CACHE, just as they are when they're detected from the interpreter. Previously they were set to the PARENT_SCOPE, but that's the module scope of pybind11NewTools.cmake, which isn't accessible when calling functions from a different module. As a result, modules created using pybind11_add_module were being built with no extension at all!
  • To encourage packages to be compatible with cross-compilation, I've removed Interpreter from all the documentation, examples and tests, except for the places which actually needed it. I've now reverted this for the reasons explained in scikit-build-core#1142 (comment).

The new policy can be tested by changing the cmake_minimum_required upper limit in CMakeLists.txt from 4.0 to 4.1, and then using cibuildwheel to build the tests project. However, I haven't changed the cmake_minimum_required in this PR, because I'm not sure what other effects it might have.

See also:

Suggested changelog entry:

  • Fix compatibility with CMake policy CMP0190, by not always requiring a Python interpreter when cross-compiling.

📚 Documentation preview 📚: https://pybind11--5829.org.readthedocs.build/

@henryiii
Copy link
Collaborator

@mhsmith is this ready to go in?

@mhsmith
Copy link
Contributor Author

mhsmith commented Jan 20, 2026

Yes, I think so.

@henryiii henryiii merged commit 53ccc32 into pybind:master Jan 20, 2026
87 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jan 20, 2026
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Jan 21, 2026
henryiii added a commit to scikit-build/scikit-build-core that referenced this pull request Jan 22, 2026
The main motivation for this PR is CMake policy
[CMP0190](https://cmake.org/cmake/help/latest/policy/CMP0190.html),
which will prohibit calling FindPython with both the `Interpreter` and
`Development` components at the same time when cross-compiling. To
encourage packages to be compatible with cross-compilation, I've removed
`Interpreter` from all the documentation, examples and tests, except for
the places which actually needed it.

CMake is still able to find the Android Python libraries by itself
without an interpreter, but it takes a very long time (20 seconds).
Going by the
[`--debug-find`](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-debug-find)
option, this may be because it's searching a huge number of nonexistent
paths, including every possible combination of Python version and
`abiflags` *squared* (both for the directory name and the library name).

So I've changed builder.py to tell CMake the Python library location on
Android, as it already does on Windows.

This performance problem doesn't affect the other Unix platforms,
because they have the `python3.x-config` script available.

See also:
* pybind/pybind11#5829

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
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.

3 participants