Build backends when your package is not pure Python

If your package is only .py files, you should read Build backends for pure Python packages. That post covers hatchling, uv-build, flit-core, and when to stay on setuptools.

Many real packages are not that simple. In AI and accelerator stacks, a lot of Python packages wrap code written in Rust, C, C++, Cython, or similar languages. That code must compile when you build the wheel. The packaging story is harder, and the pure-Python checklist is not enough.

This post is for people who need Python bindings around non-Python code. It walks language by language (and toolchain by toolchain) and names a build backend that fits.

What changes when you compile

A pure-Python wheel is often tagged py3-none-any: any Python 3, no native ABI, any platform. A compiled extension usually produces a platform wheel. The tag names an OS, CPU, and often a Python ABI. Installers must pick a wheel that matches the machine.

You still declare a build backend in pyproject.toml. Frontends such as uv build, pip, or python -m build create a temporary build environment and call the backend. The backend is what runs Cargo, Meson, or CMake and packs the result. For more on that split, see my other blogs about How Python Packages Build Themselves.

For the compiled code, your native build system usually picks the backend. Here is what PyPA’s tool recommendations are.

You have Backend
Rust maturin
Meson (meson.build) meson-python
CMake (CMakeLists.txt) scikit-build-core
Cython (.pyx) meson-python or scikit-build-core
Working setuptools C build can stay

Rust

If the native code is Rust, use maturin. It drives Cargo and is the usual choice for Rust extensions.

Most of those projects use PyO3, a Rust library for writing Python extension modules. You write Rust, expose it to Python, and maturin turns that into a wheel. Maturin also supports cffi and mixed Rust and Python trees. It can build abi3-friendly wheels when you ask for them.

[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

Use maturin when Cargo is already your build system. Do not pick it for a CMake or Meson project just because some of the stack is “systems code.”

C, C++, or Fortran with Meson

If you already have (or want) a Meson build, use meson-python. It is built for compiled packages: C, C++, Fortran, Cython, and other languages Meson supports. NumPy and SciPy moved to Meson for faster incremental and parallel builds.

[build-system]
requires = ["meson-python>=0.17", "meson>=1.6"]
build-backend = "mesonpy"

Choose meson-python when meson.build is the source of truth. If your project is already a large CMake tree, prefer scikit-build-core instead of rewriting the build in Meson only to change the Python backend.

C, C++, or CUDA with CMake

If you already have CMake (CMakeLists.txt), use scikit-build-core. scikit-build-core is the usual backend when CMake builds your native code. It runs CMake (often with Ninja), works well for C and C++, Fortran, Cython, nanobind, and many CUDA or Torch-style find_package layouts.

[build-system]
requires = ["scikit-build-core>=1.0"]
build-backend = "scikit_build_core.build"

You do not need to list cmake or ninja in requires for the common case. scikit-build-core can install them when the system copies are too old. Prefer this backend when CMake already builds your native library.

Cython

Cython (.pyx files) needs a modern backend for new projects. Both meson-python and scikit-build-core support Cython well. Pick by build system: Meson means meson-python; CMake means scikit-build-core. Meson is common in the scientific Python stack.

I won’t suggest starting a new Cython project on setuptools by default. Cython’s own docs steer new work toward modern backends.

Golang and other prebuilt native libraries

There is no widely used “maturin for Go.” Some teams use setuptools plugins, cgo, or a small C shim. Others compile a .so / .dll / .dylib outside Python and ship it inside the package.

If you only vendor a prebuilt binary and load it with ctypes or cffi, you must still ship a platform wheel, not py3-none-any. A plain setuptools project can look “pure Python” and tag the wheel wrong. Forcing the right platform layout is a special case and easy to get wrong. That recipe is out of scope here.

For a new binding you control end to end, prefer maturin, meson-python, or scikit-build-core instead of a one-off Go packaging path.

Already on setuptools with a working C extension

setuptools still builds C and C++ extensions, and it remains a valid PEP 517 backend. What is deprecated is running python setup.py sdist or bdist_wheel by hand. Use a frontend.

For a new compiled project, prefer the language-appropriate backend above. Setuptools changes often and is a build dependency for a huge share of PyPI; narrower backends usually give clearer defaults for what goes in the wheel.

For an existing setuptools C extension that already builds and publishes cleanly, there is no emergency. Migrate when you need Meson or CMake features, better parallel builds, or a simpler one-file pyproject.toml, not on principle alone. Switching backends later is usually a config change plus a real port of the native build, which is the expensive part.

Metadata still matters

Compiled or not, most [project] fields should stay static when you can write them as literals. When the version must come from git tags or from the native build (Cargo, meson.build, a CMake provider), mark those fields dynamic and configure the backend. That choice does not replace the toolchain decision; it sits beside it. For pure-Python metadata habits, see the checklist and the pure-Python backend post.

Takeaway

If the package is only Python, use Build backends for pure Python packages. If you ship bindings around non-Python code, name the language and build system first, then pick the backend: maturin for Rust, meson-python for Meson, scikit-build-core for CMake, and a careful platform-wheel story for prebuilt binaries. Build with a frontend, install the wheel on a matching platform, and confirm the import loads the native module.

Further reading

Leave a Reply