Skip to content

Commit 59ad4b1

Browse files
authoredNov 27, 2024··
Update setuptools-rust and fix building abi3 wheels (#17969)
Newer versions of `setuptools-rust` ignore the `py_limited_api` flag to `RustExtension`, and instead read it from `bdist_wheel` config. c.f. https://github.com/PyO3/setuptools-rust/blob/main/CHANGELOG.md#190-2024-02-24
1 parent a58f09a commit 59ad4b1

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed
 

‎build_rust.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# A build script for poetry that adds the rust extension.
22

3+
import itertools
34
import os
45
from typing import Any, Dict
56

7+
from packaging.specifiers import SpecifierSet
68
from setuptools_rust import Binding, RustExtension
79

810

@@ -14,10 +16,27 @@ def build(setup_kwargs: Dict[str, Any]) -> None:
1416
target="synapse.synapse_rust",
1517
path=cargo_toml_path,
1618
binding=Binding.PyO3,
19+
# This flag is a no-op in the latest versions. Instead, we need to
20+
# specify this in the `bdist_wheel` config below.
1721
py_limited_api=True,
1822
# We force always building in release mode, as we can't tell the
1923
# difference between using `poetry` in development vs production.
2024
debug=False,
2125
)
2226
setup_kwargs.setdefault("rust_extensions", []).append(extension)
2327
setup_kwargs["zip_safe"] = False
28+
29+
# We lookup the minimum supported python version by looking at
30+
# `python_requires` (e.g. ">=3.9.0,<4.0.0") and finding the first python
31+
# version that matches. We then convert that into the `py_limited_api` form,
32+
# e.g. cp39 for python 3.9.
33+
py_limited_api: str
34+
python_bounds = SpecifierSet(setup_kwargs["python_requires"])
35+
for minor_version in itertools.count(start=8):
36+
if f"3.{minor_version}.0" in python_bounds:
37+
py_limited_api = f"cp3{minor_version}"
38+
break
39+
40+
setup_kwargs.setdefault("options", {}).setdefault("bdist_wheel", {})[
41+
"py_limited_api"
42+
] = py_limited_api

‎changelog.d/17969.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update setuptools-rust and fix building abi3 wheels in latest version.

‎poetry.lock

+5-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.