From 1aad4747f9b73b549f39894a27118037ba484c20 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Wed, 30 Jul 2025 08:53:31 +0200 Subject: [PATCH] Add support for free-threaded builds (#70) * Build free-threaded wheels, disable limited API there Co-authored-by: Min RK <151929+minrk@users.noreply.github.com> * Try installing libffi-dev on Linux It's faling due to lack of includes. Presumably because the lack of cffi wheels. * Revert "Try installing libffi-dev on Linux" Does not work. * Merge * Actually build FT * support the free-threaded build of Python 3.14 (#93) * support the free-threaded build of Python 3.14 * attempt to get 3.14t CI to run * Add trove classifier * Add changelog * Add 3.14 trove classifier, too --------- Co-authored-by: Hynek Schlawack --------- Co-authored-by: Min RK <151929+minrk@users.noreply.github.com> Co-authored-by: Nathan Goldbaum --- .github/workflows/ci.yml | 3 ++- .github/workflows/wheels.yml | 2 +- CHANGELOG.md | 3 +++ pyproject.toml | 11 +++++++++-- setup.py | 7 ++++++- src/_argon2_cffi_bindings/_ffi_build.py | 5 +++++ tox.ini | 2 +- 7 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9acab59..c0b2a8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,7 @@ jobs: - "3.12" - "3.13" - "3.14" + - "3.14t" - "pypy-3.9" - "pypy-3.10" @@ -56,7 +57,7 @@ jobs: echo TOX_PYTHON=$V >>$GITHUB_ENV - - run: python -Im tox run -f $TOX_PYTHON + - run: python -Im tox run -e $TOX_PYTHON system-package: runs-on: ubuntu-latest diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index e8c9cde..ace9d90 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -31,7 +31,7 @@ jobs: persist-credentials: false # See pyproject.toml for config. - - uses: pypa/cibuildwheel@v3.0 + - uses: pypa/cibuildwheel@v3.1 - uses: actions/upload-artifact@v4 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index cf9734d..6d27817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,9 @@ Vendoring Argon2 @ [**`f57e61e`**](https://github.com/P-H-C/phc-winner-argon2/co - Official Python 3.12, 3.13, and 3.14 support. No code or packaging changes were necessary. +- Support for free-threading (aka nogil) on Python 3.14. + [#93](https://github.com/hynek/argon2-cffi-bindings/pull/93) + ### Removed diff --git a/pyproject.toml b/pyproject.toml index 1f2e5c2..9a0a001 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,8 @@ requires = [ "setuptools>=77", "setuptools_scm[toml]>=6.2", - "cffi>=1.0.1", + "cffi>=1.0.1; python_version < '3.14'", + "cffi>=2.0.0b1; python_version >= '3.14'", ] build-backend = "setuptools.build_meta" @@ -30,13 +31,18 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: Free Threading", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Security :: Cryptography", "Topic :: Security", "Topic :: Software Development :: Libraries :: Python Modules", ] -dependencies = ["cffi>=1.0.1"] +dependencies = [ + "cffi>=1.0.1; python_version < '3.14'", + "cffi>=2.0.0b1; python_version >= '3.14'", +] [project.optional-dependencies] tests = ["pytest"] @@ -61,6 +67,7 @@ local_scheme = "no-local-version" [tool.cibuildwheel] build = [ "cp39-*" , # We have portable abi3 wheels. + "cp314t-*", # Free-threading / nogil. "pp310-*", # PyPy 3.9 is EOL and doesn't build on Windows anymore. ] enable = ["pypy"] diff --git a/setup.py b/setup.py index e9f4d37..3a402e3 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ import platform import sys +import sysconfig from setuptools import setup @@ -17,7 +18,11 @@ if platform.python_implementation() == "CPython": class BDistWheel(bdist_wheel): def finalize_options(self): - self.py_limited_api = f"cp3{sys.version_info[1]}" + # Free-threaded CPython doesn't support limited API. + if sysconfig.get_config_var("Py_GIL_DISABLED"): + self.py_limited_api = False + else: + self.py_limited_api = f"cp3{sys.version_info[1]}" super().finalize_options() diff --git a/src/_argon2_cffi_bindings/_ffi_build.py b/src/_argon2_cffi_bindings/_ffi_build.py index 975d682..ec4c823 100644 --- a/src/_argon2_cffi_bindings/_ffi_build.py +++ b/src/_argon2_cffi_bindings/_ffi_build.py @@ -2,6 +2,7 @@ import os import platform +import sysconfig from pathlib import Path @@ -11,6 +12,8 @@ from cffi import FFI use_system_argon2 = os.environ.get("ARGON2_CFFI_USE_SYSTEM", "0") == "1" use_sse2 = os.environ.get("ARGON2_CFFI_USE_SSE2", None) windows = platform.system() == "Windows" +# Free-threaded CPython doesn't support limited API. +limited_api = not sysconfig.get_config_var("Py_GIL_DISABLED") # Try to detect cross-compilation. @@ -48,6 +51,7 @@ if use_system_argon2: "_ffi", "#include ", libraries=["argon2"], + py_limited_api=limited_api, ) else: lib_base = Path("extras") / "libargon2" / "src" @@ -56,6 +60,7 @@ else: "#include ", extra_compile_args=["-msse2"] if (optimized and not windows) else None, include_dirs=[str(Path("extras", "libargon2", "include"))], + py_limited_api=limited_api, sources=[ str(lib_base / path) for path in [ diff --git a/tox.ini b/tox.ini index fd9058f..7897751 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ min_version = 4 env_list = pre-commit, cog-{check,render}, - py3{9,10,11,12,13,14}, + py3{9,10,11,12,13,14,14t}, pypy3{9,10}, system-argon2