Skip to content

Commit 2882600

Browse files
committed
fix: get correct SOABI when cross-compiling
Signed-off-by: Henry Schreiner <[email protected]>
1 parent cd2ef81 commit 2882600

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

src/scikit_build_core/builder/builder.py

+7-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
from ..settings.skbuild_model import ScikitBuildSettings
1818
from .cross_compile import auto_cross_compile_env
1919
from .generator import set_environment_for_gen
20-
from .sysconfig import get_platform, get_python_include_dir, get_python_library
20+
from .sysconfig import (
21+
get_platform,
22+
get_python_include_dir,
23+
get_python_library,
24+
get_soabi,
25+
)
2126

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

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

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

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

src/scikit_build_core/builder/cross_compile.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def auto_cross_compile_env(
3232

3333
@contextlib.contextmanager
3434
def set_cross_compile_env(
35-
ext_suffix: str, env: MutableMapping[str, str]
35+
ext_suffix: str,
36+
env: MutableMapping[str, str],
3637
) -> Generator[None, None, None]:
3738
"""
3839
Generate python file and set environment variables to cross-compile Python

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)