Abstract
Building binary extensions is easier than ever thanks to several key libraries. Pybind11 provides a natural C++ language for extensions without requiring pre-processing or special dependencies. Scikit-build ties the premier C++ build system, CMake, into the Python extension build process. And cibuildwheel makes it easy to build highly compatible wheels for over 80 different platforms using CI or on your local machine.
Introduction
Historically, writing and distributing C++ extensions for Python was a painful process. Developers faced two primary hurdles: the interface gap and the distribution nightmare. Bridging C++ and Python often required complex boilerplate or external domain-specific languages like SWIG. Furthermore, distributing compiled code (binary wheels) is notoriously difficult due to the variety of operating systems, CPU architectures, and library versions—often referred to as the "manylinux" problem. Legacy tools like distutils and setuptools were not designed to handle modern C++ standards or complex build dependencies efficiently.
This paper outlines a modern, robust ecosystem for building and distributing Python binary extensions using three core tools: pybind11, scikit-build, and cibuildwheel. Together, these tools lower the barrier to entry for high-performance computing in Python, moving the community away from legacy "hacks" toward standardized, declarative packaging.
The "Holy Trinity" of Extension Tooling
The authors present a unified stack that addresses these issues, making it possible to write "header-only" bindings and ship them to users on over 80 different platform combinations with minimal manual effort.
1. pybind11: Seamless Interfacing
Pybind11 is a header-only library that exposes C++ types in Python and vice-versa. Unlike its predecessors, it uses pure C++11 (and newer) introspection without requiring a pre-compilation step or a new language. It allows for "natural" C++ code to be bound to Python with minimal syntax.
2. scikit-build: The CMake Bridge
This acts as a bridge between Python's packaging standards and CMake, the most widely used build system for C++. It allows developers to leverage CMake’s power (parallel compiles, custom library support) while remaining compatible with Python's pip and pyproject.toml ecosystem.
3. cibuildwheel: Automated Distribution
A specialized tool that runs in Continuous Integration (CI) environments, cibuildwheel handles the heavy lifting of setting up isolated environments (like Docker containers for Linux or specific SDKs for macOS/Windows). It builds "wheels" that are guaranteed to work on the end-user's machine, abstracting away the complexity of the manylinux standards.
Evolution and Modernization
The ecosystem is moving toward declarative configuration, specifically the shift to pyproject.toml (PEPs 517/518/621). This separates build requirements from project metadata, making builds more reproducible and less prone to "dependency hell."
A significant development is the introduction of nanobind, a leaner successor to pybind11. By targeting C++17 and Python 3.8+, it significantly reduces binary size and compilation time by stripping away support for legacy versions. Furthermore, a major effort funded by NSF Award 2209877 is underway to rewrite scikit-build. The new "scikit-build-core" aims to remove the legacy dependency on setuptools and distutils entirely, providing a "distutils-free" path for Python 3.12 and beyond.
Impact and Results
The adoption of these tools has been widespread. pybind11 is now the backbone of major libraries like SciPy and PyTorch, while cibuildwheel is used by foundational packages including Matplotlib, Mypy, and Scikit-learn.
Key achievements include:
- Performance Gains:
nanobindproduces binaries that are significantly smaller and faster than those produced bypybind11orboost::python. - Platform Coverage:
cibuildwheelsuccessfully automates builds for over 80 platform combinations, including Apple Silicon (M1/M2) and Windows ARM architectures. - Ecosystem Stability: The NSF funding ensures the long-term stability and modernization of this build stack.
Future Directions
Despite these successes, challenges remain. pybind11 can be slow to compile due to heavy template usage; future work includes "Optional Precompilation" to speed up development cycles. The team is also working on a "smart holder" branch to improve how C++ smart pointers (std::unique_ptr, std::shared_ptr) are passed between languages safely.
While Windows ARM support is experimental, cross-compilation for Linux remains a hurdle due to technical limitations in the Red Hat developer toolkits. Finally, the transition to the pure scikit-build-core is expected to be a multi-year roadmap spanning 2023-2025.
Summary updated