Skip to content

Commit

Permalink
Update setuptools-rust and fix building abi3 wheels (#17969)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
erikjohnston authored Nov 27, 2024
1 parent a58f09a commit 59ad4b1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
19 changes: 19 additions & 0 deletions build_rust.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# A build script for poetry that adds the rust extension.

import itertools
import os
from typing import Any, Dict

from packaging.specifiers import SpecifierSet
from setuptools_rust import Binding, RustExtension


Expand All @@ -14,10 +16,27 @@ def build(setup_kwargs: Dict[str, Any]) -> None:
target="synapse.synapse_rust",
path=cargo_toml_path,
binding=Binding.PyO3,
# This flag is a no-op in the latest versions. Instead, we need to
# specify this in the `bdist_wheel` config below.
py_limited_api=True,
# We force always building in release mode, as we can't tell the
# difference between using `poetry` in development vs production.
debug=False,
)
setup_kwargs.setdefault("rust_extensions", []).append(extension)
setup_kwargs["zip_safe"] = False

# We lookup the minimum supported python version by looking at
# `python_requires` (e.g. ">=3.9.0,<4.0.0") and finding the first python
# version that matches. We then convert that into the `py_limited_api` form,
# e.g. cp39 for python 3.9.
py_limited_api: str
python_bounds = SpecifierSet(setup_kwargs["python_requires"])
for minor_version in itertools.count(start=8):
if f"3.{minor_version}.0" in python_bounds:
py_limited_api = f"cp3{minor_version}"
break

setup_kwargs.setdefault("options", {}).setdefault("bdist_wheel", {})[
"py_limited_api"
] = py_limited_api
1 change: 1 addition & 0 deletions changelog.d/17969.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update setuptools-rust and fix building abi3 wheels in latest version.
11 changes: 5 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 59ad4b1

Please sign in to comment.