Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## Unreleased
### Fixed
- Honor `SETUPTOOLS_EXT_SUFFIX` when replacing extension suffixes for limited-API builds.

### Packaging
- Drop support for Python 3.9.
- Bump `setuptools` minimum version to 83.0.
Expand Down
4 changes: 3 additions & 1 deletion setuptools_rust/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,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)] + get_abi3_suffix()

Expand Down
40 changes: 39 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
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 _override_cargo_default_target
from setuptools_rust.build import _override_cargo_default_target, build_rust
from setuptools_rust.extension import RustExtension

NO_ENV = Env(None)

Expand Down Expand Up @@ -35,3 +41,35 @@ def test_adjusted_local_rust_target_macos():
assert (
_override_cargo_default_target("macosx-", NO_ENV) == "x86_64-apple-darwin"
)


@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
Loading