Skip to content

[WIP] unify pybind11 and nanobind into single-source bindings#5254

Draft
soswow wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
soswow:single-file-nanobind-spike
Draft

[WIP] unify pybind11 and nanobind into single-source bindings#5254
soswow wants to merge 3 commits into
AcademySoftwareFoundation:mainfrom
soswow:single-file-nanobind-spike

Conversation

@soswow

@soswow soswow commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

exploring an idea Anton had about unifiying two python backends into single source since they are so similar.
Not yet ready for review.

Remove the parallel src/python-nanobind/ tree and compile one set of
binding sources per build, selected by OIIO_PYTHON_BINDINGS_BACKEND
(pybind11 or nanobind; drop the "both" mode).

Add py_backend.h with namespace py = pybind11|nanobind and small
oiio_py:: helpers/macros only where the APIs differ. Migrate roi,
typedesc, imagespec, and paramvalue to dual-backend declare_* sources;
fold the former py_oiio_nb helpers and partial module init into
py_oiio.h / py_oiio.cpp behind #if OIIO_PY_BACKEND_NANOBIND.

Install nanobind modules into the same site-packages/OpenImageIO tree
as pybind11 (no separate nanobind package or duplicate tests). Update
CMake, CI, and INSTALL.md accordingly; move MIGRATION_STATUS.md into
src/python/.

Materialize string_view returns as std::string in py_imagespec.cpp so
nanobind can convert them to Python str.

Assisted-by: Cursor / Auto
Signed-off-by: Aleksandr Motsjonov <soswow@gmail.com>
@soswow soswow force-pushed the single-file-nanobind-spike branch from 8f988a1 to 4dbfbc5 Compare June 26, 2026 00:21
…nanobind

Refactor CMake configuration to support both pybind11 and nanobind backends through a single option, OIIO_PYTHON_BINDINGS_BACKEND, allowing for flexible builds. Update CMakeLists.txt to conditionally include source directories based on the selected backend. Modify INSTALL.md to clarify usage instructions for enabling either backend or both. Adjust CI workflows to build with the 'both' option, ensuring compatibility with both binding systems. Update various source files to streamline the integration of nanobind and pybind11, including changes to installation paths and test configurations.

Assisted-by: Cursor / Auto
Signed-off-by: Aleksandr Motsjonov <soswow@gmail.com>
@soswow soswow force-pushed the single-file-nanobind-spike branch from 4dbfbc5 to 2f5a354 Compare June 26, 2026 00:39
Signed-off-by: Aleksandr Motsjonov <soswow@gmail.com>
@soswow soswow force-pushed the single-file-nanobind-spike branch from 907a05f to b388996 Compare June 26, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants