I want to build a C extension for CPython. I could do it traditionally with a setup.py
file. However, for the reasons mentioned in PEP 517, I would prefer a declarative approach using a pyproject.toml
. I understand that setuptools
is the only build backend that can build C extensions on all relevant platforms. In fact, I am unaware of any backend capable of building C extensions at all alongside the outdated distutils
.
Against this background, a common setup.py
would look like this:
from setuptools import setup, Extension
kwargs = dict(
name='mypackage',
# more metadata
ext_modules=[
Extension('mypackage.mymodule', ['lib/mymodule.c',
'lib/mypackage.c',
'lib/myalloc.c'],
include_dirs=['lib'],
py_limited_api=True)])
setup(**kwargs)
Now, the challenge is to put the above into a pyproject.toml
plus a setup.cfg
.
The setuptools
docs suggest a pyproject.toml
like this:
[build-system]
requires = [
"setuptools >=52.0",
'wheel >= 0.36']
build-backend = "setuptools.build_meta"
See
- https://setuptools.readthedocs.io/en/latest/build_meta.html and
- https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html#declarative-config
Further, the actual metadata should go into setup.cfg
. However, I haven't found any explanation on how to translate the ext_modules
kwarg, in particular the Extension()
call, into setup.cfg
syntax.