Skip to content

Commit

Permalink
Build free-threaded wheels, disable limited API there
Browse files Browse the repository at this point in the history
Co-authored-by: Min RK <151929+minrk@users.noreply.github.com>
  • Loading branch information
hynek and minrk committed Oct 15, 2024
1 parent ba32d5f commit 7c6f0e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ jobs:
- uses: pypa/cibuildwheel@v2.21.2
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:
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import platform
import sys
import sysconfig

from setuptools import setup

Expand All @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions src/_argon2_cffi_bindings/_ffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import platform
import sysconfig

from pathlib import Path

Expand All @@ -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.
Expand Down Expand Up @@ -48,6 +51,7 @@ def _get_target_platform(arch_flags, default):
"_ffi",
"#include <argon2.h>",
libraries=["argon2"],
py_limited_api=limited_api,
)
else:
lib_base = Path("extras") / "libargon2" / "src"
Expand All @@ -56,6 +60,7 @@ def _get_target_platform(arch_flags, default):
"#include <argon2.h>",
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 [
Expand Down

0 comments on commit 7c6f0e6

Please sign in to comment.