-
Notifications
You must be signed in to change notification settings - Fork 80
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
Use method calls to initialize dependencies #1169
base: main
Are you sure you want to change the base?
Conversation
crates/cxx-qt-build/src/lib.rs
Outdated
// Build static initializers into a library that we link with whole-archive | ||
// Then use object files just to trigger the initial call. | ||
init_builder | ||
.clone() | ||
.file(initializers_file) | ||
.link_lib_modifier("+whole-archive") | ||
.compile(&format!("{}-initializers", crate_name())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the whole-archive for the cargo build or cmake build or both ?
and then why is this needed ? can these initialiser functions not be public exported functions that are built into a library. Then when linking the library the object file that is also links makes use of the public functions preventing them being optimised out ?
crates/cxx-qt-build/src/lib.rs
Outdated
.map(|init_fun| { | ||
( | ||
// declaration | ||
format!("extern \"C\" int {init_fun}();"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::std::int32_t
?
}) | ||
.unzip(); | ||
let init_function = format!( | ||
"{declarations}\nextern \"C\" int {init_fun}() {{\n{calls}\nreturn 42;\n}}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::std::int32_t
?
crates/cxx-qt-build/src/lib.rs
Outdated
.compile(&format!("{}-initializers", crate_name())); | ||
|
||
let init_call = format!( | ||
"extern \"C\" int {init_fun}();\nstatic const int do_{init_fun} = {init_fun}();", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::std::int32_t
?
@@ -11,163 +11,102 @@ | |||
#include <cxx-qt-lib/qset.h> | |||
#include <cxx-qt-lib/qvector.h> | |||
|
|||
static const int register_QHash_i32_QByteArray = | |||
extern "C" int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::std::int32_t
?
qRegisterMetaType<::QVector_u64>("QVector_u64"); | ||
|
||
return 42; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you return 42 ? Seems to be a magic value that isn't used anywhere ? Can you not use void
? If you do need to return something to indicate success why not bool
or true/false ? If this is a magic value then can we have a static const in cxx-qt or exposed from rust somewhere ?
crates/qt-build-utils/src/lib.rs
Outdated
/// The build system must ensure that if the .cpp file is built into a static library, either | ||
/// the `+whole-archive` flag is used, or the initializer function is called by the | ||
/// application. | ||
pub fn qrc(&mut self, input_file: &impl AsRef<Path>) -> (PathBuf, String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wonder if in the refactor we should have a type for a ProcessedFile or something that then has input path, source, output path, any initialiser function etc wrapped up.
fc2ed2a
to
9b66808
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1169 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 71 71
Lines 11967 11967
=========================================
Hits 11967 11967 ☔ View full report in Codecov by Sentry. |
40e7f38
to
b76d33d
Compare
This speeds up rebuilds, as we only need to link to upstream dependencies initializers, not build their initializers every time. It should also allow us to manually initialize certain libraries down the line with something similar to Q_INIT_RESOURCE, etc. Closes KDAB#1166
b76d33d
to
3dba56b
Compare
This speeds up rebuilds, as we only need to link to upstream
dependencies initializers, not build their initializers every time.
It should also allow us to manually initialize certain libraries down
the line with something similar to Q_INIT_RESOURCE, etc.
Closes #1166