Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: report correct ABI when cross-compiling #366

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(".")