Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ backends = [
"scikit-build-core",
"setuptools @ git+https://github.com/ngoldbaum/setuptools@abi3.abi3t",
"packaging @ git+https://github.com/ngoldbaum/packaging@abi3.abi3t",
"cffi @ git+https://github.com/ngoldbaum/cffi@abi3t.abi3",
]
build-tools = [
"cython @ git+https://github.com/cython/cython@freethreading-limited-api-preview",
Expand Down
3 changes: 3 additions & 0 deletions setuptools/cffi/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
recursive-include src/limited *.py
include setup.py
include pyproject.toml
14 changes: 14 additions & 0 deletions setuptools/cffi/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools@git+https://github.com/ngoldbaum/setuptools@abi3.abi3t",
"packaging@git+https://github.com/ngoldbaum/packaging@abi3.abi3t",
"cffi@git+https://github.com/ngoldbaum/cffi@abi3t.abi3",
]

[project]
name = "limited-api"
version = "1.2.3"
dependencies = [
"cffi@git+https://github.com/ngoldbaum/cffi@abi3t.abi3",
]
2 changes: 2 additions & 0 deletions setuptools/cffi/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
py_limited_api = cp315
7 changes: 7 additions & 0 deletions setuptools/cffi/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CFFI doesn't support declarative setup for this
# see https://github.com/python-cffi/cffi/issues/55
from setuptools import setup

setup(
cffi_modules=["src/limited/gen_limited.py:ffibuilder"],
)
3 changes: 3 additions & 0 deletions setuptools/cffi/src/limited/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._limited import lib

add = lib.add
24 changes: 24 additions & 0 deletions setuptools/cffi/src/limited/gen_limited.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from cffi import FFI

ffibuilder = FFI()

ffibuilder.set_source(
"limited._limited",
r"""
#include <stdint.h>

static int64_t add(int64_t a, int64_t b) {
return a + b;
}
""",
libraries=[],
)

ffibuilder.cdef(
r"""
int64_t add(int64_t a, int64_t b);
"""
)

if __name__ == "__main__":
ffibuilder.compile(verbose=True)
10 changes: 8 additions & 2 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@

import limited

# if the build system created a package, import the actual extension
if hasattr(limited, "__path__"):
from limited import limited
if hasattr(limited, "lib"):
# limited.lib is present for CFFI. We had to create a Python wrapper package
# because CFFI doesn't directly expose wrapped functions in the top-level
# namespace of an extension module
limited = limited._limited
else:
# if the build system created a package, import the actual extension
from limited import limited

assert ".abi3" in Path(limited.__file__).name, (
f"{limited.__file__} is not abi3 extension")
Expand Down
Loading