Skip to content

Commit a016386

Browse files
Remove cxx-qt dependency of cxx-qt-macro
cxx-qt-macro needed cxx-qt as a dev-dependency for the documentation. This didn't allow me to release the crate, as cxx-qt-macro depended on cxx-qt 0.7.2, which wasn't released yet, but cxx-qt itself also depended on cxx-qt-macro 0.7.2 which also wasn't released yet. We can solve this conundrum by moving the documentation of cxx-qt-macro into cxx-qt itself. The documentation of cxx-qt-macro should not be used anyway, as it is an implementation detail.
1 parent ee3c261 commit a016386

File tree

4 files changed

+95
-93
lines changed

4 files changed

+95
-93
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cxx-qt-macro/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,5 @@ proc-macro2.workspace = true
2424
syn.workspace = true
2525
quote.workspace = true
2626

27-
[dev-dependencies]
28-
cxx.workspace = true
29-
cxx-qt.workspace = true
30-
3127
[lints]
3228
workspace = true

crates/cxx-qt-macro/src/lib.rs

Lines changed: 6 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,19 @@
44
//
55
// SPDX-License-Identifier: MIT OR Apache-2.0
66

7-
#![deny(missing_docs)]
7+
// We explicitly allow missing docs for the macros in this crate, as they should be documented in
8+
// cxx-qt itself.
9+
#![allow(missing_docs)]
810
//! The cxx-qt-macro crate provides the procedural attribute macros which are used with cxx-qt.
11+
//!
12+
//! See the [cxx-qt crate docs](https://docs.rs/cxx-qt/latest/) for documentation of the macros
13+
//! inside this crate.
914
1015
use proc_macro::TokenStream;
1116
use syn::{parse_macro_input, ItemMod};
1217

1318
use cxx_qt_gen::{write_rust, GeneratedRustBlocks, Parser};
1419

15-
/// A procedural macro which generates a QObject for a struct inside a module.
16-
///
17-
/// # Example
18-
///
19-
/// ```rust
20-
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
21-
/// mod qobject {
22-
/// extern "RustQt" {
23-
/// #[qobject]
24-
/// # // Note that we can't use properties as this confuses the linker on Windows
25-
/// type MyObject = super::MyObjectRust;
26-
///
27-
/// #[qinvokable]
28-
/// fn invokable(self: &MyObject, a: i32, b: i32) -> i32;
29-
/// }
30-
/// }
31-
///
32-
/// #[derive(Default)]
33-
/// pub struct MyObjectRust;
34-
///
35-
/// impl qobject::MyObject {
36-
/// fn invokable(&self, a: i32, b: i32) -> i32 {
37-
/// a + b
38-
/// }
39-
/// }
40-
///
41-
/// # // Note that we need a fake main for doc tests to build
42-
/// # fn main() {
43-
/// # cxx_qt::init_crate!(cxx_qt);
44-
/// # }
45-
/// ```
4620
#[proc_macro_attribute]
4721
pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
4822
// Parse the TokenStream of a macro
@@ -65,65 +39,11 @@ pub fn bridge(args: TokenStream, input: TokenStream) -> TokenStream {
6539
extract_and_generate(module)
6640
}
6741

68-
/// A macro which describes that a struct should be made into a QObject.
69-
///
70-
/// It should not be used by itself and instead should be used inside a cxx_qt::bridge definition.
71-
///
72-
/// # Example
73-
///
74-
/// ```rust
75-
/// #[cxx_qt::bridge]
76-
/// mod my_object {
77-
/// extern "RustQt" {
78-
/// #[qobject]
79-
/// # // Note that we can't use properties as this confuses the linker on Windows
80-
/// type MyObject = super::MyObjectRust;
81-
/// }
82-
/// }
83-
///
84-
/// #[derive(Default)]
85-
/// pub struct MyObjectRust;
86-
///
87-
/// # // Note that we need a fake main for doc tests to build
88-
/// # fn main() {
89-
/// # cxx_qt::init_crate!(cxx_qt);
90-
/// # }
91-
/// ```
92-
///
93-
/// You can also specify a custom base class by using `#[base = QStringListModel]`, you must then use CXX to add any includes needed.
94-
///
95-
/// # Example
96-
///
97-
/// ```rust
98-
/// #[cxx_qt::bridge]
99-
/// mod my_object {
100-
/// extern "RustQt" {
101-
/// #[qobject]
102-
/// #[base = QStringListModel]
103-
/// # // Note that we can't use properties as this confuses the linker on Windows
104-
/// type MyModel = super::MyModelRust;
105-
/// }
106-
///
107-
/// unsafe extern "C++" {
108-
/// include!(<QtCore/QStringListModel>);
109-
/// type QStringListModel;
110-
/// }
111-
/// }
112-
///
113-
/// #[derive(Default)]
114-
/// pub struct MyModelRust;
115-
///
116-
/// # // Note that we need a fake main for doc tests to build
117-
/// # fn main() {
118-
/// # cxx_qt::init_crate!(cxx_qt);
119-
/// # }
120-
/// ```
12142
#[proc_macro_attribute]
12243
pub fn qobject(_args: TokenStream, _input: TokenStream) -> TokenStream {
12344
unreachable!("qobject should not be used as a macro by itself. Instead it should be used within a cxx_qt::bridge definition")
12445
}
12546

126-
/// Force a crate to be initialized
12747
#[proc_macro]
12848
pub fn init_crate(args: TokenStream) -> TokenStream {
12949
let crate_name = syn::parse_macro_input!(args as syn::Ident);
@@ -137,7 +57,6 @@ pub fn init_crate(args: TokenStream) -> TokenStream {
13757
.into()
13858
}
13959

140-
/// Force a QML module with the given URI to be initialized
14160
#[proc_macro]
14261
pub fn init_qml_module(args: TokenStream) -> TokenStream {
14362
let module_uri = syn::parse_macro_input!(args as syn::LitStr);

crates/cxx-qt/src/lib.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,98 @@ mod qobject;
2020
pub mod signalhandler;
2121
mod threading;
2222

23+
/// A procedural macro which generates a QObject for a struct inside a module.
24+
///
25+
/// # Example
26+
///
27+
/// ```rust
28+
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
29+
/// mod qobject {
30+
/// extern "RustQt" {
31+
/// #[qobject]
32+
/// # // Note that we can't use properties as this confuses the linker on Windows
33+
/// type MyObject = super::MyObjectRust;
34+
///
35+
/// #[qinvokable]
36+
/// fn invokable(self: &MyObject, a: i32, b: i32) -> i32;
37+
/// }
38+
/// }
39+
///
40+
/// #[derive(Default)]
41+
/// pub struct MyObjectRust;
42+
///
43+
/// impl qobject::MyObject {
44+
/// fn invokable(&self, a: i32, b: i32) -> i32 {
45+
/// a + b
46+
/// }
47+
/// }
48+
///
49+
/// # // Note that we need a fake main for doc tests to build
50+
/// # fn main() {
51+
/// # cxx_qt::init_crate!(cxx_qt);
52+
/// # }
53+
/// ```
2354
pub use cxx_qt_macro::bridge;
55+
56+
/// Force a crate to be initialized
2457
pub use cxx_qt_macro::init_crate;
58+
59+
/// Force a QML module with the given URI to be initialized
2560
pub use cxx_qt_macro::init_qml_module;
61+
62+
/// A macro which describes that a struct should be made into a QObject.
63+
///
64+
/// It should not be used by itself and instead should be used inside a cxx_qt::bridge definition.
65+
///
66+
/// # Example
67+
///
68+
/// ```rust
69+
/// #[cxx_qt::bridge]
70+
/// mod my_object {
71+
/// extern "RustQt" {
72+
/// #[qobject]
73+
/// # // Note that we can't use properties as this confuses the linker on Windows
74+
/// type MyObject = super::MyObjectRust;
75+
/// }
76+
/// }
77+
///
78+
/// #[derive(Default)]
79+
/// pub struct MyObjectRust;
80+
///
81+
/// # // Note that we need a fake main for doc tests to build
82+
/// # fn main() {
83+
/// # cxx_qt::init_crate!(cxx_qt);
84+
/// # }
85+
/// ```
86+
///
87+
/// You can also specify a custom base class by using `#[base = QStringListModel]`, you must then use CXX to add any includes needed.
88+
///
89+
/// # Example
90+
///
91+
/// ```rust
92+
/// #[cxx_qt::bridge]
93+
/// mod my_object {
94+
/// extern "RustQt" {
95+
/// #[qobject]
96+
/// #[base = QStringListModel]
97+
/// # // Note that we can't use properties as this confuses the linker on Windows
98+
/// type MyModel = super::MyModelRust;
99+
/// }
100+
///
101+
/// unsafe extern "C++" {
102+
/// include!(<QtCore/QStringListModel>);
103+
/// type QStringListModel;
104+
/// }
105+
/// }
106+
///
107+
/// #[derive(Default)]
108+
/// pub struct MyModelRust;
109+
///
110+
/// # // Note that we need a fake main for doc tests to build
111+
/// # fn main() {
112+
/// # cxx_qt::init_crate!(cxx_qt);
113+
/// # }
114+
/// ```
26115
pub use cxx_qt_macro::qobject;
27116
pub use qobject::QObject;
28117

0 commit comments

Comments
 (0)