Skip to content

Commit

Permalink
fix: report correct ABI when cross-compiling (#366)
Browse files Browse the repository at this point in the history
Pulled from #355.

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Jun 10, 2023
1 parent b5940ed commit c27a0a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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"] = (
Expand Down
21 changes: 21 additions & 0 deletions src/scikit_build_core/builder/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(".")

0 comments on commit c27a0a1

Please sign in to comment.