Skip to content

feat: add mcpplibs.mwrap.nanobind 3.1.0 modules - #2

Merged
Shinonome-Ryoko14 merged 8 commits into
mainfrom
feat/mwrap-nanobind
Dec 2, 2026
Merged

Shinonome-Ryoko14 merged 8 commits into
mainfrom
feat/mwrap-nanobind

Conversation

@Shinonome-Ryoko14

Copy link
Copy Markdown
Collaborator

Summary

Implements mcpplibs.mwrap.nanobind (3.1.0), a thin C++23 module wrapper over wjakob/nanobind v3.1.0, following mcpp-index/docs/mwrap.md, mwrap-readme.md, and mwrap-licensing.md.

  • Supersedes #1 using an in-repo branch (feat/mwrap-nanobind) so GitHub Actions CI runs directly and mcpp-plugins (rules-python) can cross-validate against this branch via git + branch.
  • Prerequisite mcpplibs/mcpp-index#933 (compat.robin-map@1.4.1 and compat.nanobind@3.1.0) is merged.
  • Merge gate (per @Sunrisepeak): hold merge until multi-platform CI (Linux GCC 16 / LLVM 23, macOS, Windows) is green and cross-validation with mcpp-plugins (rules-python) completes.

Highlights

  • Thin wrapper, zero vendored C++ source: depends on compat.nanobind = "3.1.0" and compiles src/nb_runtime.cpp (#include <mcpp_nanobind_combined.hpp>) behind the default runtime feature (consumers needing custom ABI flags such as Py_LIMITED_API / NB_SHARED can set default-features = false).
  • Module surface:
    • mcpplibs.mwrap.nanobind — public root re-exporting _core, macros, stl, and ndarray
    • mcpplibs.mwrap.nanobind.stl — STL type_caster specializations (string, vector, map, unordered_map, optional, variant, function, smart pointers, filesystem, chrono, etc.)
    • mcpplibs.mwrap.nanobind.ndarray — nb::ndarray, DLPack types, contiguity/device/framework tags, nb::dtype
    • mcpplibs.mwrap.nanobind.macros — NB_VERSION_* as inline constexpr in mcpplibs::mwrap::nanobind::macros
    • mcpplibs.mwrap.nanobind.operators — nb::self and ADL operator helpers (kept as an explicit opt-in module rather than implicitly re-exported by the root to avoid GCC 16.1/16.2 gen_enumeration_type_die debug-info ICE when expanding operator templates; full ADL audit runs on Clang 23)
    • <mwrap/nanobind/macros.hpp> — companion header for preprocessor macros (NB_MODULE, NB_TRAMPOLINE, NB_OVERRIDE*, NB_MAKE_OPAQUE), documented and tested with include-before-import
  • Python SDK discovery (build.mcpp):
    • Resolution order: MCPP_PYTHON_INCLUDE_DIR → xim:python → MCPP_PYTHON_EXECUTABLE / VIRTUAL_ENV / PATH → clear diagnostic
    • Normal library builds only add a private include_dir and never leak link_lib("python...") into consumers (required for Linux CPython .so extensions); only the package-internal tests feature links the embedding library
  • Runnable default template & licensing:
    • templates/embed/ uses unquoted dotted key {{self.name}} = "{{self.version}}", builds cleanly under --strict, and runs an embedded NB_MODULE demo
    • Apache-2.0 wrapper LICENSE + NOTICE (mcpp-community), byte-pinned upstream/nanobind/{LICENSE,README.md} with upstream/** -text, upstream/documents.json, tools/check_documents.py, and [[runtime.deploy]]
    • Bilingual README.md / README.zh.md + docs/usage.md + 3-platform CI (Linux GCC 16 & LLVM 23, macOS LLVM 23, Windows LLVM 23)

Local Verification

  • Linux (WSL2, GCC 16 & LLVM 23): tools/check_documents.py, mcpp build --strict, mcpp test (4/4: behavior, ndarray, operators, side_header), tools/test_template.py (--strict build + run) — all PASS
  • Windows (mcpp 2026.11.23.1, llvm@23.1.3, MSVC 14.44, Windows SDK 10.0.26100.0): tools/check_documents.py, mcpp build --strict, mcpp test (4/4 including Clang ADL audit) — all PASS

Thin C++23 module wrapper over compat.nanobind 3.1.0: core API, STL casters, ndarray/DLPack, operators and version constants. Adds the default embed template, GCC/LLVM tests, byte-pinned upstream documents and runtime license deployment.
Match only python3XX.lib on Windows, probe both venv and standalone interpreter prefixes, sort include/python3.* by numeric minor, and correct the README literal/typo examples.
Comment thread tests/behavior.cpp Resolved
Comment thread tests/behavior.cpp Resolved
Move the four embedded-Python tests to mcpplibs.mtest UTest cases with one interpreter lifetime per process. Remove standard headers that import std provides, build both build.mcpp files with import std, and document the remaining hard-required includes and ndarray initializer_list.
nanobind/ndarray.h is included in the global module fragment, so its own initializer_list inclusion already belongs there. Verified with GCC 16.2.0 and Clang 23.1.3.
Comment thread templates/embed/build.mcpp Resolved
Comment thread tests/support/python_embed.cppm Resolved
Replace tests/python_embed.hpp with tests/support/python_embed.cppm, compiled
only by the tests feature and never exported. Drop the test-side Python.h
include so behavior/ndarray/side_header keep one side-header include and
operators has none.

Use mcpp::target_os() instead of _WIN32 in both build.mcpp files and the
embed template, and use PyConfig_SetBytesString on every platform.

@Sunrisepeak Sunrisepeak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Shinonome-Ryoko14
Shinonome-Ryoko14 merged commit 89d48f1 into main Dec 2, 2026
4 checks passed
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