diff --git a/crates/cxx-qt-build/src/lib.rs b/crates/cxx-qt-build/src/lib.rs index dd48d6026..93f3b9f3f 100644 --- a/crates/cxx-qt-build/src/lib.rs +++ b/crates/cxx-qt-build/src/lib.rs @@ -91,21 +91,7 @@ impl GeneratedCpp { let generated_rust = GeneratedRustBlocks::from(&parser).unwrap(); let rust_tokens = write_rust(&generated_rust); - // Use the qobject ident as the output file name? - // - // TODO: for now we use the qobject name but in the future this will come from elswhere - if parser.cxx_qt_data.qobjects.len() != 1 { - panic!("Expected one QObject in the ItemMod."); - } - file_ident = parser - .cxx_qt_data - .qobjects - .keys() - .take(1) - .next() - .unwrap() - .to_string() - .to_case(Case::Snake); + file_ident = parser.cxx_file_stem.clone(); // We need to do this and can't rely on the macro, as we need to generate the // CXX bridge Rust code that is then fed into the cxx_gen generation. diff --git a/crates/cxx-qt-gen/src/generator/cpp/mod.rs b/crates/cxx-qt-gen/src/generator/cpp/mod.rs index f37dd978e..2b459b03a 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/mod.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/mod.rs @@ -10,10 +10,9 @@ pub mod qobject; pub mod signal; pub mod types; -use crate::generator::naming; use crate::parser::Parser; use qobject::GeneratedCppQObject; -use syn::{spanned::Spanned, Error, Result}; +use syn::Result; pub const RUST_OBJ_MUTEX_LOCK_GUARD: &str = "const std::lock_guard guard(*m_rustObjMutex);"; @@ -22,7 +21,7 @@ pub const CXX_QT_CONVERT: &str = "rust::cxxqtlib1::cxx_qt_convert"; /// Representation of the generated C++ code for a group of QObjects pub struct GeneratedCppBlocks { /// Stem of the CXX header to include - pub cxx_stem: String, + pub cxx_file_stem: String, /// Ident of the common namespace of the QObjects pub namespace: String, /// Generated QObjects @@ -31,18 +30,8 @@ pub struct GeneratedCppBlocks { impl GeneratedCppBlocks { pub fn from(parser: &Parser) -> Result { - // TODO: for now we use the name of the first and only QObject - // later this needs to come from elsewhere - if parser.cxx_qt_data.qobjects.len() != 1 { - return Err(Error::new( - parser.passthrough_module.span(), - "Expected one QObject in the ItemMod.", - )); - } - let qt_ident = parser.cxx_qt_data.qobjects.keys().take(1).next().unwrap(); - Ok(GeneratedCppBlocks { - cxx_stem: naming::module::cxx_stem_from_ident(qt_ident).to_string(), + cxx_file_stem: parser.cxx_file_stem.clone(), namespace: parser.cxx_qt_data.namespace.clone(), qobjects: parser .cxx_qt_data @@ -75,7 +64,24 @@ mod tests { let parser = Parser::from(module).unwrap(); let cpp = GeneratedCppBlocks::from(&parser).unwrap(); - assert_eq!(cpp.cxx_stem, "my_object"); + assert_eq!(cpp.cxx_file_stem, "ffi"); + assert_eq!(cpp.namespace, ""); + assert_eq!(cpp.qobjects.len(), 1); + } + + #[test] + fn test_generated_cpp_blocks_cxx_file_stem() { + let module: ItemMod = tokens_to_syn(quote! { + #[cxx_qt::bridge(cxx_file_stem = "my_object")] + mod ffi { + #[cxx_qt::qobject] + struct MyObject; + } + }); + let parser = Parser::from(module).unwrap(); + + let cpp = GeneratedCppBlocks::from(&parser).unwrap(); + assert_eq!(cpp.cxx_file_stem, "my_object"); assert_eq!(cpp.namespace, ""); assert_eq!(cpp.qobjects.len(), 1); } diff --git a/crates/cxx-qt-gen/src/generator/naming/mod.rs b/crates/cxx-qt-gen/src/generator/naming/mod.rs index f7012895c..d9cde950b 100644 --- a/crates/cxx-qt-gen/src/generator/naming/mod.rs +++ b/crates/cxx-qt-gen/src/generator/naming/mod.rs @@ -3,7 +3,6 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 pub mod invokable; -pub mod module; pub mod namespace; pub mod property; pub mod qobject; diff --git a/crates/cxx-qt-gen/src/generator/naming/module.rs b/crates/cxx-qt-gen/src/generator/naming/module.rs deleted file mode 100644 index ada44a684..000000000 --- a/crates/cxx-qt-gen/src/generator/naming/module.rs +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company -// SPDX-FileContributor: Andrew Hayzen -// -// SPDX-License-Identifier: MIT OR Apache-2.0 -use convert_case::{Case, Casing}; -use quote::format_ident; -use syn::Ident; - -/// For a given module ident generate the file stem -// -// TODO: for now the QObject ident is passed to this -pub fn cxx_stem_from_ident(ident: &Ident) -> Ident { - format_ident!("{}", ident.to_string().to_case(Case::Snake)) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_cxx_stem_from_ident() { - assert_eq!( - cxx_stem_from_ident(&format_ident!("MyObject")), - format_ident!("my_object") - ); - } -} diff --git a/crates/cxx-qt-gen/src/generator/rust/mod.rs b/crates/cxx-qt-gen/src/generator/rust/mod.rs index 8a21c902c..59fdba0d9 100644 --- a/crates/cxx-qt-gen/src/generator/rust/mod.rs +++ b/crates/cxx-qt-gen/src/generator/rust/mod.rs @@ -10,10 +10,10 @@ pub mod property; pub mod qobject; pub mod signals; -use crate::generator::{naming::module::cxx_stem_from_ident, rust::qobject::GeneratedRustQObject}; +use crate::generator::rust::qobject::GeneratedRustQObject; use crate::parser::Parser; use quote::quote; -use syn::{spanned::Spanned, Error, Item, ItemMod, Result}; +use syn::{Item, ItemMod, Result}; /// Representation of the generated Rust code for a QObject pub struct GeneratedRustBlocks { @@ -48,17 +48,7 @@ impl GeneratedRustBlocks { /// Generate the include line for this parsed block fn generate_include(parser: &Parser) -> Result { - // TODO: for now the cxx stem comes from the first QObject name - // but later this may come from the module or file so would then have - // a field on the cxx_qt_data - if parser.cxx_qt_data.qobjects.len() != 1 { - return Err(Error::new( - parser.passthrough_module.span(), - "Only one QObject is currently supported in the ItemMod.", - )); - } - let (qt_ident, _) = parser.cxx_qt_data.qobjects.iter().take(1).next().unwrap(); - let import_path = format!("cxx-qt-gen/{}.cxxqt.h", cxx_stem_from_ident(qt_ident)); + let import_path = format!("cxx-qt-gen/{}.cxxqt.h", parser.cxx_file_stem); syn::parse2(quote! { unsafe extern "C++" { @@ -91,7 +81,7 @@ mod tests { &rust.cxx_mod_contents[0], quote! { unsafe extern "C++" { - include!("cxx-qt-gen/my_object.cxxqt.h"); + include!("cxx-qt-gen/ffi.cxxqt.h"); } }, ); @@ -139,4 +129,31 @@ mod tests { assert_eq!(rust.namespace, "cxx_qt"); assert_eq!(rust.qobjects.len(), 1); } + + #[test] + fn test_generated_rust_blocks_cxx_file_stem() { + let module: ItemMod = tokens_to_syn(quote! { + #[cxx_qt::bridge(cxx_file_stem = "my_object")] + mod ffi { + #[cxx_qt::qobject] + struct MyObject; + } + }); + let parser = Parser::from(module).unwrap(); + + let rust = GeneratedRustBlocks::from(&parser).unwrap(); + assert_eq!(rust.cxx_mod.content.unwrap().1.len(), 0); + assert_eq!(rust.cxx_mod_contents.len(), 1); + assert_tokens_eq( + &rust.cxx_mod_contents[0], + quote! { + unsafe extern "C++" { + include!("cxx-qt-gen/my_object.cxxqt.h"); + } + }, + ); + assert_eq!(rust.cxx_qt_mod_contents.len(), 0); + assert_eq!(rust.namespace, ""); + assert_eq!(rust.qobjects.len(), 1); + } } diff --git a/crates/cxx-qt-gen/src/parser/mod.rs b/crates/cxx-qt-gen/src/parser/mod.rs index f5feb3951..db62c22f9 100644 --- a/crates/cxx-qt-gen/src/parser/mod.rs +++ b/crates/cxx-qt-gen/src/parser/mod.rs @@ -23,6 +23,8 @@ pub struct Parser { pub passthrough_module: ItemMod, /// Any CXX-Qt data that needs generation later pub cxx_qt_data: ParsedCxxQtData, + /// The stem of the file that the CXX headers for this module will be generated into + pub cxx_file_stem: String, } impl Parser { @@ -30,20 +32,27 @@ impl Parser { pub fn from(mut module: ItemMod) -> Result { let mut cxx_qt_data = ParsedCxxQtData::default(); let mut others = vec![]; + let mut cxx_file_stem = module.ident.to_string(); // Remove the cxx_qt::bridge attribute if let Some(index) = attribute_find_path(&module.attrs, &["cxx_qt", "bridge"]) { - // Parse any namespace in the cxx_qt::bridge macro - cxx_qt_data.namespace = if let Some(lit_str) = attribute_tokens_to_map::( + let attr_map = attribute_tokens_to_map::( &module.attrs[index], AttributeDefault::None, - )? - .get("e::format_ident!("namespace")) - { - lit_str.value() - } else { - "".to_owned() - }; + )?; + // Parse any namespace in the cxx_qt::bridge macro + cxx_qt_data.namespace = + if let Some(lit_str) = attr_map.get("e::format_ident!("namespace")) { + lit_str.value() + } else { + "".to_owned() + }; + + // Parse any custom file stem + if let Some(stem) = attr_map.get("e::format_ident!("cxx_file_stem")) { + cxx_file_stem = stem.value(); + } + module.attrs.remove(index); } else { return Err(Error::new( @@ -87,6 +96,7 @@ impl Parser { Ok(Self { passthrough_module: module, cxx_qt_data, + cxx_file_stem, }) } } diff --git a/crates/cxx-qt-gen/src/writer/cpp/header.rs b/crates/cxx-qt-gen/src/writer/cpp/header.rs index a33b7f2ce..ff8691943 100644 --- a/crates/cxx-qt-gen/src/writer/cpp/header.rs +++ b/crates/cxx-qt-gen/src/writer/cpp/header.rs @@ -129,11 +129,11 @@ pub fn write_cpp_header(generated: &GeneratedCppBlocks) -> String { }} {forward_declare} - #include "cxx-qt-gen/{cxx_stem}.cxx.h" + #include "cxx-qt-gen/{cxx_file_stem}.cxx.h" {qobjects} "#, - cxx_stem = generated.cxx_stem, + cxx_file_stem = generated.cxx_file_stem, forward_declare = forward_declare(generated).join("\n"), qobjects = qobjects_header(generated).join("\n"), } diff --git a/crates/cxx-qt-gen/src/writer/cpp/mod.rs b/crates/cxx-qt-gen/src/writer/cpp/mod.rs index af1ab360b..fb4d63202 100644 --- a/crates/cxx-qt-gen/src/writer/cpp/mod.rs +++ b/crates/cxx-qt-gen/src/writer/cpp/mod.rs @@ -51,7 +51,7 @@ mod tests { /// Helper to create a GeneratedCppBlocks for testing pub fn create_generated_cpp() -> GeneratedCppBlocks { GeneratedCppBlocks { - cxx_stem: "cxx_stem".to_owned(), + cxx_file_stem: "cxx_file_stem".to_owned(), namespace: "cxx_qt::my_object".to_owned(), qobjects: vec![ GeneratedCppQObject { @@ -149,7 +149,7 @@ mod tests { /// Helper to create a GeneratedCppBlocks for testing with multiple qobjects pub fn create_generated_cpp_multi_qobjects() -> GeneratedCppBlocks { GeneratedCppBlocks { - cxx_stem: "cxx_stem".to_owned(), + cxx_file_stem: "cxx_file_stem".to_owned(), namespace: "cxx_qt".to_owned(), qobjects: vec![ GeneratedCppQObject { @@ -254,7 +254,7 @@ mod tests { using MyObjectCxxQtThread = rust::cxxqtlib1::CxxQtThread; } // namespace cxx_qt::my_object - #include "cxx-qt-gen/cxx_stem.cxx.h" + #include "cxx-qt-gen/cxx_file_stem.cxx.h" namespace cxx_qt::my_object { class MyObject : public QStringListModel @@ -326,7 +326,7 @@ mod tests { using SecondObjectCxxQtThread = rust::cxxqtlib1::CxxQtThread; } // namespace cxx_qt - #include "cxx-qt-gen/cxx_stem.cxx.h" + #include "cxx-qt-gen/cxx_file_stem.cxx.h" namespace cxx_qt { class FirstObject : public QStringListModel @@ -425,7 +425,7 @@ mod tests { using MyObjectCxxQtThread = rust::cxxqtlib1::CxxQtThread; - #include "cxx-qt-gen/cxx_stem.cxx.h" + #include "cxx-qt-gen/cxx_file_stem.cxx.h" class MyObject : public QStringListModel @@ -477,7 +477,7 @@ mod tests { /// Helper for the expected source pub fn expected_source() -> &'static str { indoc! {r#" - #include "cxx-qt-gen/cxx_stem.cxxqt.h" + #include "cxx-qt-gen/cxx_file_stem.cxxqt.h" namespace cxx_qt::my_object { @@ -565,7 +565,7 @@ mod tests { /// Helper for the expected source with multiple QObjects pub fn expected_source_multi_qobjects() -> &'static str { indoc! {r#" - #include "cxx-qt-gen/cxx_stem.cxxqt.h" + #include "cxx-qt-gen/cxx_file_stem.cxxqt.h" namespace cxx_qt { @@ -685,7 +685,7 @@ mod tests { /// Helper for the expected header with no namespace pub fn expected_source_no_namespace() -> &'static str { indoc! {r#" - #include "cxx-qt-gen/cxx_stem.cxxqt.h" + #include "cxx-qt-gen/cxx_file_stem.cxxqt.h" diff --git a/crates/cxx-qt-gen/src/writer/cpp/source.rs b/crates/cxx-qt-gen/src/writer/cpp/source.rs index 68fff34e4..6cf3dc159 100644 --- a/crates/cxx-qt-gen/src/writer/cpp/source.rs +++ b/crates/cxx-qt-gen/src/writer/cpp/source.rs @@ -80,11 +80,11 @@ fn qobjects_source(generated: &GeneratedCppBlocks) -> Vec { /// For a given GeneratedCppBlocks write this into a C++ source pub fn write_cpp_source(generated: &GeneratedCppBlocks) -> String { formatdoc! {r#" - #include "cxx-qt-gen/{cxx_stem}.cxxqt.h" + #include "cxx-qt-gen/{cxx_file_stem}.cxxqt.h" {qobjects} "#, - cxx_stem = generated.cxx_stem, + cxx_file_stem = generated.cxx_file_stem, qobjects = qobjects_source(generated).join("\n"), } } diff --git a/crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs b/crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs index 32233017d..7f11454dc 100644 --- a/crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs +++ b/crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs @@ -1,5 +1,5 @@ #[attrA] -#[cxx_qt::bridge(namespace = "cxx_qt::my_object")] +#[cxx_qt::bridge(namespace = "cxx_qt::my_object", cxx_file_stem = "my_object")] #[attrB] pub mod ffi { // ItemConst diff --git a/crates/cxx-qt-gen/test_outputs/invokables.cpp b/crates/cxx-qt-gen/test_outputs/invokables.cpp index 2f576a5d8..4217755b0 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.cpp +++ b/crates/cxx-qt-gen/test_outputs/invokables.cpp @@ -1,4 +1,4 @@ -#include "cxx-qt-gen/my_object.cxxqt.h" +#include "cxx-qt-gen/ffi.cxxqt.h" namespace cxx_qt::my_object { diff --git a/crates/cxx-qt-gen/test_outputs/invokables.h b/crates/cxx-qt-gen/test_outputs/invokables.h index 200eaf121..1cec4554e 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.h +++ b/crates/cxx-qt-gen/test_outputs/invokables.h @@ -13,7 +13,7 @@ class MyObject; using MyObjectCxxQtThread = rust::cxxqtlib1::CxxQtThread; } // namespace cxx_qt::my_object -#include "cxx-qt-gen/my_object.cxx.h" +#include "cxx-qt-gen/ffi.cxx.h" namespace cxx_qt::my_object { class MyObject : public QObject diff --git a/crates/cxx-qt-gen/test_outputs/invokables.rs b/crates/cxx-qt-gen/test_outputs/invokables.rs index f32f79d6e..5420dbe25 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.rs +++ b/crates/cxx-qt-gen/test_outputs/invokables.rs @@ -15,7 +15,7 @@ mod ffi { } unsafe extern "C++" { - include!("cxx-qt-gen/my_object.cxxqt.h"); + include!("cxx-qt-gen/ffi.cxxqt.h"); } unsafe extern "C++" { diff --git a/crates/cxx-qt-gen/test_outputs/properties.cpp b/crates/cxx-qt-gen/test_outputs/properties.cpp index cc10fe12f..84a2d10b0 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.cpp +++ b/crates/cxx-qt-gen/test_outputs/properties.cpp @@ -1,4 +1,4 @@ -#include "cxx-qt-gen/my_object.cxxqt.h" +#include "cxx-qt-gen/ffi.cxxqt.h" namespace cxx_qt::my_object { diff --git a/crates/cxx-qt-gen/test_outputs/properties.h b/crates/cxx-qt-gen/test_outputs/properties.h index b8df7432f..fdd0f7454 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.h +++ b/crates/cxx-qt-gen/test_outputs/properties.h @@ -13,7 +13,7 @@ class MyObject; using MyObjectCxxQtThread = rust::cxxqtlib1::CxxQtThread; } // namespace cxx_qt::my_object -#include "cxx-qt-gen/my_object.cxx.h" +#include "cxx-qt-gen/ffi.cxx.h" namespace cxx_qt::my_object { class MyObject : public QObject diff --git a/crates/cxx-qt-gen/test_outputs/properties.rs b/crates/cxx-qt-gen/test_outputs/properties.rs index 4cd34cb45..c44be0868 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.rs +++ b/crates/cxx-qt-gen/test_outputs/properties.rs @@ -13,7 +13,7 @@ mod ffi { } unsafe extern "C++" { - include!("cxx-qt-gen/my_object.cxxqt.h"); + include!("cxx-qt-gen/ffi.cxxqt.h"); } unsafe extern "C++" { diff --git a/crates/cxx-qt-gen/test_outputs/signals.cpp b/crates/cxx-qt-gen/test_outputs/signals.cpp index 0f27bcf60..1276820b9 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.cpp +++ b/crates/cxx-qt-gen/test_outputs/signals.cpp @@ -1,4 +1,4 @@ -#include "cxx-qt-gen/my_object.cxxqt.h" +#include "cxx-qt-gen/ffi.cxxqt.h" namespace cxx_qt::my_object { diff --git a/crates/cxx-qt-gen/test_outputs/signals.h b/crates/cxx-qt-gen/test_outputs/signals.h index 2200cd8af..c9895353c 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.h +++ b/crates/cxx-qt-gen/test_outputs/signals.h @@ -13,7 +13,7 @@ class MyObject; using MyObjectCxxQtThread = rust::cxxqtlib1::CxxQtThread; } // namespace cxx_qt::my_object -#include "cxx-qt-gen/my_object.cxx.h" +#include "cxx-qt-gen/ffi.cxx.h" namespace cxx_qt::my_object { class MyObject : public QObject diff --git a/crates/cxx-qt-gen/test_outputs/signals.rs b/crates/cxx-qt-gen/test_outputs/signals.rs index 63af1eb36..8af5dacfd 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.rs +++ b/crates/cxx-qt-gen/test_outputs/signals.rs @@ -13,7 +13,7 @@ mod ffi { } unsafe extern "C++" { - include!("cxx-qt-gen/my_object.cxxqt.h"); + include!("cxx-qt-gen/ffi.cxxqt.h"); } unsafe extern "C++" { diff --git a/examples/cargo_without_cmake/src/cpp/run.cpp b/examples/cargo_without_cmake/src/cpp/run.cpp index 5a219c7fc..584c74c54 100644 --- a/examples/cargo_without_cmake/src/cpp/run.cpp +++ b/examples/cargo_without_cmake/src/cpp/run.cpp @@ -11,7 +11,7 @@ #include #include -#include "cxx-qt-gen/my_object.cxxqt.h" +#include "cxx-qt-gen/ffi.cxxqt.h" // Include the C++ code generated by rcc from the .qrc file #include "qml.qrc.cpp" diff --git a/examples/demo_threading/rust/src/lib.rs b/examples/demo_threading/rust/src/lib.rs index b1637f073..c674febc0 100644 --- a/examples/demo_threading/rust/src/lib.rs +++ b/examples/demo_threading/rust/src/lib.rs @@ -117,7 +117,7 @@ struct QtData { total_use: f64, } -#[cxx_qt::bridge(namespace = "cxx_qt::energy_usage")] +#[cxx_qt::bridge(cxx_file_stem = "energy_usage", namespace = "cxx_qt::energy_usage")] mod ffi { use super::{NetworkChannel, QtData, Request, RequestCommand, Response, SensorData, Status}; use async_std::{ diff --git a/examples/qml_extension_plugin/plugin/rust/src/lib.rs b/examples/qml_extension_plugin/plugin/rust/src/lib.rs index 51109d796..b6388666e 100644 --- a/examples/qml_extension_plugin/plugin/rust/src/lib.rs +++ b/examples/qml_extension_plugin/plugin/rust/src/lib.rs @@ -26,7 +26,7 @@ impl From<&MyObject> for DataSerde { const DEFAULT_STR: &str = r#"{"number": 1, "string": "Hello World!"}"#; -#[cxx_qt::bridge(namespace = "core")] +#[cxx_qt::bridge(cxx_file_stem = "my_object", namespace = "core")] mod ffi { use super::{DataSerde, DEFAULT_STR}; diff --git a/examples/qml_features/rust/src/custom_base.rs b/examples/qml_features/rust/src/custom_base.rs index a8c5e8d1b..48aeddd35 100644 --- a/examples/qml_features/rust/src/custom_base.rs +++ b/examples/qml_features/rust/src/custom_base.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // ANCHOR: book_macro_code -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "custom_base")] mod ffi { unsafe extern "C++" { include!(); diff --git a/examples/qml_features/rust/src/empty.rs b/examples/qml_features/rust/src/empty.rs index 4e2d01936..2448f3761 100644 --- a/examples/qml_features/rust/src/empty.rs +++ b/examples/qml_features/rust/src/empty.rs @@ -3,7 +3,7 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "empty")] mod ffi { #[cxx_qt::qobject] #[derive(Default)] diff --git a/examples/qml_features/rust/src/lib.rs b/examples/qml_features/rust/src/lib.rs index ade6853de..e4ecf642c 100644 --- a/examples/qml_features/rust/src/lib.rs +++ b/examples/qml_features/rust/src/lib.rs @@ -14,7 +14,7 @@ mod struct_properties; mod threading; mod types; -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "my_object")] mod ffi { unsafe extern "C++" { include!("cxx-qt-lib/qstring.h"); diff --git a/examples/qml_features/rust/src/mock_qt_types.rs b/examples/qml_features/rust/src/mock_qt_types.rs index bc57ef2f2..9fcc0b22c 100644 --- a/examples/qml_features/rust/src/mock_qt_types.rs +++ b/examples/qml_features/rust/src/mock_qt_types.rs @@ -4,7 +4,7 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "mock_qt_types")] mod ffi { use cxx_qt_lib::QVariantValue; diff --git a/examples/qml_features/rust/src/rust_obj_invokables.rs b/examples/qml_features/rust/src/rust_obj_invokables.rs index 2586be378..0ed1c245c 100644 --- a/examples/qml_features/rust/src/rust_obj_invokables.rs +++ b/examples/qml_features/rust/src/rust_obj_invokables.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // ANCHOR: book_macro_code -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "rust_obj_invokables")] pub mod ffi { #[cxx_qt::qobject] pub struct RustObjInvokables { diff --git a/examples/qml_features/rust/src/serialisation.rs b/examples/qml_features/rust/src/serialisation.rs index da1d1ada8..695a41c5b 100644 --- a/examples/qml_features/rust/src/serialisation.rs +++ b/examples/qml_features/rust/src/serialisation.rs @@ -23,7 +23,7 @@ impl From<&Serialisation> for DataSerde { } } -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "serialisation")] mod ffi { use super::DataSerde; diff --git a/examples/qml_features/rust/src/signals.rs b/examples/qml_features/rust/src/signals.rs index 0bf8d9bd0..be9218fae 100644 --- a/examples/qml_features/rust/src/signals.rs +++ b/examples/qml_features/rust/src/signals.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // ANCHOR: book_macro_code -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "signals")] pub mod ffi { unsafe extern "C++" { include!("cxx-qt-lib/qpoint.h"); diff --git a/examples/qml_features/rust/src/struct_properties.rs b/examples/qml_features/rust/src/struct_properties.rs index 683448f54..8e1fd9705 100644 --- a/examples/qml_features/rust/src/struct_properties.rs +++ b/examples/qml_features/rust/src/struct_properties.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // ANCHOR: book_macro_code -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "struct_properties")] mod ffi { #[cxx_qt::qobject] #[derive(Default)] diff --git a/examples/qml_features/rust/src/threading.rs b/examples/qml_features/rust/src/threading.rs index d440f92bd..dd6e119b5 100644 --- a/examples/qml_features/rust/src/threading.rs +++ b/examples/qml_features/rust/src/threading.rs @@ -5,7 +5,7 @@ // ANCHOR: book_macro_code // ANCHOR: book_namespace_macro -#[cxx_qt::bridge(namespace = "cxx_qt::website")] +#[cxx_qt::bridge(cxx_file_stem = "threading_website", namespace = "cxx_qt::website")] mod ffi { // ANCHOR_END: book_namespace_macro #[namespace = ""] diff --git a/examples/qml_features/rust/src/types.rs b/examples/qml_features/rust/src/types.rs index b982ed0ad..54215088b 100644 --- a/examples/qml_features/rust/src/types.rs +++ b/examples/qml_features/rust/src/types.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 // ANCHOR: book_macro_code -#[cxx_qt::bridge] +#[cxx_qt::bridge(cxx_file_stem = "types")] mod ffi { use cxx_qt_lib::QVariantValue; diff --git a/examples/qml_minimal/cpp/main.cpp b/examples/qml_minimal/cpp/main.cpp index 2aa9dea26..7218b1e4f 100644 --- a/examples/qml_minimal/cpp/main.cpp +++ b/examples/qml_minimal/cpp/main.cpp @@ -11,7 +11,7 @@ #include // ANCHOR: book_cpp_include -#include "cxx-qt-gen/my_object.cxxqt.h" +#include "cxx-qt-gen/ffi.cxxqt.h" // ANCHOR_END: book_cpp_include int diff --git a/examples/qml_minimal/tests/myobject/tst_myobject.cpp b/examples/qml_minimal/tests/myobject/tst_myobject.cpp index 1529d896c..1120ebf81 100644 --- a/examples/qml_minimal/tests/myobject/tst_myobject.cpp +++ b/examples/qml_minimal/tests/myobject/tst_myobject.cpp @@ -9,7 +9,7 @@ #include #include -#include "cxx-qt-gen/my_object.cxxqt.h" +#include "cxx-qt-gen/ffi.cxxqt.h" class Setup : public QObject { diff --git a/tests/basic_cxx_qt/rust/src/data.rs b/tests/basic_cxx_qt/rust/src/data.rs index df82fbb0e..872c087a2 100644 --- a/tests/basic_cxx_qt/rust/src/data.rs +++ b/tests/basic_cxx_qt/rust/src/data.rs @@ -22,7 +22,7 @@ impl From<&MyData> for DataSerde { } } -#[cxx_qt::bridge(namespace = "cxx_qt::my_data")] +#[cxx_qt::bridge(cxx_file_stem = "my_data", namespace = "cxx_qt::my_data")] mod ffi { use super::DataSerde; diff --git a/tests/basic_cxx_qt/rust/src/lib.rs b/tests/basic_cxx_qt/rust/src/lib.rs index d8c3eb2cd..caf625435 100644 --- a/tests/basic_cxx_qt/rust/src/lib.rs +++ b/tests/basic_cxx_qt/rust/src/lib.rs @@ -7,7 +7,7 @@ mod data; mod types; -#[cxx_qt::bridge(namespace = "cxx_qt::my_object")] +#[cxx_qt::bridge(cxx_file_stem = "my_object", namespace = "cxx_qt::my_object")] mod ffi { #[namespace = ""] unsafe extern "C++" { diff --git a/tests/basic_cxx_qt/rust/src/types.rs b/tests/basic_cxx_qt/rust/src/types.rs index dc4ef82a0..87fc99439 100644 --- a/tests/basic_cxx_qt/rust/src/types.rs +++ b/tests/basic_cxx_qt/rust/src/types.rs @@ -4,7 +4,7 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -#[cxx_qt::bridge(namespace = "cxx_qt::my_types")] +#[cxx_qt::bridge(cxx_file_stem = "my_types", namespace = "cxx_qt::my_types")] mod ffi { #[cxx_qt::qobject] #[derive(Default)]