Looking for pointers on writing Rust for C/++ consumption

⚓ Rust    📅 2026-06-26    👤 surdeus    👁️ 1      

surdeus

Hi!

I know this is probably a regular topic and I apologize for starting yet another thread on it, but information overload is actually part of my problem so...

I would like to write a Rust library whose main consumers will, at least in the early days, be C and C++ code. To be more precise, it will be extracted/ported from a Qt library which will be rapidly rebuilt on top of it to avoid maintaining two implementations of the same thing in parallel, so the first consumer of my library will be a Qt library that builds on top of it. This means that right from the beginning, my library will need to be usable from a build system based on qmake which, if I understand correctly (it's been ages since I've last done Qt, I'll need to brush those skills up a bit for this project) is a relatively thin layer on top of CMake these days ?

My question is, what tooling would you recommend today to make this project easier ? I'm particularly interested in...

  • Tools that simplify the process of building and maintaining idiomatic C++ bindings on top of a Rust project. I know I can just expose a handwritten C interface and write a C++ layer on top of it, but that sounds a bit time-consuming and more worryingly also high-maintenance in the long run, so I'm wondering what my other options are. There are so many options for FFI bindings these days (cxx, diplomat, zngur, crubit...) that from a distance it can be a bit hard to see which one is most appropriate for this particular problem.
  • Tools to automatically generate CMake/qmake configuration for this project, ideally supporting vendored builds in addition to regular "find the .so somewhere in /usr" logic. I don't like vendored builds myself, but some of my colleagues are not very expert programmers (which is how we ended up with this Qt-based implementation of a low-level network protocol that we're unhappy about...) and everything I can do to make their life easier will increase the chance of them accepting my unusual language choice and being open to porting more of the stack to Rust in the future.

And if you've been down this road before (or know of someone else who did), I'm also interested in more general feedback. How did that go ? What was unexpectedly easy or hard for you ? Any way I can design my Rust APIs to make them easier to bind from C++ while still feeling reasonably ergonomic from Rust code ? Any particular build tooling or libraries that you would recommend in addition to those that I mentioned above ?

And of course, if you know of a good write-up on this subject, please don't bother with rewriting it in a forum post and just give me a link, that works too !

Many thanks in advance,
Hadrien

1 post - 1 participant

Read full topic

🏷️ Rust_feed