-
Notifications
You must be signed in to change notification settings - Fork 82
cxx-qt-build: return an Interface from CxxQtBuilder #1224
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1224 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 73 73
Lines 12634 12634
=========================================
Hits 12634 12634 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
crates/cxx-qt/build.rs
Outdated
// TODO: should we even have this ? Instead pass in an include_directory to our | ||
// builder that handles this? | ||
// As they are first being copied to the OUT_DIR/include/<crate> and then | ||
// to the target/cxx-qt-build/../include | ||
// | ||
// This then causes problems because we try to symlink this dir now after | ||
// the CXX files are written already |
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.
@LeonMatthesKDAB lets discuss this and the general way that we should handle how we have include dirs that use files from the source directory + have generated files (so is not as simple as a symlink). And whether there should be a default include dir already or not 🤔
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.
I note that in the CXX tutorials ( https://cxx.rs/tutorial.html ) they have the following
#include "cxx-demo/include/blobstore.h"
#include "cxx-demo/src/main.rs.h"
For CXX the crate is already added as an include directory and the other folder is target/cxxbridge/cxx-demo/src/main.rs.h
.
I wonder if we can do similar and use the fact that rust files are (always?) under src/
? As we could instead have
my-crate/
include/
myheader.h
src/
rustmod.rs
Then have in the export target folder
exporttarget/
my-crate/
include/ -- symlink to the my-crate/include/ (which avoids the current copy we always do)
src/ -- where the generated files are written?
But probably needs more thought about how we can avoid collisions and if we can avoid a copy of the include like we do currently or not 🤔
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.
Here's the notes from todays call:
include/
my_crate/
- include/
- my_header.hpp <-- copied over from crate source
- src/
- my_bridge.rs // <-- actually a header file generated from the bridge
- my_bridge.rs.h // <-- actually a header file generated from the bridge
- my_bridge.rs.cxx.h // <-- actually a header file generated from the bridge
upstream_crate/ <-- ???
// CXX-Qt behavior (OUT_DIR)
include/ <--- include_dir
cxx-qt-lib/
src/core/
- qobject.rs ---> .cxxqt.h
- qobject.rs.cxxqt.h
- qobject.rs.cxx.h
include/ <-- copied from crate dir (same as CXX does see: best_effort_copy_headers))
...
include!(cxx-qt-lib/include/qstring.h);
vvvvvvv include_dir
crates/cxx-qt-lib/include/cxx-qt-lib/qstring.h
crates-include/ <-- this is added as an include_dir
- cxx-qt-lib -> source of cxx-qt-lib
- cxx-qt -> Source of cxx-qt
- my-crate -> source of my-crate
The important point was to separate the downstream dependencies header dirs from the header dirs provided by the current crate.
Then you can manually separately override which dependencies to re-export, and which of the include dirs to export for the current crate.
dbe3464
to
08febd9
Compare
08febd9
to
5f8f83d
Compare
@@ -121,6 +121,10 @@ pub(crate) fn header_root() -> PathBuf { | |||
crate_target().join("include") | |||
} | |||
|
|||
pub(crate) fn header_root_interface() -> PathBuf { | |||
target().join("crates-include") |
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.
probably want a better name like export-include
and sort out various naming across the codebase
e7141dd
to
d5ab884
Compare
This still needs more refactoring later but is a first step.
This allows export() to have no args meaning we can return an Interface from the compile command next.
e7ce493
to
a690dc8
Compare
a690dc8
to
24e624b
Compare
24e624b
to
fb6ff0f
Compare
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.
This seems to be going in the right direction, but some concepts around where which include dir is defined still require working out.
.collect() | ||
} | ||
|
||
fn reexported_dependencies(interface: &Interface, dependencies: &[Dependency]) -> Vec<Dependency> { |
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.
This should be in impl Interface
, no?
Same with all_include_prefix
.
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.
Could be, this has just moved the existing code :-)
.expect("Failed to convert Manifest to JSON!"); | ||
std::fs::write(&manifest_path, manifest_json).expect("Failed to write manifest.json!"); | ||
println!( | ||
"cargo::metadata=CXX_QT_MANIFEST_PATH={}", |
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.
This assumes we have a links key set, right?
We should probably panic if it isn't the case here.
However, then we'd have to check whether we're currently exporting to CMake, as then it's not needed.
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.
A few lines further up (at the start of this export() function) we panic if the link name is empty?
crates/cxx-qt-build/src/lib.rs
Outdated
let mut this = Self::new(); | ||
this.public_interface = Some(interface_definition); | ||
|
||
pub fn library() -> Self { |
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.
This method won't really be necessary here anymore, right?
The Interface
in the end defines whether the project is re-exported or not, at which point it should also check whether the links key is set.
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.
Right i'll see if this can be removed now...
@@ -1134,6 +1083,17 @@ extern "C" bool {init_fun}() {{ | |||
// to the generated files without any namespacing. | |||
include_paths.push(header_root.join(&self.include_prefix)); | |||
|
|||
// Automatically add any include/ directory from the cargo manifest dir |
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.
This will mean any directory named include/
will be available directly without prefix, right?
e.g. something like this:
include/test.h
Cargo.toml
Will mean it'll be possible to do:
#include <test.h>
I think CXX behavior was to have this available as:
#include <my_crate/include/test.h>
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.
I think to specify certain include directories we wanted to add an include
function that sets up the right include path with the given prefix and is passed to the Interface, right?
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.
We possibly need to
- copy CXX and add any headers relative to the manifest dir to the header root (OUT/include) under crate name (so includes become crate/include/header.h)
- one of the functions allows for copying things from header root to exported headers (OUT/crate-include)
Note that we currently rename to eg cxx-qt-lib/qstring.h instead of cxx-qt-lib/include/core/qstring.h, however we now have the problem of how do these headers include other the common.h as within the build they are at cxx-qt-lib/include/common.h but when exported they are now at cxx-qt-lib/common.h. Should we instead not perform our renaming and force the developer to create a clean input ? For cxx-qt-lib this would mean you copy/write the headers into the structure you want inside the OUT dir and then manually add that to CxxQtBuilder rather than using the automatic relative manifest include. For other crates that don't need this functionality they can use the automatic relative manifest include.
4bdf78f
to
16f9f04
Compare
This is the first step towards #1125 towards a builder pattern with various stages.