KDAB / cxx-qt

Safe interop between Rust and Qt
https://kdab.github.io/cxx-qt/book/
978 stars 67 forks source link

figure out and document how to link multiple cxx-qt modules into an application #148

Open Be-ing opened 2 years ago

Be-ing commented 2 years ago

Application developers will likely want to link multiple cxx-qt modules into applications. I can think of two approaches this could take:

  1. Create a cargo workspace within the application repository with multiple lib crates, built as normal rlib crates. Link them together into one staticlib crate and link the staticlib crate into the C++ application. This is the approach Firefox takes: https://hg.mozilla.org/mozilla-central/rev/841c2247f57d, https://bugzilla.mozilla.org/show_bug.cgi?id=1163224
  2. Write one big staticlib crate with separate modules using cxx-qt within it. I doubt this would be a good idea for build times because Cargo parallelizes at the level of crates, not modules.
Be-ing commented 2 years ago

Related: #119

ahayzen-kdab commented 2 years ago

I assume you mean multiple crates ? And not multiple modules, as we support already defining multiple modules that are in the same crate and are then expose multiple QObject's to C++.

Are you describing having multiple Rust crates so that there would be two Rust static libraries to link to the C++ application ? As I don't really see why that wouldn't work already ? (or would there be collisions where some CXX things are the same in both the libs?) Once we have the CMake CLI tool it'll be easier to work with cargo workspaces too.

Be-ing commented 1 year ago

Create a cargo workspace within the application repository with multiple lib crates, built as normal rlib crates. Link them together into one staticlib crate and link the staticlib crate into the C++ application. This is the approach Firefox takes: https://hg.mozilla.org/mozilla-central/rev/841c2247f57d, https://bugzilla.mozilla.org/show_bug.cgi?id=1163224

Proof of concept of that is in #598. Unfortunately it is blocked on https://github.com/rust-lang/rust/issues/108081 upstream.