Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Crate project - second try #1178

Merged
merged 9 commits into from
Feb 14, 2025

Conversation

LeonMatthesKDAB
Copy link
Collaborator

@LeonMatthesKDAB LeonMatthesKDAB commented Feb 5, 2025

A combination of #598 and #1169.

Closes #598
Closes #148
Closes #1135

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (eb42349) to head (227cad2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1178   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           73        73           
  Lines        12438     12438           
=========================================
  Hits         12438     12438           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LeonMatthesKDAB LeonMatthesKDAB force-pushed the 592-multi-crate-project branch 6 times, most recently from 14e1d29 to b8b5603 Compare February 6, 2025 15:41
@LeonMatthesKDAB LeonMatthesKDAB marked this pull request as ready for review February 6, 2025 15:41
@LeonMatthesKDAB LeonMatthesKDAB force-pushed the 592-multi-crate-project branch 3 times, most recently from d8e4664 to 89c2cd7 Compare February 14, 2025 08:31
ahayzen-kdab and others added 8 commits February 14, 2025 13:44
This isn't required for the libraries published to crates.io,
so this isn't specified in the workspace Cargo.toml.
No need to change the privacy of these; just need to have the
symbols referenced within the staticlib crate.
This also adds cxx_qt::init_crate! and init_qml_module!
Previously, downstream QML modules weren't exported.
This should now be fixed, as QML modules are always exported.
qml_multi_crates is the grand finale in our quest for CMake&Cargo
compatibility.
It is a project that can be built as a Cargo lib and binary, as well as
imported into CMake with a C++ binary and uses multiple Cargo crates
internally.

It does rely on the init_crate! and init_qml_module! macros, but
otherwise works quite seamless.
Copy link
Collaborator

@ahayzen-kdab ahayzen-kdab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, lets go with this :-)

@LeonMatthesKDAB LeonMatthesKDAB merged commit 1f6d8cf into KDAB:main Feb 14, 2025
16 checks passed
@Be-ing
Copy link
Contributor

Be-ing commented Feb 14, 2025

Wow, good job finally figuring out this cursed puzzle!

Next we need to ensure the initializers can be found by the linker.

If you followed step 1, modern linkers like `mold` or `lld` should already be able to link everything correctly.
We encourage switching to such a linker if you're still using the (now deprecated) `ld.gold` on Linux.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ld.bfd is still the default linker on most distros?

Copy link
Contributor

@Be-ing Be-ing Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be worth mentioning here that CXX-Qt will automatically prefer lld or mold if they are installed, and also that the linker can be configured for all Rust builds by putting

[target.x86_64-unknown-linux-gnu] # or whatever target
rustflags = [
    "-C", "link-arg=-fuse-ld=mold"
]

in ~/.cargo/config.toml.

I just tested the main branch with ld.bfd and ld.gold, and with the recent changes, cargo build -p qml-minimal-no-cmake links successfully. cargo build -p qml_multi_crates works with all linkers, but if I comment out cxx_qt::init_crate!(qml_multi_crates); then ld.bfd and ld.gold both fail.

#[cfg(test)]
mod tests {
#[test]
fn initialize_eependencies() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who needs dependencies when you can have eependencies? 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants