Skip to content

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ahayzen-kdab
Copy link
Collaborator

This is the first step towards #1125 towards a builder pattern with various stages.

Copy link

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a662b2e) to head (16f9f04).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 35 to 41
// 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
Copy link
Collaborator Author

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 🤔

Copy link
Collaborator Author

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 🤔

Copy link
Collaborator

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.

@ahayzen-kdab ahayzen-kdab force-pushed the 1125-build-system-changes branch from dbe3464 to 08febd9 Compare March 13, 2025 17:14
@ahayzen-kdab ahayzen-kdab force-pushed the 1125-build-system-changes branch from 08febd9 to 5f8f83d Compare April 18, 2025 11:03
@@ -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")
Copy link
Collaborator Author

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

@ahayzen-kdab ahayzen-kdab force-pushed the 1125-build-system-changes branch 2 times, most recently from e7141dd to d5ab884 Compare April 21, 2025 11:33
@ahayzen-kdab ahayzen-kdab force-pushed the 1125-build-system-changes branch 2 times, most recently from e7ce493 to a690dc8 Compare April 22, 2025 08:09
@ahayzen-kdab ahayzen-kdab force-pushed the 1125-build-system-changes branch from a690dc8 to 24e624b Compare April 22, 2025 09:44
@ahayzen-kdab ahayzen-kdab force-pushed the 1125-build-system-changes branch from 24e624b to fb6ff0f Compare April 22, 2025 10:44
@ahayzen-kdab ahayzen-kdab marked this pull request as ready for review April 22, 2025 12:49
Copy link
Collaborator

@LeonMatthesKDAB LeonMatthesKDAB left a 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> {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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={}",
Copy link
Collaborator

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.

Copy link
Collaborator Author

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?

let mut this = Self::new();
this.public_interface = Some(interface_definition);

pub fn library() -> Self {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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>

Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

@ahayzen-kdab ahayzen-kdab force-pushed the 1125-build-system-changes branch from 4bdf78f to 16f9f04 Compare April 22, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants