From ffe98fff9bc89e7c3fd67dfd514d0a64d9b69799 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Tue, 8 Oct 2024 08:09:35 +0200 Subject: [PATCH] Build free-threaded wheels, disable limited API there Co-authored-by: Min RK <151929+minrk@users.noreply.github.com> --- .github/workflows/wheels.yml | 4 +++- setup.py | 7 ++++++- src/_argon2_cffi_bindings/_ffi_build.py | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 7b0336a..c1e20f5 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -39,12 +39,14 @@ jobs: - uses: pypa/cibuildwheel@v2 env: # Only build CPython 3.9, because we have portable abi3 wheels. - CIBW_BUILD: "cp39-* cp39-win_arm64" + # Only exception are free-threaded builds. + CIBW_BUILD: "cp39-* cp39-win_arm64 cp313t-*" CIBW_ARCHS_LINUX: "auto aarch64" CIBW_ARCHS_MACOS: "auto universal2" CIBW_TEST_COMMAND: python -Ic "from _argon2_cffi_bindings import ffi, lib; print(lib.ARGON2_VERSION_NUMBER)" # https://github.com/pypa/cibuildwheel/pull/1169 CIBW_TEST_SKIP: "*-macosx_universal2:arm64" + CIBW_FREE_THREADED_SUPPORT: true - uses: actions/upload-artifact@v4 with: 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 @@ 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 0d4d0be..3934d9d 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 @@ 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 @@ def _get_target_platform(arch_flags, default): "_ffi", "#include ", libraries=["argon2"], + py_limited_api=limited_api, ) else: lib_base = Path("extras") / "libargon2" / "src" @@ -56,6 +60,7 @@ def _get_target_platform(arch_flags, default): "#include ", extra_compile_args=["-msse2"] if (optimized and not windows) else None, include_dirs=[os.path.join("extras", "libargon2", "include")], + py_limited_api=limited_api, sources=[ str(lib_base / path) for path in [