pybind11_abseil icon indicating copy to clipboard operation
pybind11_abseil copied to clipboard

Nanobind port

Open jiawen opened this issue 1 year ago • 4 comments

Nanobind looks fairly stable at this point. I recently got nanobind to work with my various Bazel projects and considering doing a port.

Are there any plans to release a nanobind_abseil? If not, I'm happy to take a stab at it in my spare time.

jiawen avatar Sep 05 '23 19:09 jiawen

How similar are the nanobind type_casters to the pybind11 one? Could we just have the nanobind casters inherit from the pybind11 casters?

If not, to not develop a severe case of copy-pasteritis, we'd need to factor out the guts of the type conversions into core from-python and to-python functions, then hook them into the type_caster frameworks for pybind11 and nanobind.

rwgk avatar Sep 06 '23 05:09 rwgk

Interesting perspective. AFAICT, they're identical, except for changing the namespace. But of course there could easily be some odd corners where they differ (in particular, the removal of the holder concept when dealing with smart pointers).

I suppose there's only one way to find out - I will attempt a copy paste and see what happens to the tests.

Re: inheritance - would that not introduce a dependency on pybind11 as well as nanobind? This can easily increase binary size.

jiawen avatar Sep 06 '23 13:09 jiawen

the removal of the holder concept when dealing with smart pointers).

I don't think there is a connection between type_caster_base and other type_casters in this respect.

This can easily increase binary size.

Duplicating all casters & then having to maintain everything twice is far worse. Of course divergence will appear ~immediately, creating a whack-a-mole game. (The "far worse" aspect is probably not very obvious for a single project in isolation, but I'm working with a gigantic codebase in a mono repo, it's very clear then how much human time is lost when something is copy-pasted like nanobind was.)

Re: inheritance - would that not introduce a dependency on pybind11 as well as nanobind?

Another ~easy solution is to factor our generic casters and inherit in the pybind11::detail and nanobind::detail namespaces.

rwgk avatar Sep 06 '23 13:09 rwgk

My 2 cents, Google Benchmark seems to use nanobind... https://github.com/google/benchmark/tree/main/bindings/python

Mizux avatar Jan 12 '24 10:01 Mizux