diff --git a/CHANGELOG.md b/CHANGELOG.md index 743c2354..a7f834cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased ### Fixed +- Honor `SETUPTOOLS_EXT_SUFFIX` when replacing extension suffixes for limited-API builds. - Select PyO3's ABI3T features for limited-API builds targeting free-threaded Python. ### Packaging diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index 228f5418..45e469b6 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -500,7 +500,9 @@ def get_dylib_ext_path(self, ext: RustExtension, target_fname: str) -> str: if _is_py_limited_api(ext.py_limited_api, self._py_limited_api()): abi3_suffix = get_abi3_suffix() if abi3_suffix is not None: - so_ext = get_config_var("EXT_SUFFIX") + so_ext = os.getenv("SETUPTOOLS_EXT_SUFFIX") or get_config_var( + "EXT_SUFFIX" + ) assert isinstance(so_ext, str) ext_path = ext_path[: -len(so_ext)] + abi3_suffix diff --git a/tests/test_build.py b/tests/test_build.py index 59eb215f..2edffac0 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,9 +1,16 @@ +import sysconfig +from pathlib import Path from unittest import mock import pytest +from setuptools import Distribution from setuptools_rust._utils import Env -from setuptools_rust.build import _binding_features, _override_cargo_default_target +from setuptools_rust.build import ( + _binding_features, + _override_cargo_default_target, + build_rust, +) from setuptools_rust.extension import Binding, RustExtension NO_ENV = Env(None) @@ -40,6 +47,38 @@ def test_adjusted_local_rust_target_macos(): ) +@pytest.mark.parametrize( + "ext_suffix", + [None, "", ".so", ".custom.so", ".custom.extension.suffix.longer.than.default.so"], +) +@pytest.mark.parametrize( + "abi3_suffix", + [ + None, + ".abi3.so", + ".abi3-aarch64-linux-gnu.so", + ".abi3t-aarch64-linux-gnu.so", + ".pyd", + ], +) +def test_get_dylib_ext_path_suffix_override(monkeypatch, ext_suffix, abi3_suffix): + if ext_suffix is None: + monkeypatch.delenv("SETUPTOOLS_EXT_SUFFIX", raising=False) + else: + monkeypatch.setenv("SETUPTOOLS_EXT_SUFFIX", ext_suffix) + ext = RustExtension("package.rust") + command = build_rust(Distribution()) + command.plat_name = sysconfig.get_platform() + build_ext = command.get_finalized_command("build_ext") + path = Path(build_ext.get_ext_fullpath(ext.name)) + expected = path.with_name("rust" + abi3_suffix) if abi3_suffix else path + with ( + mock.patch.object(command, "_py_limited_api", return_value="cp39"), + mock.patch("setuptools_rust.build.get_abi3_suffix", return_value=abi3_suffix), + ): + assert Path(command.get_dylib_ext_path(ext, ext.name)) == expected + + @pytest.mark.parametrize( "gil_disabled,py_limited_api,feature", [