Skip to content

Commit 5e13847

Browse files
authored
Merge pull request #197 from davidhewitt/abi3-suffix-bug
build: don't use abi3 lib suffix when py_limited_api unspecified
2 parents 1d31c87 + c3ea296 commit 5e13847

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ jobs:
3434

3535
- run: tox -e mypy
3636

37+
pytest:
38+
runs-on: "ubuntu-latest"
39+
steps:
40+
- uses: actions/checkout@v2
41+
42+
- name: Set up Python ${{ matrix.python-version }}
43+
uses: actions/setup-python@v2
44+
with:
45+
python-version: "3.x"
46+
47+
- run: pip install tox
48+
49+
- run: tox -e pytest
50+
3751
build:
3852
name: ${{ matrix.python-version }} ${{ matrix.platform.os }}-${{ matrix.platform.python-architecture }}
3953
runs-on: ${{ matrix.platform.os }}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Fix regression from `setuptools-rust` 1.1.0 which broke builds for the `x86_64-unknown-linux-musl` target. [#194](https://github.com/PyO3/setuptools-rust/pull/194)
66
- Fix `--target` command line option being unable to take a value. [#195](https://github.com/PyO3/setuptools-rust/pull/195)
77
- Fix regression from `setuptools-rust` 1.0.0 which broke builds on arm64 macos conda builds. [#196](https://github.com/PyO3/setuptools-rust/pull/196)
8+
- Fix regression from `setuptools-rust` 1.1.0 which incorrectly converted library extension suffixes to the "abi3" suffix when `py_limited_api` was unspecified. [#197](https://github.com/PyO3/setuptools-rust/pull/197)
89

910
## 1.1.0 (2021-11-30)
1011
### Added

setuptools_rust/build.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
import sys
88
import sysconfig
9+
from distutils import log
910
from distutils.command.build import build as CommandBuild
1011
from distutils.errors import (
1112
CompileError,
@@ -15,10 +16,11 @@
1516
)
1617
from distutils.sysconfig import get_config_var
1718
from subprocess import check_output
18-
from typing import Dict, List, NamedTuple, Optional, cast
19+
from typing import Dict, List, NamedTuple, Optional, Union, cast
1920

2021
from setuptools.command.build_ext import build_ext as CommandBuildExt
2122
from setuptools.command.build_ext import get_abi3_suffix
23+
from typing_extensions import Literal
2224

2325
from .command import RustCommand
2426
from .extension import Binding, RustExtension, Strip
@@ -298,6 +300,7 @@ def install_extension(
298300
ext_path = self.get_dylib_ext_path(ext, module_name)
299301
os.makedirs(os.path.dirname(ext_path), exist_ok=True)
300302

303+
log.info("Copying rust artifact from %s to %s", dylib_path, ext_path)
301304
shutil.copyfile(dylib_path, ext_path)
302305

303306
if sys.platform != "win32" and not debug_build:
@@ -327,9 +330,7 @@ def get_dylib_ext_path(self, ext: RustExtension, target_fname: str) -> str:
327330

328331
ext_path: str = build_ext.get_ext_fullpath(target_fname)
329332

330-
if (ext.py_limited_api == "auto" and self._py_limited_api()) or (
331-
ext.py_limited_api
332-
):
333+
if _is_py_limited_api(ext.py_limited_api, self._py_limited_api()):
333334
abi3_suffix = get_abi3_suffix()
334335
if abi3_suffix is not None:
335336
so_ext = get_config_var("EXT_SUFFIX")
@@ -683,3 +684,30 @@ def _base_cargo_target_dir(ext: RustExtension) -> str:
683684
target_directory, str
684685
), "expected cargo metadata to return a string target directory"
685686
return target_directory
687+
688+
689+
def _is_py_limited_api(
690+
ext_setting: Literal["auto", True, False],
691+
wheel_setting: Optional[PyLimitedApi],
692+
) -> bool:
693+
"""Returns whether this extension is being built for the limited api.
694+
695+
>>> _is_py_limited_api("auto", None)
696+
False
697+
698+
>>> _is_py_limited_api("auto", True)
699+
True
700+
701+
>>> _is_py_limited_api(True, False)
702+
True
703+
704+
>>> _is_py_limited_api(False, True)
705+
False
706+
"""
707+
708+
# If the extension explicitly states to use py_limited_api or not, use that.
709+
if ext_setting != "auto":
710+
return ext_setting
711+
712+
# "auto" setting - use whether the bdist_wheel option is truthy.
713+
return bool(wheel_setting)

setuptools_rust/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(
113113
script: bool = False,
114114
native: bool = False,
115115
optional: bool = False,
116-
py_limited_api: Union[bool, Literal["auto"]] = "auto",
116+
py_limited_api: Literal["auto", True, False] = "auto",
117117
):
118118
if isinstance(target, dict):
119119
name = "; ".join("%s=%s" % (key, val) for key, val in target.items())

tox.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = mypy
2+
envlist = mypy,pytest
33

44
[testenv:mypy]
55
deps =
@@ -11,3 +11,8 @@ deps =
1111
setenv =
1212
MYPYPATH={toxinidir}
1313
commands = mypy setuptools_rust {posargs}
14+
15+
[testenv:pytest]
16+
deps =
17+
pytest
18+
commands = pytest --doctest-modules setuptools_rust {posargs}

0 commit comments

Comments
 (0)