Skip to content

Commit 203c826

Browse files
clin1234indygreg
authored andcommitted
build: update cffi versions and compatibility for 3.14 and nogil
We need cffi 2.0 for nogil support. cffi 2.0 only implements nogil support on 3.14+, so we need to disable cffi for nogil on 3.13. Closes #274.
1 parent 99ab56d commit 203c826

4 files changed

Lines changed: 138 additions & 11 deletions

File tree

docs/news.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Version History
4141
13.10 through 18.04, Fedora 19 to 28, and RHEL/Centos 7. However, in
4242
practice most platforms don't container newer glibc symbols and are still
4343
ABI compatible with ``manylinux2014``.
44+
* We now require cffi >= 2.0.0b on Python 3.14. <3.14 still requires 1.17.
45+
(#274)
46+
* The cffi backend is now automatically disabled for free-threaded builds
47+
on Python <3.14, as cffi didn't implement free-threaded support until
48+
the 2.0 release. (#274)
4449

4550
0.24.0 (released 2025-08-17)
4651
============================

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ dependencies = []
2424

2525
[project.optional-dependencies]
2626
cffi = [
27-
'cffi>=1.17 ; python_version >= "3.13" and platform_python_implementation != "PyPy"',
27+
"cffi~=1.17; platform_python_implementation != 'PyPy' and python_version < '3.14'",
28+
"cffi>=2.0.0b; platform_python_implementation != 'PyPy' and python_version >= '3.14'",
2829
]
2930

3031
[project.urls]
@@ -33,15 +34,17 @@ Documentation = "https://python-zstandard.readthedocs.io/en/latest/"
3334

3435
[build-system]
3536
requires = [
36-
"cffi>=1.17.0 ; platform_python_implementation != 'PyPy'",
37+
"cffi~=1.17; platform_python_implementation != 'PyPy' and python_version < '3.14'",
38+
"cffi>=2.0.0b; platform_python_implementation != 'PyPy' and python_version >= '3.14'",
3739
"packaging",
3840
"setuptools>=77.0.0",
3941
]
4042
build-backend = "setuptools.build_meta"
4143

4244
[dependency-groups]
4345
dev = [
44-
"cffi>=1.17.0 ; platform_python_implementation != 'PyPy'",
46+
"cffi~=1.17; platform_python_implementation != 'PyPy' and python_version < '3.14'",
47+
"cffi>=2.0.0b; platform_python_implementation != 'PyPy' and python_version >= '3.14'",
4548
"hypothesis==6.111.0",
4649
"mypy>=1.17.1",
4750
"pytest>=8.4.1",

setup.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import platform
1212
import sys
13+
import sysconfig
1314

1415
from packaging.version import Version
1516
from setuptools import setup
@@ -24,7 +25,8 @@
2425
# garbage collection pitfalls.
2526
# Require 1.17 everywhere so we don't have to think about supporting older
2627
# versions.
27-
MINIMUM_CFFI_VERSION = "1.17"
28+
# Require 2.0 for Python 3.14+ to add improved free-threading support
29+
MINIMUM_CFFI_VERSION = "2.0" if sys.version_info[0:2] >= (3, 14) else "1.17"
2830

2931
ext_suffix = os.environ.get("SETUPTOOLS_EXT_SUFFIX")
3032
if ext_suffix:
@@ -83,6 +85,16 @@
8385
if platform.python_implementation() == "PyPy":
8486
C_BACKEND = False
8587

88+
# cffi 2.0 only introduced no-GIL support for 3.14+.
89+
if sys.version_info[0:2] < (3, 14) and sysconfig.get_config_var(
90+
"Py_GIL_DISABLED"
91+
):
92+
print(
93+
"cffi backend requires 3.14+ for nogil Python; disabling cffi",
94+
file=sys.stderr,
95+
)
96+
CFFI_BACKEND = False
97+
8698
if "--legacy" in sys.argv:
8799
SUPPORT_LEGACY = True
88100
sys.argv.remove("--legacy")

0 commit comments

Comments
 (0)