scikit-build-core icon indicating copy to clipboard operation
scikit-build-core copied to clipboard

fix: add Android support

Open mhsmith opened this issue 3 months ago • 2 comments

The main motivation for this PR is CMake policy CMP0190, 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 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:

  • https://github.com/pybind/pybind11/pull/5829

mhsmith avatar Sep 05 '25 15:09 mhsmith

From what I understand, you can set a emulated Python for it, though.

I saw that in the CMake documentation, but I initially rejected it because starting up a whole Android emulator just to run a short Python script would be too slow.

However, then I realized that cibuildwheel's simulated Android Python environment effectively is an emulator as far as FindPython is concerned. So all we need to do is add a dummy CMAKE_CROSSCOMPILING_EMULATOR to the toolchain file (https://github.com/pypa/cibuildwheel/pull/2591), and then we can build for Android with the Interpreter component included.

This is a much better solution, because it's compatible with the many existing packages which already have Interpreter in their CMakeLists.

mhsmith avatar Sep 13 '25 15:09 mhsmith

(I'll work on helping with this when I get back from India, sorry for the delay!)

henryiii avatar Sep 19 '25 00:09 henryiii