From 66386b1a3043df38dd78828d229a77f1c5a02283 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Wed, 3 Sep 2025 21:58:27 +0100 Subject: [PATCH 1/3] Add Android support --- README.md | 2 +- .../downstream/nanobind_example/CMakeLists.txt | 2 +- .../downstream/pybind11_example/CMakeLists.txt | 2 +- .../getting_started/abi3/CMakeLists.txt | 2 +- ...e-0.0.1-cp313-cp313-android_21_arm64_v8a.whl | Bin 0 -> 2362 bytes .../getting_started/fortran/CMakeLists.txt | 2 +- .../getting_started/nanobind/CMakeLists.txt | 2 +- .../getting_started/swig/CMakeLists.txt | 2 +- docs/guide/cmakelists.md | 12 ++++++------ docs/guide/crosscompile.md | 15 ++++++++++++++- docs/guide/faqs.md | 16 ++++++++-------- docs/guide/migration_guide.md | 2 +- src/scikit_build_core/builder/builder.py | 12 +++++++----- tests/conftest.py | 12 +++++++++++- .../packages/abi3_pyproject_ext/CMakeLists.txt | 2 +- .../packages/abi3_setuptools_ext/CMakeLists.txt | 2 +- tests/packages/broken_fallback/CMakeLists.txt | 2 +- tests/packages/dynamic_metadata/CMakeLists.txt | 2 +- .../packages/importlib_editable/CMakeLists.txt | 2 +- tests/packages/navigate_editable/CMakeLists.txt | 2 +- .../simple_pyproject_ext/CMakeLists.txt | 2 +- .../src/CMakeLists.txt | 2 +- tests/packages/simplest_c/CMakeLists.txt | 2 +- 23 files changed, 63 insertions(+), 38 deletions(-) create mode 100644 docs/examples/getting_started/c/wheelhouse/example-0.0.1-cp313-cp313-android_21_arm64_v8a.whl diff --git a/README.md b/README.md index ba1626045..10b7e6199 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ An example `CMakeLists.txt`: cmake_minimum_required(VERSION 3.15...3.30) project(${SKBUILD_PROJECT_NAME} LANGUAGES C) -find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) +find_package(Python COMPONENTS Development.Module REQUIRED) Python_add_library(_module MODULE src/module.c WITH_SOABI) install(TARGETS _module DESTINATION ${SKBUILD_PROJECT_NAME}) diff --git a/docs/examples/downstream/nanobind_example/CMakeLists.txt b/docs/examples/downstream/nanobind_example/CMakeLists.txt index ba3ee222b..98f3ffb8a 100644 --- a/docs/examples/downstream/nanobind_example/CMakeLists.txt +++ b/docs/examples/downstream/nanobind_example/CMakeLists.txt @@ -30,7 +30,7 @@ endif() # Try to import all Python components potentially needed by nanobind find_package( Python 3.8 REQUIRED - COMPONENTS Interpreter Development.Module + COMPONENTS Development.Module OPTIONAL_COMPONENTS Development.SABIModule) # Import nanobind through CMake's find_package mechanism diff --git a/docs/examples/downstream/pybind11_example/CMakeLists.txt b/docs/examples/downstream/pybind11_example/CMakeLists.txt index 928b01d9b..8ba63e131 100644 --- a/docs/examples/downstream/pybind11_example/CMakeLists.txt +++ b/docs/examples/downstream/pybind11_example/CMakeLists.txt @@ -5,7 +5,7 @@ project( VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX) -find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) +find_package(Python REQUIRED COMPONENTS Development.Module) find_package(pybind11 CONFIG REQUIRED) python_add_library(_core MODULE src/main.cpp WITH_SOABI) diff --git a/docs/examples/getting_started/abi3/CMakeLists.txt b/docs/examples/getting_started/abi3/CMakeLists.txt index c4f4e3f36..fbb81353c 100644 --- a/docs/examples/getting_started/abi3/CMakeLists.txt +++ b/docs/examples/getting_started/abi3/CMakeLists.txt @@ -3,7 +3,7 @@ project(${SKBUILD_PROJECT_NAME} LANGUAGES C) find_package( Python - COMPONENTS Interpreter Development.SABIModule + COMPONENTS Development.SABIModule REQUIRED) python_add_library(example MODULE example.c WITH_SOABI USE_SABI 3.8) diff --git a/docs/examples/getting_started/c/wheelhouse/example-0.0.1-cp313-cp313-android_21_arm64_v8a.whl b/docs/examples/getting_started/c/wheelhouse/example-0.0.1-cp313-cp313-android_21_arm64_v8a.whl new file mode 100644 index 0000000000000000000000000000000000000000..28519b238c1a4434cec78ecc7659939f9a6ecd5c GIT binary patch literal 2362 zcmaJ@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Tt>pLqFh zBA~IuZXXAy80hDV0Q)EYIiKVIzP_&od-L|H?B6T^cosjwUMv2e_fyU7McXT*?`T%s oKS%pVRC}TJ_VqgyC(qBJ{_U~@jEhYN0Q=Y`!`21Q{=cKY0DNF6XaE2J literal 0 HcmV?d00001 diff --git a/docs/examples/getting_started/fortran/CMakeLists.txt b/docs/examples/getting_started/fortran/CMakeLists.txt index 1d05f2544..f43cb0224 100644 --- a/docs/examples/getting_started/fortran/CMakeLists.txt +++ b/docs/examples/getting_started/fortran/CMakeLists.txt @@ -3,7 +3,7 @@ project(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran) find_package( Python - COMPONENTS Interpreter Development.Module NumPy + COMPONENTS Development.Module NumPy REQUIRED) # F2PY headers diff --git a/docs/examples/getting_started/nanobind/CMakeLists.txt b/docs/examples/getting_started/nanobind/CMakeLists.txt index bf30109b5..0d0d21ca0 100644 --- a/docs/examples/getting_started/nanobind/CMakeLists.txt +++ b/docs/examples/getting_started/nanobind/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.15...3.26) project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) -find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development.Module) +find_package(Python 3.8 REQUIRED COMPONENTS Development.Module) find_package(nanobind CONFIG REQUIRED) diff --git a/docs/examples/getting_started/swig/CMakeLists.txt b/docs/examples/getting_started/swig/CMakeLists.txt index e0c3b349b..bbc87e709 100644 --- a/docs/examples/getting_started/swig/CMakeLists.txt +++ b/docs/examples/getting_started/swig/CMakeLists.txt @@ -3,7 +3,7 @@ project(${SKBUILD_PROJECT_NAME} LANGUAGES C) find_package( Python - COMPONENTS Interpreter Development.Module + COMPONENTS Development.Module REQUIRED) find_package( diff --git a/docs/guide/cmakelists.md b/docs/guide/cmakelists.md index e75cff82e..bd1cfe587 100644 --- a/docs/guide/cmakelists.md +++ b/docs/guide/cmakelists.md @@ -26,13 +26,13 @@ Scikit-build-core provides several useful variables: You can directly use FindPython: ```cmake -find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) +find_package(Python COMPONENTS Development.Module REQUIRED) ``` -You always want to find at least `Interpreter` and the `Module` component of the -`Development` package. You do not want to find the entire `Development` package, -as that include `Embed` component, which is not always present and is not -related to making Python extension modules. +You always want to find at least the `Development.Module` component. You do not +want to find the entire `Development` component, as that includes +`Development.Embed`, which is not always present and is not related to making +Python extension modules. If you are making a Limited API / Stable ABI package, you'll need the `Development.SABIModule` component instead (CMake 3.26+). You can use the @@ -129,7 +129,7 @@ When you do that, `${SKBUILD_SABI_COMPONENT}` will be set to remain an empty string otherwise (PyPy). This allows the following idiom: ```cmake -find_package(Python REQUIRED COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT}) +find_package(Python REQUIRED COMPONENTS Development.Module ${SKBUILD_SABI_COMPONENT}) ``` This will require the `Development.SABIModule` component only if diff --git a/docs/guide/crosscompile.md b/docs/guide/crosscompile.md index 97b24531a..b35a710f3 100644 --- a/docs/guide/crosscompile.md +++ b/docs/guide/crosscompile.md @@ -52,7 +52,7 @@ correct suffix. These values are set by cibuildwheel when cross-compiling. It should be possible to cross-compile to Linux, but due to the challenges of getting the manylinux RHEL devtoolkit compilers, this is currently a TODO. See -`py-build-cmake `\_ +[py-build-cmake](https://tttapa.github.io/py-build-cmake/Cross-compilation.html) for an alternative package's usage of toolchain files. ### Intel to Emscripten (Pyodide) @@ -64,3 +64,16 @@ by setting `_PYTHON_SYSCONFIGDATA_NAME`. This causes values like `SOABI` and This is unfortunately incorrectly stripped from the cmake wrapper pyodide uses, so FindPython will report the wrong values, but pyodide-build will rename the .so's afterwards. + +## Android + +To build for Android, you'll need the following items, all of which will be +provided automatically if you use cibuildwheel: + +- An Android + [toolchain file](https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html) + which adds the location of the Python headers and libraries to + `CMAKE_FIND_ROOT_PATH`. +- Compiler paths and flags, either in the toolchain file or in environment + variables. +- A Python environment which simulates Android. diff --git a/docs/guide/faqs.md b/docs/guide/faqs.md index cdddf29a1..b3b3888f2 100644 --- a/docs/guide/faqs.md +++ b/docs/guide/faqs.md @@ -42,14 +42,14 @@ is missing some value you need, please open an issue and let us know. ## Finding Python -One common mistake when using FindPython is to forget to only request the -`Development.Module` component. If you request `Development`, you will also -require the `Development.Embed` component, which will require the Python -libraries to be found for linking. When building a module on Unix, you do not -link to Python - the Python symbols are already loaded in the interpreter. -What's more, the manylinux image (which is used to make redistributable Linux -wheels) does not have the Python libraries, both to avoid this mistake, and to -reduce size. +One common mistake when using FindPython is to request the `Development` +component, which requires the `Development.Embed` component, which will require +the Python libraries to be found for linking. When building a module on Unix, +you do not link to Python - the Python symbols are already loaded in the +interpreter. What's more, the manylinux image (which is used to make +redistributable Linux wheels) does not have the Python libraries, both to avoid +this mistake, and to reduce size. Instead, you should only request the +`Development.Module` component. ## Cross compiling diff --git a/docs/guide/migration_guide.md b/docs/guide/migration_guide.md index 599f63dcd..b9c35e7ff 100644 --- a/docs/guide/migration_guide.md +++ b/docs/guide/migration_guide.md @@ -53,7 +53,7 @@ python_extension_module(${LIBRARY}) to ```cmake -find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) +find_package(Python COMPONENTS Development.Module REQUIRED) python_add_library(${LIBRARY} MODULE WITH_SOABI ${FILENAME}) ``` diff --git a/src/scikit_build_core/builder/builder.py b/src/scikit_build_core/builder/builder.py index dde36ddab..045517db8 100644 --- a/src/scikit_build_core/builder/builder.py +++ b/src/scikit_build_core/builder/builder.py @@ -254,11 +254,13 @@ def configure( cache_config[f"{prefix}_ROOT_DIR"] = Path(sys.prefix) cache_config[f"{prefix}_INCLUDE_DIR"] = python_include_dir cache_config[f"{prefix}_FIND_REGISTRY"] = "NEVER" - # FindPython may break if this is set - only useful on Windows - if python_library and sysconfig.get_platform().startswith("win"): - cache_config[f"{prefix}_LIBRARY"] = python_library - if python_sabi_library and sysconfig.get_platform().startswith("win"): - cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library + # Setting the library location is only needed on some platforms - on + # other platforms it may break FindPython. + if sysconfig.get_platform().startswith(("win", "android")): + if python_library: + cache_config[f"{prefix}_LIBRARY"] = python_library + if python_sabi_library: + cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library if numpy_include_dir: cache_config[f"{prefix}_NumPy_INCLUDE_DIR"] = numpy_include_dir diff --git a/tests/conftest.py b/tests/conftest.py index db9eda952..d8b6350fa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,7 @@ import sysconfig from importlib import metadata from pathlib import Path -from typing import Any, Literal, overload +from typing import TYPE_CHECKING, Any, Literal, overload import virtualenv as _virtualenv @@ -19,6 +19,8 @@ else: import tomllib +if TYPE_CHECKING: + from pytest_subprocess import FakeProcess import pytest from packaging.requirements import Requirement @@ -30,6 +32,14 @@ VIRTUALENV_VERSION = Version(metadata.version("virtualenv")) +@pytest.fixture +def fp(fp: FakeProcess) -> FakeProcess: + # For program_search._macos_binary_is_x86 + fp.register(["lipo", fp.any()], returncode=1) + fp.register(["file", fp.any()], returncode=1) + return fp + + @pytest.fixture(scope="session") def pep518_wheelhouse(tmp_path_factory: pytest.TempPathFactory) -> Path: wheelhouse = tmp_path_factory.mktemp("wheelhouse") diff --git a/tests/packages/abi3_pyproject_ext/CMakeLists.txt b/tests/packages/abi3_pyproject_ext/CMakeLists.txt index 43c6e5bef..2422d5fbb 100644 --- a/tests/packages/abi3_pyproject_ext/CMakeLists.txt +++ b/tests/packages/abi3_pyproject_ext/CMakeLists.txt @@ -7,7 +7,7 @@ project( find_package( Python - COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT} + COMPONENTS Development.Module ${SKBUILD_SABI_COMPONENT} REQUIRED) if(NOT "${SKBUILD_SABI_VERSION}" STREQUAL "") diff --git a/tests/packages/abi3_setuptools_ext/CMakeLists.txt b/tests/packages/abi3_setuptools_ext/CMakeLists.txt index 5fc6ad6c7..880e95d9c 100644 --- a/tests/packages/abi3_setuptools_ext/CMakeLists.txt +++ b/tests/packages/abi3_setuptools_ext/CMakeLists.txt @@ -7,7 +7,7 @@ project( find_package( Python - COMPONENTS Interpreter Development.SABIModule + COMPONENTS Development.SABIModule REQUIRED) python_add_library(abi3_example MODULE abi3_example.c WITH_SOABI USE_SABI 3.8) diff --git a/tests/packages/broken_fallback/CMakeLists.txt b/tests/packages/broken_fallback/CMakeLists.txt index a0f12eeee..ed7e57ae0 100644 --- a/tests/packages/broken_fallback/CMakeLists.txt +++ b/tests/packages/broken_fallback/CMakeLists.txt @@ -7,7 +7,7 @@ endif() find_package( Python - COMPONENTS Interpreter Development.Module + COMPONENTS Development.Module REQUIRED) python_add_library(example MODULE main.c WITH_SOABI) diff --git a/tests/packages/dynamic_metadata/CMakeLists.txt b/tests/packages/dynamic_metadata/CMakeLists.txt index c2e2115a2..b11af7d7d 100644 --- a/tests/packages/dynamic_metadata/CMakeLists.txt +++ b/tests/packages/dynamic_metadata/CMakeLists.txt @@ -5,7 +5,7 @@ project( LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) -find_package(Python COMPONENTS Interpreter Development.Module) +find_package(Python COMPONENTS Development.Module) set(Python_SOABI ${SKBUILD_SOABI}) python_add_library(_module MODULE src/module.c WITH_SOABI) diff --git a/tests/packages/importlib_editable/CMakeLists.txt b/tests/packages/importlib_editable/CMakeLists.txt index 7a96fb06b..5a8de63bd 100644 --- a/tests/packages/importlib_editable/CMakeLists.txt +++ b/tests/packages/importlib_editable/CMakeLists.txt @@ -3,7 +3,7 @@ project(${SKBUILD_PROJECT_NAME} LANGUAGES C) find_package( Python - COMPONENTS Interpreter Development.Module + COMPONENTS Development.Module REQUIRED) python_add_library(emod MODULE emod.c WITH_SOABI) diff --git a/tests/packages/navigate_editable/CMakeLists.txt b/tests/packages/navigate_editable/CMakeLists.txt index 13420b6fe..c55006c67 100644 --- a/tests/packages/navigate_editable/CMakeLists.txt +++ b/tests/packages/navigate_editable/CMakeLists.txt @@ -5,7 +5,7 @@ project( LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) -find_package(Python COMPONENTS Interpreter Development.Module) +find_package(Python COMPONENTS Development.Module) python_add_library(c_module MODULE src/shared_pkg/c_module.c WITH_SOABI) diff --git a/tests/packages/simple_pyproject_ext/CMakeLists.txt b/tests/packages/simple_pyproject_ext/CMakeLists.txt index b9a8a304c..eeaeddffc 100644 --- a/tests/packages/simple_pyproject_ext/CMakeLists.txt +++ b/tests/packages/simple_pyproject_ext/CMakeLists.txt @@ -6,7 +6,7 @@ project( find_package( Python - COMPONENTS Interpreter Development.Module + COMPONENTS Development.Module REQUIRED) find_package(pybind11 CONFIG REQUIRED) diff --git a/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt b/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt index 703a4ad83..7aff103ea 100644 --- a/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt +++ b/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt @@ -6,7 +6,7 @@ project( find_package( Python - COMPONENTS Interpreter Development.Module + COMPONENTS Development.Module REQUIRED) find_package(pybind11 CONFIG REQUIRED) diff --git a/tests/packages/simplest_c/CMakeLists.txt b/tests/packages/simplest_c/CMakeLists.txt index 9d6caab25..6bcf41db6 100644 --- a/tests/packages/simplest_c/CMakeLists.txt +++ b/tests/packages/simplest_c/CMakeLists.txt @@ -5,7 +5,7 @@ project( LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) -find_package(Python COMPONENTS Interpreter Development.Module) +find_package(Python COMPONENTS Development.Module) python_add_library(_module MODULE src/module.c WITH_SOABI) From 869c9c1363b3a80cc0fe8bdc344c1385d2cf1a9f Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Fri, 5 Sep 2025 17:09:00 +0100 Subject: [PATCH 2/3] Improve wording --- docs/guide/faqs.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/guide/faqs.md b/docs/guide/faqs.md index b3b3888f2..8e1e1706c 100644 --- a/docs/guide/faqs.md +++ b/docs/guide/faqs.md @@ -42,14 +42,14 @@ is missing some value you need, please open an issue and let us know. ## Finding Python -One common mistake when using FindPython is to request the `Development` -component, which requires the `Development.Embed` component, which will require -the Python libraries to be found for linking. When building a module on Unix, -you do not link to Python - the Python symbols are already loaded in the -interpreter. What's more, the manylinux image (which is used to make -redistributable Linux wheels) does not have the Python libraries, both to avoid -this mistake, and to reduce size. Instead, you should only request the -`Development.Module` component. +When using `find_package(Python ...)`, you should only request the +`Development.Module` component. If you request `Development`, you will also +require the `Development.Embed` component, which will require the Python +libraries to be found for linking. When building a module on Unix, you do not +link to Python - the Python symbols are already loaded in the interpreter. +What's more, the manylinux image (which is used to make redistributable Linux +wheels) does not have the Python libraries, both to avoid this mistake, and to +reduce size. ## Cross compiling From cbc124dc0e346206ca83b288411478bc05c500ce Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Sat, 13 Sep 2025 16:24:55 +0100 Subject: [PATCH 3/3] Revert removal of Interpreter --- README.md | 2 +- .../nanobind_example/CMakeLists.txt | 2 +- .../pybind11_example/CMakeLists.txt | 2 +- .../getting_started/abi3/CMakeLists.txt | 2 +- ...0.0.1-cp313-cp313-android_21_arm64_v8a.whl | Bin 2362 -> 0 bytes .../getting_started/fortran/CMakeLists.txt | 2 +- .../getting_started/nanobind/CMakeLists.txt | 2 +- .../getting_started/swig/CMakeLists.txt | 2 +- docs/guide/cmakelists.md | 12 ++++++------ docs/guide/crosscompile.md | 18 +++++++++++++----- docs/guide/migration_guide.md | 2 +- src/scikit_build_core/builder/builder.py | 12 +++++------- .../abi3_pyproject_ext/CMakeLists.txt | 2 +- .../abi3_setuptools_ext/CMakeLists.txt | 2 +- tests/packages/broken_fallback/CMakeLists.txt | 2 +- .../packages/dynamic_metadata/CMakeLists.txt | 2 +- .../importlib_editable/CMakeLists.txt | 2 +- .../packages/navigate_editable/CMakeLists.txt | 2 +- .../simple_pyproject_ext/CMakeLists.txt | 2 +- .../src/CMakeLists.txt | 2 +- tests/packages/simplest_c/CMakeLists.txt | 2 +- 21 files changed, 41 insertions(+), 35 deletions(-) delete mode 100644 docs/examples/getting_started/c/wheelhouse/example-0.0.1-cp313-cp313-android_21_arm64_v8a.whl diff --git a/README.md b/README.md index 10b7e6199..ba1626045 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ An example `CMakeLists.txt`: cmake_minimum_required(VERSION 3.15...3.30) project(${SKBUILD_PROJECT_NAME} LANGUAGES C) -find_package(Python COMPONENTS Development.Module REQUIRED) +find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) Python_add_library(_module MODULE src/module.c WITH_SOABI) install(TARGETS _module DESTINATION ${SKBUILD_PROJECT_NAME}) diff --git a/docs/examples/downstream/nanobind_example/CMakeLists.txt b/docs/examples/downstream/nanobind_example/CMakeLists.txt index 98f3ffb8a..ba3ee222b 100644 --- a/docs/examples/downstream/nanobind_example/CMakeLists.txt +++ b/docs/examples/downstream/nanobind_example/CMakeLists.txt @@ -30,7 +30,7 @@ endif() # Try to import all Python components potentially needed by nanobind find_package( Python 3.8 REQUIRED - COMPONENTS Development.Module + COMPONENTS Interpreter Development.Module OPTIONAL_COMPONENTS Development.SABIModule) # Import nanobind through CMake's find_package mechanism diff --git a/docs/examples/downstream/pybind11_example/CMakeLists.txt b/docs/examples/downstream/pybind11_example/CMakeLists.txt index 8ba63e131..928b01d9b 100644 --- a/docs/examples/downstream/pybind11_example/CMakeLists.txt +++ b/docs/examples/downstream/pybind11_example/CMakeLists.txt @@ -5,7 +5,7 @@ project( VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES CXX) -find_package(Python REQUIRED COMPONENTS Development.Module) +find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) find_package(pybind11 CONFIG REQUIRED) python_add_library(_core MODULE src/main.cpp WITH_SOABI) diff --git a/docs/examples/getting_started/abi3/CMakeLists.txt b/docs/examples/getting_started/abi3/CMakeLists.txt index fbb81353c..c4f4e3f36 100644 --- a/docs/examples/getting_started/abi3/CMakeLists.txt +++ b/docs/examples/getting_started/abi3/CMakeLists.txt @@ -3,7 +3,7 @@ project(${SKBUILD_PROJECT_NAME} LANGUAGES C) find_package( Python - COMPONENTS Development.SABIModule + COMPONENTS Interpreter Development.SABIModule REQUIRED) python_add_library(example MODULE example.c WITH_SOABI USE_SABI 3.8) diff --git a/docs/examples/getting_started/c/wheelhouse/example-0.0.1-cp313-cp313-android_21_arm64_v8a.whl b/docs/examples/getting_started/c/wheelhouse/example-0.0.1-cp313-cp313-android_21_arm64_v8a.whl deleted file mode 100644 index 28519b238c1a4434cec78ecc7659939f9a6ecd5c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2362 zcmaJ@2{hFE7ymJ#$S%uYc6r&!vy5RRDGbkUWJFR*GsZfy41=L zi8r_`{4S)w>cDRh1C%A5OgH&8m}QN^K1~gXa2R@* z{|7xj|MIw`J9!G6+#GuGK~T^9Jx2fLLLnrSRs`8v%_bRCcY{#SZwFUpkL%5?I29lh zM7F&-<{hrLc&9njGrH3`D2a^%yb~we(y``v^&Ilm`fNtwQ7ChCg}GejksE+9oOMk8%;ODiYzmB<@Ome50qG*6|S7#9=_X@QB64%q_ikH z6_xlAnwR44r@@K%GJ3^mpf%~(?aCHBy^V@lw?n?Y!ITAbGdRXezyi?_gG+v~NNfab zt31#ReOazvf0bdlTQ0$RiIal5$IZaw0yW#@wA*Ms^n3Ca)c9^kO*;Gr17oz%WtO?D ztyV;vsn?Ro&11TrtUokyMz_sENX&DSMh@KlLJh@n-*0Ni!U}*id`&7cZL1|CB<|t5 z;PUu!4Sct6`N0s(gk;88R+K^&f;%kzuw5srU-DgYPVgKw;M8ES1q3A}IU3igfOJ?M ztjc?n8?HD`d5A^^+y)O{dAOC8*3D#gsEQhA5)O-#vVw$imBNQ@Kk<#wloUlIc)--n zMMfjbI?>Etrr7bDGQEHg-IA&@Q`p||7=59ofCAz*J3UhE@@-12#AKm#MDPhF%AL|I zf^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!gmsbX70uP(M-&Z0^o0p|zvuHRz@3ob*C~z0eZ(ZAo2Kqk>BpLl zD>9~R{3%Xd7^OZ{qn!lL>?xmcEHk`8bk`@{#cAzSbSe29D|R0-_Q%Q%Z-uYEVplB0 z0RXc9QMr?)g}u{BOkZtCf(`%-Oa&hJH9pQbY`+4$#$2txVDJG?9;bL`eq6El41RHG zD-P~`V{UkaARCY7>t>XA+jTXs%`4SV$Qk{eB|Md4d1IY|mppR(8pMcZDrNl~U)>@c zcO}H1;nP3Sev^I-*|}+dKvY>dVUk*EZUOeJfzF(GIA|w`pnugj+`8~;gUEZ8Cy`L6 zMEB=1S@cm?B7S3G<<7pyFFQ7a5_RG7JQ|8PjeL2t+O+DjvT7f7#zxm0bbTt>pLqFh zBA~IuZXXAy80hDV0Q)EYIiKVIzP_&od-L|H?B6T^cosjwUMv2e_fyU7McXT*?`T%s oKS%pVRC}TJ_VqgyC(qBJ{_U~@jEhYN0Q=Y`!`21Q{=cKY0DNF6XaE2J diff --git a/docs/examples/getting_started/fortran/CMakeLists.txt b/docs/examples/getting_started/fortran/CMakeLists.txt index f43cb0224..1d05f2544 100644 --- a/docs/examples/getting_started/fortran/CMakeLists.txt +++ b/docs/examples/getting_started/fortran/CMakeLists.txt @@ -3,7 +3,7 @@ project(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran) find_package( Python - COMPONENTS Development.Module NumPy + COMPONENTS Interpreter Development.Module NumPy REQUIRED) # F2PY headers diff --git a/docs/examples/getting_started/nanobind/CMakeLists.txt b/docs/examples/getting_started/nanobind/CMakeLists.txt index 0d0d21ca0..bf30109b5 100644 --- a/docs/examples/getting_started/nanobind/CMakeLists.txt +++ b/docs/examples/getting_started/nanobind/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.15...3.26) project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) -find_package(Python 3.8 REQUIRED COMPONENTS Development.Module) +find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development.Module) find_package(nanobind CONFIG REQUIRED) diff --git a/docs/examples/getting_started/swig/CMakeLists.txt b/docs/examples/getting_started/swig/CMakeLists.txt index bbc87e709..e0c3b349b 100644 --- a/docs/examples/getting_started/swig/CMakeLists.txt +++ b/docs/examples/getting_started/swig/CMakeLists.txt @@ -3,7 +3,7 @@ project(${SKBUILD_PROJECT_NAME} LANGUAGES C) find_package( Python - COMPONENTS Development.Module + COMPONENTS Interpreter Development.Module REQUIRED) find_package( diff --git a/docs/guide/cmakelists.md b/docs/guide/cmakelists.md index bd1cfe587..e75cff82e 100644 --- a/docs/guide/cmakelists.md +++ b/docs/guide/cmakelists.md @@ -26,13 +26,13 @@ Scikit-build-core provides several useful variables: You can directly use FindPython: ```cmake -find_package(Python COMPONENTS Development.Module REQUIRED) +find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) ``` -You always want to find at least the `Development.Module` component. You do not -want to find the entire `Development` component, as that includes -`Development.Embed`, which is not always present and is not related to making -Python extension modules. +You always want to find at least `Interpreter` and the `Module` component of the +`Development` package. You do not want to find the entire `Development` package, +as that include `Embed` component, which is not always present and is not +related to making Python extension modules. If you are making a Limited API / Stable ABI package, you'll need the `Development.SABIModule` component instead (CMake 3.26+). You can use the @@ -129,7 +129,7 @@ When you do that, `${SKBUILD_SABI_COMPONENT}` will be set to remain an empty string otherwise (PyPy). This allows the following idiom: ```cmake -find_package(Python REQUIRED COMPONENTS Development.Module ${SKBUILD_SABI_COMPONENT}) +find_package(Python REQUIRED COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT}) ``` This will require the `Development.SABIModule` component only if diff --git a/docs/guide/crosscompile.md b/docs/guide/crosscompile.md index b35a710f3..b558cc3af 100644 --- a/docs/guide/crosscompile.md +++ b/docs/guide/crosscompile.md @@ -70,10 +70,18 @@ so FindPython will report the wrong values, but pyodide-build will rename the To build for Android, you'll need the following items, all of which will be provided automatically if you use cibuildwheel: -- An Android - [toolchain file](https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html) - which adds the location of the Python headers and libraries to - `CMAKE_FIND_ROOT_PATH`. +- A Python environment in which `sys.platform`, `sysconfig`, etc. all simulate + Android. +- A + [`CMAKE_TOOLCHAIN_FILE`](https://cmake.org/cmake/help/latest/envvar/CMAKE_TOOLCHAIN_FILE.html) + environment variable, pointing to a file which does at least the following: + - Set `CMAKE_SYSTEM_NAME`, `CMAKE_SYSTEM_PROCESSOR` and + `CMAKE_SYSTEM_VERSION`. + - Set `CMAKE_FIND_ROOT_PATH` to the location of the Python headers and + libraries. + - Set `CMAKE_CROSSCOMPILING_EMULATOR` to `/bin/sh -c [["$0" "$@"]]`. This + allows CMake to run Python in the simulated Android environment when policy + [CMP0190](https://cmake.org/cmake/help/latest/policy/CMP0190.html) is + active. - Compiler paths and flags, either in the toolchain file or in environment variables. -- A Python environment which simulates Android. diff --git a/docs/guide/migration_guide.md b/docs/guide/migration_guide.md index b9c35e7ff..599f63dcd 100644 --- a/docs/guide/migration_guide.md +++ b/docs/guide/migration_guide.md @@ -53,7 +53,7 @@ python_extension_module(${LIBRARY}) to ```cmake -find_package(Python COMPONENTS Development.Module REQUIRED) +find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(${LIBRARY} MODULE WITH_SOABI ${FILENAME}) ``` diff --git a/src/scikit_build_core/builder/builder.py b/src/scikit_build_core/builder/builder.py index 045517db8..dde36ddab 100644 --- a/src/scikit_build_core/builder/builder.py +++ b/src/scikit_build_core/builder/builder.py @@ -254,13 +254,11 @@ def configure( cache_config[f"{prefix}_ROOT_DIR"] = Path(sys.prefix) cache_config[f"{prefix}_INCLUDE_DIR"] = python_include_dir cache_config[f"{prefix}_FIND_REGISTRY"] = "NEVER" - # Setting the library location is only needed on some platforms - on - # other platforms it may break FindPython. - if sysconfig.get_platform().startswith(("win", "android")): - if python_library: - cache_config[f"{prefix}_LIBRARY"] = python_library - if python_sabi_library: - cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library + # FindPython may break if this is set - only useful on Windows + if python_library and sysconfig.get_platform().startswith("win"): + cache_config[f"{prefix}_LIBRARY"] = python_library + if python_sabi_library and sysconfig.get_platform().startswith("win"): + cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library if numpy_include_dir: cache_config[f"{prefix}_NumPy_INCLUDE_DIR"] = numpy_include_dir diff --git a/tests/packages/abi3_pyproject_ext/CMakeLists.txt b/tests/packages/abi3_pyproject_ext/CMakeLists.txt index 2422d5fbb..43c6e5bef 100644 --- a/tests/packages/abi3_pyproject_ext/CMakeLists.txt +++ b/tests/packages/abi3_pyproject_ext/CMakeLists.txt @@ -7,7 +7,7 @@ project( find_package( Python - COMPONENTS Development.Module ${SKBUILD_SABI_COMPONENT} + COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT} REQUIRED) if(NOT "${SKBUILD_SABI_VERSION}" STREQUAL "") diff --git a/tests/packages/abi3_setuptools_ext/CMakeLists.txt b/tests/packages/abi3_setuptools_ext/CMakeLists.txt index 880e95d9c..5fc6ad6c7 100644 --- a/tests/packages/abi3_setuptools_ext/CMakeLists.txt +++ b/tests/packages/abi3_setuptools_ext/CMakeLists.txt @@ -7,7 +7,7 @@ project( find_package( Python - COMPONENTS Development.SABIModule + COMPONENTS Interpreter Development.SABIModule REQUIRED) python_add_library(abi3_example MODULE abi3_example.c WITH_SOABI USE_SABI 3.8) diff --git a/tests/packages/broken_fallback/CMakeLists.txt b/tests/packages/broken_fallback/CMakeLists.txt index ed7e57ae0..a0f12eeee 100644 --- a/tests/packages/broken_fallback/CMakeLists.txt +++ b/tests/packages/broken_fallback/CMakeLists.txt @@ -7,7 +7,7 @@ endif() find_package( Python - COMPONENTS Development.Module + COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(example MODULE main.c WITH_SOABI) diff --git a/tests/packages/dynamic_metadata/CMakeLists.txt b/tests/packages/dynamic_metadata/CMakeLists.txt index b11af7d7d..c2e2115a2 100644 --- a/tests/packages/dynamic_metadata/CMakeLists.txt +++ b/tests/packages/dynamic_metadata/CMakeLists.txt @@ -5,7 +5,7 @@ project( LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) -find_package(Python COMPONENTS Development.Module) +find_package(Python COMPONENTS Interpreter Development.Module) set(Python_SOABI ${SKBUILD_SOABI}) python_add_library(_module MODULE src/module.c WITH_SOABI) diff --git a/tests/packages/importlib_editable/CMakeLists.txt b/tests/packages/importlib_editable/CMakeLists.txt index 5a8de63bd..7a96fb06b 100644 --- a/tests/packages/importlib_editable/CMakeLists.txt +++ b/tests/packages/importlib_editable/CMakeLists.txt @@ -3,7 +3,7 @@ project(${SKBUILD_PROJECT_NAME} LANGUAGES C) find_package( Python - COMPONENTS Development.Module + COMPONENTS Interpreter Development.Module REQUIRED) python_add_library(emod MODULE emod.c WITH_SOABI) diff --git a/tests/packages/navigate_editable/CMakeLists.txt b/tests/packages/navigate_editable/CMakeLists.txt index c55006c67..13420b6fe 100644 --- a/tests/packages/navigate_editable/CMakeLists.txt +++ b/tests/packages/navigate_editable/CMakeLists.txt @@ -5,7 +5,7 @@ project( LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) -find_package(Python COMPONENTS Development.Module) +find_package(Python COMPONENTS Interpreter Development.Module) python_add_library(c_module MODULE src/shared_pkg/c_module.c WITH_SOABI) diff --git a/tests/packages/simple_pyproject_ext/CMakeLists.txt b/tests/packages/simple_pyproject_ext/CMakeLists.txt index eeaeddffc..b9a8a304c 100644 --- a/tests/packages/simple_pyproject_ext/CMakeLists.txt +++ b/tests/packages/simple_pyproject_ext/CMakeLists.txt @@ -6,7 +6,7 @@ project( find_package( Python - COMPONENTS Development.Module + COMPONENTS Interpreter Development.Module REQUIRED) find_package(pybind11 CONFIG REQUIRED) diff --git a/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt b/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt index 7aff103ea..703a4ad83 100644 --- a/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt +++ b/tests/packages/simple_pyproject_source_dir/src/CMakeLists.txt @@ -6,7 +6,7 @@ project( find_package( Python - COMPONENTS Development.Module + COMPONENTS Interpreter Development.Module REQUIRED) find_package(pybind11 CONFIG REQUIRED) diff --git a/tests/packages/simplest_c/CMakeLists.txt b/tests/packages/simplest_c/CMakeLists.txt index 6bcf41db6..9d6caab25 100644 --- a/tests/packages/simplest_c/CMakeLists.txt +++ b/tests/packages/simplest_c/CMakeLists.txt @@ -5,7 +5,7 @@ project( LANGUAGES C VERSION ${SKBUILD_PROJECT_VERSION}) -find_package(Python COMPONENTS Development.Module) +find_package(Python COMPONENTS Interpreter Development.Module) python_add_library(_module MODULE src/module.c WITH_SOABI)