Skip to content

Commit c27a0a1

Browse files
authored
fix: report correct ABI when cross-compiling (#366)
Pulled from #355. Signed-off-by: Henry Schreiner <[email protected]>
1 parent b5940ed commit c27a0a1

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

src/scikit_build_core/builder/builder.py

+7-18
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
from ..resources import find_python
1717
from ..settings.skbuild_model import ScikitBuildSettings
1818
from .generator import set_environment_for_gen
19-
from .sysconfig import get_platform, get_python_include_dir, get_python_library
19+
from .sysconfig import (
20+
get_platform,
21+
get_python_include_dir,
22+
get_python_library,
23+
get_soabi,
24+
)
2025

2126
__all__: list[str] = ["Builder", "get_archs", "archs_to_tags"]
2227

@@ -157,23 +162,7 @@ def configure(
157162
if python_sabi_library and sysconfig.get_platform().startswith("win"):
158163
cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library
159164

160-
if limited_abi:
161-
cache_config["SKBUILD_SOABI"] = (
162-
"" if sysconfig.get_platform().startswith("win") else "abi3"
163-
)
164-
else:
165-
# Workaround for bug in PyPy and packaging that is not handled in CMake
166-
# According to PEP 3149, SOABI and EXT_SUFFIX are interchangeable (and
167-
# the latter is much more likely to be correct as it is used elsewhere)
168-
if sys.version_info < (3, 8, 7):
169-
# See https://github.com/python/cpython/issues/84006
170-
import distutils.sysconfig # pylint: disable=deprecated-module
171-
172-
ext_suffix = distutils.sysconfig.get_config_var("EXT_SUFFIX")
173-
else:
174-
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
175-
assert isinstance(ext_suffix, str)
176-
cache_config["SKBUILD_SOABI"] = ext_suffix.rsplit(".", 1)[0].lstrip(".")
165+
cache_config["SKBUILD_SOABI"] = get_soabi(self.config.env, abi3=limited_abi)
177166

178167
# Allow CMakeLists to detect this is supposed to be a limited ABI build
179168
cache_config["SKBUILD_SABI_COMPONENT"] = (

src/scikit_build_core/builder/sysconfig.py

+21
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,24 @@ def get_cmake_platform(env: Mapping[str, str] | None) -> str:
130130
"""
131131
plat = get_platform(env)
132132
return PLAT_TO_CMAKE.get(plat, plat)
133+
134+
135+
def get_soabi(env: Mapping[str, str], *, abi3: bool = False) -> str:
136+
if abi3:
137+
return "" if sysconfig.get_platform().startswith("win") else "abi3"
138+
139+
# Cross-compile support
140+
setuptools_ext_suffix = env.get("SETUPTOOLS_EXT_SUFFIX", "")
141+
if setuptools_ext_suffix:
142+
return setuptools_ext_suffix.rsplit(".", 1)[0].lstrip(".")
143+
144+
if sys.version_info < (3, 8, 7):
145+
# See https://github.com/python/cpython/issues/84006
146+
import distutils.sysconfig # pylint: disable=deprecated-module
147+
148+
ext_suffix = distutils.sysconfig.get_config_var("EXT_SUFFIX")
149+
else:
150+
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
151+
152+
assert isinstance(ext_suffix, str)
153+
return ext_suffix.rsplit(".", 1)[0].lstrip(".")

0 commit comments

Comments
 (0)