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

WIP: cxx-qt-build: use isolated cc::Build for QmlModules #1066

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Libraries can pass build information to cxx-qt-build in the form of a `cxx_qt_build::Interface`
- Add CMake wrappers around corrosion to simplify importing crates and qml modules that were built with cxx-qt-build
- CMake code has been extracted into a separate repository for faster downloads (kdab/cxx-qt-cmake)
- Folder structure of Rust bridges is now considered in the same way as CXX in `CxxQtBuilder`
- `cxx_file_stem` has been removed from `#[cxx_qt::bridge]` and the source file name is now used for generated headers similar to CXX

### Removed

Expand Down
2 changes: 1 addition & 1 deletion book/src/bridge/extern_rustqt.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod ffi {

The `extern "RustQt"` section of a CXX bridge declares Rust types and signatures to be made available to Qt and C++.

The CXX code generator uses your `extern "Rust"` section(s) to produce a C++ header file containing the corresponding C++ declarations. The generated header has a file name matching the module ident or the `cxx_file_stem` field in the `#[cxx_qt::bridge]` attribute and with a `.cxxqt.h` file extension.
The CXX code generator uses your `extern "Rust"` section(s) to produce a C++ header file containing the corresponding C++ declarations. The generated header has the same file name as the input rust file but with `.cxxqt.h` file extension.

A bridge module may contain zero or more `extern "RustQt"` blocks.

Expand Down
22 changes: 1 addition & 21 deletions book/src/bridge/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,6 @@ This Rust module will then function like a normal CXX bridge, whilst also suppor

> Don't forget to add the Rust source file to the `CxxQtBuilder` in your `build.rs` script. For instructions, see the [Getting Started guide](../getting-started/5-cmake-integration.md).

The `#[cxx_qt::bridge]` macro supports two options in its attribute:
The `#[cxx_qt::bridge]` macro supports the options in its attribute:

- [`cxx_file_stem`](#cxx_file_stem)
- [`namespace`](./attributes.md#namespace)

## cxx_file_stem

By default, the name of the generated C++ header file will be the name of the module, followed by `.cxxqt.h` (and `.cxx.h` for CXX files).

This can cause issues as the module is normally called `ffi` or `qobject`, so collisions would occur.

The `cxx_file_stem` option allow a file name to be specified to avoid collisions.

```rust,ignore
{{#include ../../../examples/qml_features/rust/src/types.rs:book_cxx_file_stem}}
```

> Currently, `cxx-qt-gen` writes all generated header files into a single folder.
> Therefore, you need to be careful to not produce two header files with the same filename.

> We want to use the name of the Rust source file that the macro is located in (the same as CXX).
> However, this requires [inspection APIs from `proc_macro::Span`](https://github.com/rust-lang/rust/issues/54725)
> which is currently a nightly feature.
2 changes: 1 addition & 1 deletion book/src/bridge/shared_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ It is currently not possible to add a `#[qenum(...)]` to any `extern "C++Qt"` `Q
Example:

```rust,ignore,noplayground
#[cxx_qt::bridge(cxx_file_stem="custom_base_class")]
#[cxx_qt::bridge]
pub mod qobject {
{{#include ../../../examples/qml_features/rust/src/custom_base_class.rs:book_qenum_in_qobject}}

Expand Down
6 changes: 3 additions & 3 deletions book/src/getting-started/5-cmake-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ You can add as much C++ code as you want in addition to this.

For every `#[cxx_qt::bridge]` that we define in Rust, CXX-Qt will generate a corresponding C++ header file.
To include any of the generated files, use the crates name as the include directory.
The name of the header file will be the name of the Rust module of your `#[cxx_qt::bridge]`, followed by `.cxxqt.h`.
So in our case: `#include <qml_minimal/qobject.cxxqt.h>`
The name of the header file will be the folder names, combined with the input rust file name of your `#[cxx_qt::bridge]`, followed by `.cxxqt.h`.
So in our case: `#include <qml_minimal/src/cxxqt_object.cxxqt.h>`

> Note that the [`cxx_file_stem`](../bridge/index.md#cxx_file_stem) option can be specified in the bridge macro to choose the file name.
> Note any folders relative to the cargo manifest are considered hence the `src` folder.

Including the generated header allows us to access the `MyObject` C++ class, just like any other C++ class.
Inherit from it, connect signals and slots to it, put it in a QVector, do whatever you want with it.
Expand Down
Loading
Loading