Migrate pybind11 to nanobind - #1086
Merged
justinchuby merged 3 commits intoJul 1, 2026
Merged
Conversation
- replace pybind11 with nanobind v2.13.0 in CMake and dependency manifest - port pyop bindings and C API wrappers from pybind11 APIs to nanobind APIs - update wheel build matrices to build cp310/cp311/cp312 only for abi3 strategy - add py_limited_api metadata and wheel tagging for cp312+ stable ABI - add abi3audit checks (cp312 baseline) in cibuildwheel test scripts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- enable py_limited_api only on CPython >= 3.12 and non-free-threaded runtimes - define Py_LIMITED_API=0x030C0000 only when limited ABI is enabled - gate bdist_wheel cp312 abi3 tagging with the same runtime checks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates the project’s Python extension bindings and build integration from pybind11 to nanobind, while also tightening the supported Python versions and improving limited-API (abi3) wheel handling across build/CI.
Changes:
- Replaced
pybind11-based bindings withnanobindin the Python custom-op layer (pyop/*) and updated module initialization. - Updated CMake to fetch/build with
nanobindand modernized Python discovery viafind_package(Python ...). - Dropped older Python versions from CI wheel matrices and added limited-API wheel tagging plus abi3 verification in wheel test scripts.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/test_cibuildwheel.sh | Adds import smoke-test and runs abi3audit for Python ≥ 3.12. |
| tools/test_cibuildwheel.bat | Windows equivalent of the wheel import check + abi3audit. |
| tools/ci_build/github/azure-pipeline/wheels_macos.yml | Removes cp313 from wheel build matrix. |
| tools/ci_build/github/azure-pipeline/wheels_linux.yml | Removes cp313 from wheel build matrix. |
| tools/ci_build/github/azure-pipeline/templates/windows-build-stage.yml | Removes cp313 from wheel build matrix. |
| setup.py | Adds python_requires>=3.10 and marks the extension as limited-API when applicable. |
| pyop/pykernel.h | Updates binding API surface to accept nanobind::module_. |
| pyop/pyfunc.cc | Migrates bindings and NumPy interop from pybind11 to nanobind. |
| pyop/py_c_api.cc | Migrates C-API bindings and NumPy interop from pybind11 to nanobind. |
| cmake/externals/pybind11.cmake | Removes pybind11 FetchContent external. |
| cmake/externals/nanobind.cmake | Adds nanobind FetchContent external. |
| cmake/ext_python.cmake | Switches Python discovery to Python package and builds the extension with nanobind_add_module. |
| cgmanifest.json | Updates dependency tracking from pybind11 to nanobind. |
| .pyproject/cmdclass.py | Adds a custom bdist_wheel to mark CPython ≥ 3.12 wheels as limited-API. |
| .pipelines/wheels_win32.yml | Drops older Python versions from wheel build matrix. |
| .pipelines/wheels_macos.yml | Drops older Python versions from wheel build matrix. |
| .pipelines/wheels_linux.yml | Drops older Python versions from wheel build matrix. |
| .pipelines/templates/onebranch-windows-build-stage.yml | Drops older Python versions from wheel build matrix. |
| .github/workflows/linux_arm64_wheel.yaml | Updates wheel build workflow to Python 3.10–3.12 only. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
133
to
136
| std::vector<std::size_t> npy_dims; | ||
| for (auto n = num_dims - num_dims; n < num_dims; ++n) { | ||
| npy_dims.push_back(shape[n]); | ||
| } |
Contributor
Author
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
Merging into a branch in this repo first to facilitate copilot edits |
justinchuby
merged commit Jul 1, 2026
511e901
into
microsoft:justinchu/nanobind
4 of 37 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request makes several significant changes to the Python extension build and C++/Python interop layers. The most important update is the migration from
pybind11tonanobindfor Python bindings, which affects both the C++ code and the build system. It also updates the supported Python versions for builds and wheels, and introduces improved handling for Python limited API wheels.Migration from pybind11 to nanobind:
pybind11withnanobindin C++ source files such aspyop/py_c_api.ccandpyop/pyfunc.cc, updating type aliases, includes, and APIs accordingly. This includes changes to type conversions, error handling, and NumPy array creation. [1] [2] [3] [4] [5] [6] [7] [8]nanobindinstead ofpybind11, including removing thepybind11external and adding a newnanobind.cmakemodule. The extension module is now built withnanobind_add_moduleand linked accordingly. [1] [2] [3] [4]Build and wheel configuration updates:
Wheel build improvements:
bdist_wheelcommand to ensure that wheels built with Python 3.12 and above are marked as limited API (cp312), improving compatibility. [1] [2]CMake and Python discovery improvements:
cmake/ext_python.cmaketo use the modernPythonpackage instead ofPython3, improving reliability and future-proofing the build process.Dependency tracking:
nanobindrepository and its current version, replacing the previous reference topybind11.