adventures.michaelfbryan.com
adventures.michaelfbryan.com copied to clipboard
WIP: Experiment: Safe FFI for Rust ↔ C++
@dtolnay I was thinking of doing a write-up on cxx
and would be keen to get your input!
I've started wrapping the bz2
library (because that's the example the bindgen tutorial uses) but realised wrapping a C library doesn't really show off the library... Are there any relatively simple real-world C++ libraries you've been using during testing?
FFI with C++ is very different from FFI with C so I would flag that C FFI use cases shouldn't be expected to translate well, as you noticed.
The real world use cases I have been experimenting with are Proxygen's server API and Thrift's client API. https://michael-f-bryan.github.io/rust-ffi-guide/basic_request.html + https://michael-f-bryan.github.io/rust-ffi-guide/send_basic.html looks pretty close as a simplified form of the same thing.
Note to self: I think I'll give up on writing bindings for libtorrent
and look for something which builds more reliably (maybe llvm?)
I spent a good 2 evenings trying to get it to build reliably using build.rs
and still haven't been able to link correctly :disappointed: The annoyance was that their default builds generate dynamic libraries, but I want static libraries because I don't want the hassle of distributing *.so
... When a recompile takes 5-10 minutes using all cores (and locking up my laptop in the process) or 30+ minutes, it's kinda hard to iteratively test new cmake
incantations manually then replicate them in build.rs
to see if the changes work.
I was hoping I'd be able to use this to show off how annoying getting a native library to compile and link can be, and the tricks you can use while troubleshooting, but that doesn't really work when there's no happy ending... So I'm going to throw this into the too hard basket.