google / autocxx

Tool for safe ergonomic Rust/C++ interop driven from existing C++ headers
https://docs.rs/autocxx
Apache License 2.0
2.13k stars 139 forks source link

Experience: Building bindings for rocksdb c++ API #1073

Open dignifiedquire opened 2 years ago

dignifiedquire commented 2 years ago

I am using this as a collection of challenges that I run into, when building bindings for https://github.com/facebook/rocksdb/. The work is based on https://github.com/rust-rocksdb/rust-rocksdb/ but switching to cxx + autocxx for generating bindings instead of using bindgen to bind to the C api.

I apollogise in advance if this is the wrong place, and happy to put this somewhere else.

The good news: I have gotten things to compile and generate some bindings šŸŽ‰ Now for the challenges

Code lives here: https://github.com/dignifiedquire/rust-rocksdb/tree/autocxx

adetaylor commented 2 years ago

Thanks for the experience report!

The last issue is probably something I encountered a few days ago too and have just finished reducing - there's a failing test case at #1074 which hopefully I'll diagnose and fix in the coming days. (No promises of course).

For the others - yeah, there are lots of kinds of types we don't yet support. As well as gradually increasing support for more kinds of types, it might be that we can instead start to treat unsupported types as opaque types, so you can at least receive them from one function/method and pass them back into another. There's currently no tracking issue for this. In due course I may open one.

dignifiedquire commented 2 years ago

@adetaylor any recommendations on how to work around those, e.g can I auto generate some of the methods that work and fill in the others by hand? or do I have to opt out for the entire class if some things are not supported?

adetaylor commented 2 years ago

With the exception of the last problem, which hopefully is fixed by #1074, you should still be able to generate the rest of the class. It should only reject/ignore specific methods which cause difficulties.

tv42 commented 4 weeks ago

For Pointer pointed to something unsupported in the case of DB::Open, it's an "out parameter" so a pointer to a pointer, see #1361 (no solution at this time).