diff --git a/src/scikit_build_core/builder/builder.py b/src/scikit_build_core/builder/builder.py index 2389c78a..395466a7 100644 --- a/src/scikit_build_core/builder/builder.py +++ b/src/scikit_build_core/builder/builder.py @@ -16,7 +16,12 @@ from ..resources import find_python from ..settings.skbuild_model import ScikitBuildSettings from .generator import set_environment_for_gen -from .sysconfig import get_platform, get_python_include_dir, get_python_library +from .sysconfig import ( + get_platform, + get_python_include_dir, + get_python_library, + get_soabi, +) __all__: list[str] = ["Builder", "get_archs", "archs_to_tags"] @@ -157,23 +162,7 @@ def configure( if python_sabi_library and sysconfig.get_platform().startswith("win"): cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library - if limited_abi: - cache_config["SKBUILD_SOABI"] = ( - "" if sysconfig.get_platform().startswith("win") else "abi3" - ) - else: - # Workaround for bug in PyPy and packaging that is not handled in CMake - # According to PEP 3149, SOABI and EXT_SUFFIX are interchangeable (and - # the latter is much more likely to be correct as it is used elsewhere) - if sys.version_info < (3, 8, 7): - # See https://github.com/python/cpython/issues/84006 - import distutils.sysconfig # pylint: disable=deprecated-module - - ext_suffix = distutils.sysconfig.get_config_var("EXT_SUFFIX") - else: - ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") - assert isinstance(ext_suffix, str) - cache_config["SKBUILD_SOABI"] = ext_suffix.rsplit(".", 1)[0].lstrip(".") + cache_config["SKBUILD_SOABI"] = get_soabi(self.config.env, abi3=limited_abi) # Allow CMakeLists to detect this is supposed to be a limited ABI build cache_config["SKBUILD_SABI_COMPONENT"] = ( diff --git a/src/scikit_build_core/builder/sysconfig.py b/src/scikit_build_core/builder/sysconfig.py index c4d0aa32..aea0afbc 100644 --- a/src/scikit_build_core/builder/sysconfig.py +++ b/src/scikit_build_core/builder/sysconfig.py @@ -130,3 +130,24 @@ def get_cmake_platform(env: Mapping[str, str] | None) -> str: """ plat = get_platform(env) return PLAT_TO_CMAKE.get(plat, plat) + + +def get_soabi(env: Mapping[str, str], *, abi3: bool = False) -> str: + if abi3: + return "" if sysconfig.get_platform().startswith("win") else "abi3" + + # Cross-compile support + setuptools_ext_suffix = env.get("SETUPTOOLS_EXT_SUFFIX", "") + if setuptools_ext_suffix: + return setuptools_ext_suffix.rsplit(".", 1)[0].lstrip(".") + + if sys.version_info < (3, 8, 7): + # See https://github.com/python/cpython/issues/84006 + import distutils.sysconfig # pylint: disable=deprecated-module + + ext_suffix = distutils.sysconfig.get_config_var("EXT_SUFFIX") + else: + ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") + + assert isinstance(ext_suffix, str) + return ext_suffix.rsplit(".", 1)[0].lstrip(".")