C++ Bindings for the matrix-rust-sdk crate

⚓ Rust    📅 2025-10-13    👤 surdeus    👁️ 1      

surdeus

Hello everyone,

We're trying to implement a Matrix client in a QT application. Our current approach is based on the official matrix-rust-sdk, as it's one of the officially supported SDKs. Therefore, we'd like to create C++ bindings for the matrix-rust-sdk crate and have tested various approaches with different libraries. A big difficulty is that the matrix-rust-sdk is heavily based on async. Below are the approaches we have already tested and the problems we encountered.

cbindgen/manually writing header files: Although this works on paper, this is an impractical approach because we have to manually wrap and convert between C++ and Rust types such as strings or vecs. This is a lot of work and, above all, very error-prone.

cxx: Currently, async and callbacks (function pointers) are not supported from C++ to Rust. This forces us to wrap the asynchronous code on the Rust side with, for example, tokio::Runtime::block_on and execute it synchronously. This requires the implementation of multithreading on the C++ side. However, this also raises the question of how this is implemented on the Rust side so that the code is thread-safe, especially if we have a single static, mutable client. It is also not entirely clear how the Matrix client's event queue can best be implemented with this approach.

cxx-async: Implements async support for cxx using the C++20 couroutine features for the folly and cppcoro libraries. With this library, there's already the problem that, due to the cppcoro and folly libraries, I haven't even been able to get the library examples to work yet. The examples aren't documented, and compiling and linking the two libraries is quite complicated. Furthermore, cppcoro seems to be unmaintained and outdated. The build is based on Python 2.7 and an old version of clang, which isn't installable on a new Ubuntu. According to the documentation, the build was tested on Ubuntu 17.04.

Does anyone here have experience in this area or other ideas on how we can implement the bindings? Are we perhaps overlooking the simplest approaches?

Thank you in advance for help :slight_smile:

1 post - 1 participant

Read full topic

🏷️ Rust_feed