diff --git a/src/scikit_build_core/builder/builder.py b/src/scikit_build_core/builder/builder.py index 8d3340cc9..dbac57d7c 100644 --- a/src/scikit_build_core/builder/builder.py +++ b/src/scikit_build_core/builder/builder.py @@ -13,6 +13,7 @@ from ..resources import find_python from .generator import set_environment_for_gen from .sysconfig import ( + get_numpy_include_dir, get_platform, get_python_include_dir, get_python_library, @@ -148,6 +149,7 @@ def configure( get_python_library(self.config.env, abi3=True) if limited_abi else None ) python_include_dir = get_python_include_dir() + numpy_include_dir = get_numpy_include_dir() # Classic Find Python cache_config["PYTHON_EXECUTABLE"] = sys.executable @@ -166,6 +168,8 @@ def configure( 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 cache_config["SKBUILD_SOABI"] = get_soabi(self.config.env, abi3=limited_abi) diff --git a/src/scikit_build_core/builder/sysconfig.py b/src/scikit_build_core/builder/sysconfig.py index 9ddb2ab16..f6decf28a 100644 --- a/src/scikit_build_core/builder/sysconfig.py +++ b/src/scikit_build_core/builder/sysconfig.py @@ -12,7 +12,13 @@ if TYPE_CHECKING: from collections.abc import Mapping -__all__ = ["get_python_include_dir", "get_python_library", "get_cmake_platform"] +__all__ = [ + "get_python_include_dir", + "get_python_library", + "get_cmake_platform", + "get_soabi", + "get_numpy_include_dir", +] TARGET_TO_PLAT = { @@ -154,3 +160,12 @@ def get_soabi(env: Mapping[str, str], *, abi3: bool = False) -> str: assert isinstance(ext_suffix, str) return ext_suffix.rsplit(".", 1)[0].lstrip(".") + + +def get_numpy_include_dir() -> Path | None: + try: + import numpy as np + except ImportError: + return None + + return Path(np.get_include())