diff --git a/crates/cxx-qt-build/src/dependencies.rs b/crates/cxx-qt-build/src/dependencies.rs index 659e55f55..8f4e111d4 100644 --- a/crates/cxx-qt-build/src/dependencies.rs +++ b/crates/cxx-qt-build/src/dependencies.rs @@ -7,100 +7,9 @@ use serde::{Deserialize, Serialize}; -use std::collections::HashSet; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; -/// When generating a library with cxx-qt-build, the library may need to export certain flags or headers. -/// These are all specified by this Interface struct, which should be passed to the [crate::CxxQtBuilder::library] function. -pub struct Interface { - // The name of the links keys, whose CXX-Qt dependencies to reexport - pub(crate) reexport_links: HashSet, - pub(crate) exported_include_prefixes: Vec, - pub(crate) exported_include_directories: Vec<(PathBuf, String)>, - // TODO: In future, we want to also set up the include paths so that you can include anything - // from the crates source directory. - // Once this is done, this flag should indicate whether or not to export our own crates source - // directory to downstream dependencies? - // export_crate_directory: bool, -} - -impl Default for Interface { - fn default() -> Self { - Self { - reexport_links: HashSet::new(), - exported_include_prefixes: vec![super::crate_name()], - exported_include_directories: Vec::new(), - } - } -} - -impl Interface { - /// Export all headers with the given prefix to downstream dependencies - /// - /// Note: This will overwrite any previously specified header_prefixes, including the default - /// header_prefix of this crate. - /// - /// This function will panic if any of the given prefixes are already exported through the - /// [Self::export_include_directory] function. - pub fn export_include_prefixes<'a>( - mut self, - prefixes: impl IntoIterator, - ) -> Self { - let prefixes = prefixes.into_iter().map(|item| item.to_string()).collect(); - - let mut exported_prefixes = self - .exported_include_directories - .iter() - .map(|(_path, prefix)| prefix); - for prefix in &prefixes { - if let Some(duplicate) = - exported_prefixes.find(|exported_prefix| exported_prefix.starts_with(prefix)) - { - panic!("Duplicate export_prefix! Cannot export `{prefix}`, as `{duplicate}` is already exported as an export_include_directory!"); - } - } - - self.exported_include_prefixes = prefixes; - self - } - - /// Add a directory that will be added as an include directory under the given prefix. - /// - /// The prefix will automatically be exported (see also: [Self::export_include_prefixes]) - /// - /// This function will panic if the given prefix is already exported. - pub fn export_include_directory(mut self, directory: impl AsRef, prefix: &str) -> Self { - let mut exported_prefixes = self.exported_include_prefixes.iter().chain( - self.exported_include_directories - .iter() - .map(|(_path, prefix)| prefix), - ); - if let Some(duplicate) = - exported_prefixes.find(|exported_prefix| exported_prefix.starts_with(prefix)) - { - panic!("Duplicate export_prefix! Cannot export `{prefix}`, as `{duplicate}` is already exported!"); - } - - self.exported_include_directories - .push((directory.as_ref().into(), prefix.to_owned())); - self - } - - /// Reexport the dependency with the given link name. - /// This will make the dependency available to downstream dependencies. - /// - /// Specifically it will reexport all include_prefixes of the given dependency - /// as well as any definitions made by that dependency. - /// - /// Note that the link name may differ from the crate name. - /// Check your dependencies manifest file for the correct link name. - pub fn reexport_dependency(mut self, link_name: &str) -> Self { - self.reexport_links.insert(link_name.to_owned()); - self - } -} - -#[derive(Clone, Serialize, Deserialize)] +#[derive(Clone, Default, Serialize, Deserialize)] /// This struct is used by cxx-qt-build internally to propagate data through to downstream /// dependencies pub(crate) struct Manifest { @@ -162,44 +71,3 @@ pub(crate) fn initializers(dependencies: &[Dependency]) -> Vec Vec { - interface - .exported_include_prefixes - .iter() - .cloned() - .chain( - interface - .exported_include_directories - .iter() - .map(|(_path, prefix)| prefix.clone()), - ) - .chain( - dependencies - .iter() - .flat_map(|dep| &dep.manifest.exported_include_prefixes) - .cloned(), - ) - .collect() -} - -pub(crate) fn reexported_dependencies( - interface: &Interface, - dependencies: &[Dependency], -) -> Vec { - let mut exported_dependencies = Vec::new(); - for link_name in &interface.reexport_links { - if let Some(dependency) = dependencies - .iter() - .find(|dep| &dep.manifest.link_name == link_name) - { - exported_dependencies.push(dependency.clone()); - } else { - panic!("Could not find dependency with link name `{link_name}` to reexport!"); - } - } - exported_dependencies -} diff --git a/crates/cxx-qt-build/src/dir.rs b/crates/cxx-qt-build/src/dir.rs index fc173821b..0691367a9 100644 --- a/crates/cxx-qt-build/src/dir.rs +++ b/crates/cxx-qt-build/src/dir.rs @@ -121,6 +121,10 @@ pub(crate) fn header_root() -> PathBuf { crate_target().join("include") } +pub(crate) fn header_root_interface() -> PathBuf { + target().join("include-interface") +} + /// The OUT_DIR, converted into a PathBuf pub(crate) fn out() -> PathBuf { env::var("OUT_DIR").unwrap().into() diff --git a/crates/cxx-qt-build/src/interface.rs b/crates/cxx-qt-build/src/interface.rs new file mode 100644 index 000000000..07226dcc4 --- /dev/null +++ b/crates/cxx-qt-build/src/interface.rs @@ -0,0 +1,210 @@ +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Leon Matthes +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! This modules contains utilities for specifying interfaces with cxx-qt-build. + +use std::collections::HashSet; + +use std::path::{Path, PathBuf}; + +use crate::{dir, dir::INCLUDE_VERB, Dependency, Manifest}; + +/// When generating a library with cxx-qt-build, the library may need to export certain flags or headers. +/// These are all specified by this Interface struct. +pub struct Interface { + // The name of the links keys, whose CXX-Qt dependencies to reexport + pub(crate) reexport_links: HashSet, + pub(crate) exported_include_prefixes: Vec, + pub(crate) exported_include_directories: Vec<(PathBuf, String)>, + pub(crate) manifest: Manifest, + pub(crate) dependencies: Vec, + // TODO: In future, we want to also set up the include paths so that you can include anything + // from the crates source directory. + // Once this is done, this flag should indicate whether or not to export our own crates source + // directory to downstream dependencies? + // export_crate_directory: bool, +} + +impl Default for Interface { + fn default() -> Self { + Self { + reexport_links: HashSet::new(), + exported_include_prefixes: vec![super::crate_name()], + exported_include_directories: Vec::new(), + manifest: Manifest::default(), + dependencies: Vec::new(), + } + } +} + +impl Interface { + /// Export all headers with the given prefix to downstream dependencies + /// + /// Note: This will overwrite any previously specified header_prefixes, including the default + /// header_prefix of this crate. + /// + /// This function will panic if any of the given prefixes are already exported through the + /// [Self::export_include_directory] function. + pub fn export_include_prefixes<'a>( + mut self, + prefixes: impl IntoIterator, + ) -> Self { + let prefixes = prefixes.into_iter().map(|item| item.to_string()).collect(); + + let mut exported_prefixes = self + .exported_include_directories + .iter() + .map(|(_path, prefix)| prefix); + for prefix in &prefixes { + if let Some(duplicate) = + exported_prefixes.find(|exported_prefix| exported_prefix.starts_with(prefix)) + { + panic!("Duplicate export_prefix! Cannot export `{prefix}`, as `{duplicate}` is already exported as an export_include_directory!"); + } + } + + self.exported_include_prefixes = prefixes; + self + } + + /// Add a directory that will be added as an include directory under the given prefix. + /// + /// The prefix will automatically be exported (see also: [Self::export_include_prefixes]) + /// + /// This function will panic if the given prefix is already exported. + pub fn export_include_directory(mut self, directory: impl AsRef, prefix: &str) -> Self { + let mut exported_prefixes = self.exported_include_prefixes.iter().chain( + self.exported_include_directories + .iter() + .map(|(_path, prefix)| prefix), + ); + if let Some(duplicate) = + exported_prefixes.find(|exported_prefix| exported_prefix.starts_with(prefix)) + { + panic!("Duplicate export_prefix! Cannot export `{prefix}`, as `{duplicate}` is already exported!"); + } + + self.exported_include_directories + .push((directory.as_ref().into(), prefix.to_owned())); + self + } + + /// Reexport the dependency with the given link name. + /// This will make the dependency available to downstream dependencies. + /// + /// Specifically it will reexport all include_prefixes of the given dependency + /// as well as any definitions made by that dependency. + /// + /// Note that the link name may differ from the crate name. + /// Check your dependencies manifest file for the correct link name. + pub fn reexport_dependency(mut self, link_name: &str) -> Self { + self.reexport_links.insert(link_name.to_owned()); + self + } + + /// Export the manifest for this crate so that is can be used by downstream + /// crates or CMake + pub fn export(mut self) { + // Ensure that a link name has been set + if self.manifest.link_name.is_empty() { + panic!("The links key must be set when exporting with CXX-Qt-build"); + } + + self.write_exported_include_directories(); + + // We automatically reexport all qt_modules and downstream dependencies + // as they will always need to be enabled in the final binary. + // However, we only reexport the headers of libraries that + // are marked as re-export. + let dependencies = reexported_dependencies(&self, &self.dependencies); + + self.manifest.exported_include_prefixes = all_include_prefixes(&self, &dependencies); + + let manifest_path = dir::crate_target().join("manifest.json"); + let manifest_json = serde_json::to_string_pretty(&self.manifest) + .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={}", + manifest_path.to_string_lossy() + ); + } + + fn write_exported_include_directories(&self) { + // Add any export directories as a child of the include interface directory + let header_root_interface = dir::header_root_interface(); + std::fs::create_dir_all(&header_root_interface) + .expect("Failed to create header root for interface"); + for (header_dir, dest) in &self.exported_include_directories { + let dest_dir = header_root_interface.join(dest); + // Relative paths are take from under the header root + // + // TODO: is this correct? + let header_dir = if header_dir.is_relative() { + dir::header_root().join(header_dir) + } else { + header_dir.clone() + }; + match dir::symlink_or_copy_directory(&header_dir, &dest_dir) { + Ok(true) => {}, + Ok(false) => panic!("Failed to create symlink folder for `{dest}`"), + Err(e) => panic!( + "Failed to {INCLUDE_VERB} `{dest}` for export_include_directory `{dir_name}`: {e:?}", + dir_name = header_dir.to_string_lossy() + ) + }; + } + + // Add any reexport links as a child of the include interface directory + let header_root = dir::header_root(); + for reexport in &self.reexport_links { + let source_dir = header_root.join(reexport); + let dest_dir = header_root_interface.join(reexport); + match dir::symlink_or_copy_directory(&source_dir, &dest_dir) { + Ok(true) => {}, + Ok(false) => panic!("Failed to create symlink folder for `{reexport}`"), + Err(e) => panic!( + "Failed to {INCLUDE_VERB} `{reexport}` for export_include_directory `{dir_name}`: {e:?}", + dir_name = source_dir.to_string_lossy() + ) + }; + } + } +} + +fn all_include_prefixes(interface: &Interface, dependencies: &[Dependency]) -> Vec { + interface + .exported_include_prefixes + .iter() + .cloned() + .chain( + interface + .exported_include_directories + .iter() + .map(|(_path, prefix)| prefix.clone()), + ) + .chain( + dependencies + .iter() + .flat_map(|dep| &dep.manifest.exported_include_prefixes) + .cloned(), + ) + .collect() +} + +fn reexported_dependencies(interface: &Interface, dependencies: &[Dependency]) -> Vec { + let mut exported_dependencies = Vec::new(); + for link_name in &interface.reexport_links { + if let Some(dependency) = dependencies + .iter() + .find(|dep| &dep.manifest.link_name == link_name) + { + exported_dependencies.push(dependency.clone()); + } else { + panic!("Could not find dependency with link name `{link_name}` to reexport!"); + } + } + exported_dependencies +} diff --git a/crates/cxx-qt-build/src/lib.rs b/crates/cxx-qt-build/src/lib.rs index 4cc23ce37..ebef8b80a 100644 --- a/crates/cxx-qt-build/src/lib.rs +++ b/crates/cxx-qt-build/src/lib.rs @@ -20,9 +20,11 @@ pub mod dir; use dir::INCLUDE_VERB; mod dependencies; -pub use dependencies::Interface; use dependencies::{Dependency, Manifest}; +mod interface; +pub use interface::Interface; + mod opts; pub use opts::CxxQtBuildersOpts; pub use opts::QObjectHeaderOpts; @@ -31,6 +33,8 @@ mod qml_modules; use qml_modules::OwningQmlModule; pub use qml_modules::QmlModule; +mod utils; + pub use qt_build_utils::MocArguments; use qt_build_utils::SemVer; use quote::ToTokens; @@ -368,7 +372,6 @@ pub struct CxxQtBuilder { qt_modules: HashSet, qml_modules: Vec, cc_builder: cc::Build, - public_interface: Option, include_prefix: String, } @@ -408,26 +411,10 @@ impl CxxQtBuilder { qt_modules, qml_modules: vec![], cc_builder: cc::Build::new(), - public_interface: None, include_prefix: crate_name(), } } - /// Create a new builder that is set up to create a library crate that is meant to be - /// included by later dependencies. - /// - /// The headers generated for this crate will be specified - pub fn library(interface_definition: Interface) -> Self { - let mut this = Self::new(); - this.public_interface = Some(interface_definition); - - if link_name().is_none() { - panic!("Building a Cxx-Qt based library requires setting a `links` field in the Cargo.toml file.\nConsider adding:\n\tlinks = \"{}\"\nto your Cargo.toml\n", crate_name()); - } - - this - } - /// Specify rust file paths to parse through the cxx-qt marco /// Relative paths are treated as relative to the path of your crate's Cargo.toml file pub fn file(mut self, rust_source: impl AsRef) -> Self { @@ -481,7 +468,7 @@ impl CxxQtBuilder { /// The `Core` module and any modules from dependencies are linked automatically; there is no need to specify them. /// /// Note that any qt_module you specify here will be enabled for all downstream - /// dependencies as well if this crate is built as a library with [CxxQtBuilder::library]. + /// dependencies as well if this crate is exported. /// It is therefore best practice to specify features on your crate that allow downstream users /// to disable any qt modules that are optional. pub fn qt_module(mut self, module: &str) -> Self { @@ -656,12 +643,18 @@ impl CxxQtBuilder { // or deep copy the files if the platform does not support symlinks. fn include_dependency(&mut self, dependency: &Dependency) { let header_root = dir::header_root(); - let dependency_root = dependency.path.join("include"); + // Note must be kept in sync with dir.rs + let dependency_root = dependency.path.join("include-interface"); for include_prefix in &dependency.manifest.exported_include_prefixes { // setup include directory let source = dependency_root.join(include_prefix); let dest = header_root.join(include_prefix); + // Not all crates have include interface, skip it this does not exist + if !Path::new(&source).is_dir() { + continue; + } + match dir::symlink_or_copy_directory(source, dest) { Ok(true) => (), Ok(false) => { @@ -1037,42 +1030,6 @@ extern "C" bool {init_fun}() {{ .collect() } - fn write_manifest( - &self, - dependencies: &[Dependency], - qt_modules: HashSet, - initializers: Vec, - ) { - if let Some(interface) = &self.public_interface { - // We automatically reexport all qt_modules and downstream dependencies - // as they will always need to be enabled in the final binary. - // However, we only reexport the headers of libraries that - // are marked as re-export. - let dependencies = dependencies::reexported_dependencies(interface, dependencies); - - let exported_include_prefixes = - dependencies::all_include_prefixes(interface, &dependencies); - - let manifest = Manifest { - name: crate_name(), - link_name: link_name() - .expect("The links key must be set when creating a library with CXX-Qt-build!"), - initializers, - qt_modules: qt_modules.into_iter().collect(), - exported_include_prefixes, - }; - - let manifest_path = dir::crate_target().join("manifest.json"); - let manifest_json = serde_json::to_string_pretty(&manifest) - .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={}", - manifest_path.to_string_lossy() - ); - } - } - fn qt_modules(&self, dependencies: &[Dependency]) -> HashSet { let mut qt_modules = self.qt_modules.clone(); for dependency in dependencies { @@ -1081,25 +1038,9 @@ extern "C" bool {init_fun}() {{ qt_modules } - fn write_interface_include_dirs(&self) { - let Some(interface) = &self.public_interface else { - return; - }; - let header_root = dir::header_root(); - for (header_dir, dest) in &interface.exported_include_directories { - let dest_dir = header_root.join(dest); - if let Err(e) = dir::symlink_or_copy_directory(header_dir, dest_dir) { - panic!( - "Failed to {INCLUDE_VERB} `{dest}` for export_include_directory `{dir_name}`: {e:?}", - dir_name = header_dir.to_string_lossy() - ) - }; - } - } - /// Generate and compile cxx-qt C++ code, as well as compile any additional files from /// [CxxQtBuilder::qobject_header] and [CxxQtBuilder::cc_builder]. - pub fn build(mut self) { + pub fn build(mut self) -> Interface { dir::clean(dir::crate_target()).expect("Failed to clean crate export directory!"); // We will do these two steps first, as setting up the dependencies can modify flags we @@ -1107,7 +1048,6 @@ extern "C" bool {init_fun}() {{ // Also write the common headers first, to make sure they don't conflict with any // dependencies Self::write_common_headers(); - self.write_interface_include_dirs(); let dependencies = Dependency::find_all(); for dependency in &dependencies { self.include_dependency(dependency); @@ -1134,6 +1074,18 @@ extern "C" bool {init_fun}() {{ // to the generated files without any namespacing. include_paths.push(header_root.join(&self.include_prefix)); + // Automatically add any header looking files to the header_root, so that they are + // a) in the include path + // b) able to be reexported + let manifest_dir = + PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("No CARGO_MANIFEST_DIR set")); + let max_depth = 6; + utils::best_effort_copy_headers( + manifest_dir.as_path(), + header_root.join(crate_name()).as_path(), + max_depth, + ); + Self::setup_cc_builder(&mut self.cc_builder, &include_paths); // Generate files @@ -1176,10 +1128,16 @@ extern "C" bool {init_fun}() {{ self.cc_builder.compile(&static_lib_name()); } - self.write_manifest( - &dependencies, - qt_modules, - vec![public_initializer.strip_file()], - ); + Interface { + manifest: Manifest { + name: crate_name(), + link_name: link_name().unwrap_or_default(), + initializers: vec![public_initializer.strip_file()], + qt_modules: qt_modules.into_iter().collect(), + exported_include_prefixes: vec![], + }, + dependencies, + ..Default::default() + } } } diff --git a/crates/cxx-qt-build/src/utils.rs b/crates/cxx-qt-build/src/utils.rs new file mode 100644 index 000000000..09f0e7f29 --- /dev/null +++ b/crates/cxx-qt-build/src/utils.rs @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: CXX Authors +// SPDX-FileContributor: Andrew Hayzen +// SPDX-FileContributor: David Tolnay +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +// Modified from +// https://github.com/dtolnay/cxx/blob/0608b11f31c40d6ca11abbf51395f16c4c16ad5e/gen/build/src/lib.rs#L426 + +use std::{ffi::OsStr, fs, path::Path}; + +pub(crate) fn best_effort_copy_headers(src: &Path, dst: &Path, max_depth: usize) { + let mut dst_created = false; + let Ok(mut entries) = fs::read_dir(src) else { + return; + }; + + while let Some(Ok(entry)) = entries.next() { + let file_name = entry.file_name(); + if file_name.to_string_lossy().starts_with('.') { + continue; + } + match entry.file_type() { + Ok(file_type) if file_type.is_dir() && max_depth > 0 => { + let src = entry.path(); + if src.join("Cargo.toml").exists() || src.join("CACHEDIR.TAG").exists() { + continue; + } + let dst = dst.join(file_name); + best_effort_copy_headers(&src, &dst, max_depth - 1); + } + Ok(file_type) if file_type.is_file() => { + let src = entry.path(); + match src.extension().and_then(OsStr::to_str) { + Some("h" | "hh" | "hpp") => {} + _ => continue, + } + if !dst_created && fs::create_dir_all(dst).is_err() { + return; + } + + // Ensure that we rebuild if there are changes + println!("cargo::rerun-if-changed={}", src.to_string_lossy()); + + dst_created = true; + let dst = dst.join(file_name); + let _ = fs::remove_file(&dst); + let _ = fs::copy(src, dst); + } + _ => {} + } + } +} diff --git a/crates/cxx-qt-gen/src/generator/cpp/cxxqttype.rs b/crates/cxx-qt-gen/src/generator/cpp/cxxqttype.rs index 0fbe10c17..321cf8d44 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/cxxqttype.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/cxxqttype.rs @@ -13,7 +13,7 @@ pub fn generate(qobject_idents: &QObjectNames) -> Result".to_owned()); + .insert("#include ".to_owned()); result .base_classes @@ -36,7 +36,9 @@ mod tests { // includes assert_eq!(generated.includes.len(), 1); - assert!(generated.includes.contains("#include ")); + assert!(generated + .includes + .contains("#include ")); // base class assert_eq!(generated.base_classes.len(), 1); diff --git a/crates/cxx-qt-gen/src/generator/cpp/externcxxqt.rs b/crates/cxx-qt-gen/src/generator/cpp/externcxxqt.rs index fd2bd1fdb..eb665502c 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/externcxxqt.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/externcxxqt.rs @@ -51,7 +51,9 @@ pub fn generate( // Include casting header let mut result = GeneratedCppExternCxxQtBlocks::default(); - result.includes.insert("#include ".into()); + result + .includes + .insert("#include ".into()); out.push(result); diff --git a/crates/cxx-qt-gen/src/generator/cpp/qobject.rs b/crates/cxx-qt-gen/src/generator/cpp/qobject.rs index 323f258ff..45fe6e98c 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/qobject.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/qobject.rs @@ -176,7 +176,9 @@ impl GeneratedCppQObject { // Include casting header let mut result = GeneratedCppQObjectBlocks::default(); - result.includes.insert("#include ".into()); + result + .includes + .insert("#include ".into()); generated.blocks.append(&mut result); diff --git a/crates/cxx-qt-gen/src/generator/cpp/signal.rs b/crates/cxx-qt-gen/src/generator/cpp/signal.rs index 1dc4808da..87d80cc34 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/signal.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/signal.rs @@ -96,7 +96,7 @@ pub fn generate_cpp_signal( // Add the include we need generated .includes - .insert("#include ".to_owned()); + .insert("#include ".to_owned()); // Build a namespace that includes any namespace for the T let qobject_ident_namespaced = qobject_name.cxx_qualified(); diff --git a/crates/cxx-qt-gen/src/generator/cpp/threading.rs b/crates/cxx-qt-gen/src/generator/cpp/threading.rs index 52eb3d1b6..0a300d824 100644 --- a/crates/cxx-qt-gen/src/generator/cpp/threading.rs +++ b/crates/cxx-qt-gen/src/generator/cpp/threading.rs @@ -30,7 +30,7 @@ pub fn generate(qobject_idents: &QObjectNames) -> Result<(String, GeneratedCppQO result .includes - .insert("#include ".to_owned()); + .insert("#include ".to_owned()); result .base_classes @@ -84,7 +84,9 @@ mod tests { // includes assert_eq!(generated.includes.len(), 1); - assert!(generated.includes.contains("#include ")); + assert!(generated + .includes + .contains("#include ")); // base class assert_eq!(generated.base_classes.len(), 1); diff --git a/crates/cxx-qt-gen/src/generator/rust/threading.rs b/crates/cxx-qt-gen/src/generator/rust/threading.rs index d0f2aae7f..488b13613 100644 --- a/crates/cxx-qt-gen/src/generator/rust/threading.rs +++ b/crates/cxx-qt-gen/src/generator/rust/threading.rs @@ -62,7 +62,7 @@ pub fn generate( #[namespace = #cxx_qt_thread_namespace] #(#cfgs)* type #cxx_qt_thread_ident = cxx_qt::CxxQtThread<#cpp_struct_ident>; - include!("cxx-qt/thread.h"); + include!("cxx-qt/include/thread.h"); #[doc(hidden)] #(#thread_fn_attrs)* @@ -209,7 +209,7 @@ mod tests { #[doc(hidden)] #[namespace = ""] type MyObjectCxxQtThread = cxx_qt::CxxQtThread; - include!("cxx-qt/thread.h"); + include!("cxx-qt/include/thread.h"); #[doc(hidden)] #[cxx_name = "qtThread"] diff --git a/crates/cxx-qt-gen/src/writer/cpp/header.rs b/crates/cxx-qt-gen/src/writer/cpp/header.rs index 645ff16ae..050a01b56 100644 --- a/crates/cxx-qt-gen/src/writer/cpp/header.rs +++ b/crates/cxx-qt-gen/src/writer/cpp/header.rs @@ -256,8 +256,8 @@ mod tests { let expected = indoc! {r#" #pragma once -#include -#include +#include +#include class MyObject; diff --git a/crates/cxx-qt-gen/src/writer/rust/mod.rs b/crates/cxx-qt-gen/src/writer/rust/mod.rs index c92f0cb68..ed4e11f2a 100644 --- a/crates/cxx-qt-gen/src/writer/rust/mod.rs +++ b/crates/cxx-qt-gen/src/writer/rust/mod.rs @@ -67,7 +67,7 @@ fn signal_boilerplate() -> TokenStream { unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] diff --git a/crates/cxx-qt-gen/test_outputs/cfgs.h b/crates/cxx-qt-gen/test_outputs/cfgs.h index 67e943c6e..2a1e51125 100644 --- a/crates/cxx-qt-gen/test_outputs/cfgs.h +++ b/crates/cxx-qt-gen/test_outputs/cfgs.h @@ -1,9 +1,9 @@ #pragma once #include -#include -#include -#include +#include +#include +#include class QObjectEnabled; diff --git a/crates/cxx-qt-gen/test_outputs/cfgs.rs b/crates/cxx-qt-gen/test_outputs/cfgs.rs index af2f2f565..dfe1b923f 100644 --- a/crates/cxx-qt-gen/test_outputs/cfgs.rs +++ b/crates/cxx-qt-gen/test_outputs/cfgs.rs @@ -3,7 +3,7 @@ mod ffi { unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.h b/crates/cxx-qt-gen/test_outputs/inheritance.h index 6e7700a3f..c5a44363c 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.h +++ b/crates/cxx-qt-gen/test_outputs/inheritance.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include class MyObject; diff --git a/crates/cxx-qt-gen/test_outputs/inheritance.rs b/crates/cxx-qt-gen/test_outputs/inheritance.rs index 3baf93952..3d710ae88 100644 --- a/crates/cxx-qt-gen/test_outputs/inheritance.rs +++ b/crates/cxx-qt-gen/test_outputs/inheritance.rs @@ -10,7 +10,7 @@ mod inheritance { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] diff --git a/crates/cxx-qt-gen/test_outputs/invokables.h b/crates/cxx-qt-gen/test_outputs/invokables.h index ad7cd7e04..fe1803c95 100644 --- a/crates/cxx-qt-gen/test_outputs/invokables.h +++ b/crates/cxx-qt-gen/test_outputs/invokables.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace cxx_qt::my_object { class MyObject; diff --git a/crates/cxx-qt-gen/test_outputs/invokables.rs b/crates/cxx-qt-gen/test_outputs/invokables.rs index 9ee861444..68c9a9cc8 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 ! (< QtCore / QObject >); - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] @@ -125,7 +125,7 @@ mod ffi { #[doc(hidden)] #[namespace = "cxx_qt::my_object"] type MyObjectCxxQtThread = cxx_qt::CxxQtThread; - include!("cxx-qt/thread.h"); + include!("cxx-qt/include/thread.h"); #[doc(hidden)] #[cxx_name = "qtThread"] #[namespace = "rust::cxxqt1"] diff --git a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h index 76dafdad2..6c8c4b3eb 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace cxx_qt::multi_object { class MyObject; diff --git a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs index 40fe6462d..3a4166640 100644 --- a/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs +++ b/crates/cxx-qt-gen/test_outputs/passthrough_and_naming.rs @@ -57,7 +57,7 @@ pub mod ffi { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] diff --git a/crates/cxx-qt-gen/test_outputs/properties.h b/crates/cxx-qt-gen/test_outputs/properties.h index ee9caf2b1..f2a140bbe 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.h +++ b/crates/cxx-qt-gen/test_outputs/properties.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace cxx_qt::my_object { class MyObject; diff --git a/crates/cxx-qt-gen/test_outputs/properties.rs b/crates/cxx-qt-gen/test_outputs/properties.rs index 440e13c7a..6f8c6e9eb 100644 --- a/crates/cxx-qt-gen/test_outputs/properties.rs +++ b/crates/cxx-qt-gen/test_outputs/properties.rs @@ -8,7 +8,7 @@ mod ffi { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] diff --git a/crates/cxx-qt-gen/test_outputs/qenum.h b/crates/cxx-qt-gen/test_outputs/qenum.h index a81c424c2..3f220a693 100644 --- a/crates/cxx-qt-gen/test_outputs/qenum.h +++ b/crates/cxx-qt-gen/test_outputs/qenum.h @@ -3,8 +3,8 @@ #include #include #include -#include -#include +#include +#include namespace cxx_qt::my_object { class MyObject; diff --git a/crates/cxx-qt-gen/test_outputs/qenum.rs b/crates/cxx-qt-gen/test_outputs/qenum.rs index f054521d1..d17441d29 100644 --- a/crates/cxx-qt-gen/test_outputs/qenum.rs +++ b/crates/cxx-qt-gen/test_outputs/qenum.rs @@ -3,7 +3,7 @@ mod ffi { unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] diff --git a/crates/cxx-qt-gen/test_outputs/signals.h b/crates/cxx-qt-gen/test_outputs/signals.h index bad91af1b..d4a3be9d6 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.h +++ b/crates/cxx-qt-gen/test_outputs/signals.h @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace cxx_qt::my_object { class MyObject; diff --git a/crates/cxx-qt-gen/test_outputs/signals.rs b/crates/cxx-qt-gen/test_outputs/signals.rs index ba6f41b6e..2aa3423a5 100644 --- a/crates/cxx-qt-gen/test_outputs/signals.rs +++ b/crates/cxx-qt-gen/test_outputs/signals.rs @@ -9,7 +9,7 @@ mod ffi { } unsafe extern "C++" { include ! (< QtCore / QObject >); - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] #[namespace = "Qt"] #[rust_name = "CxxQtConnectionType"] diff --git a/crates/cxx-qt-lib-extras/build.rs b/crates/cxx-qt-lib-extras/build.rs index 8e6b5c125..f3c88f18a 100644 --- a/crates/cxx-qt-lib-extras/build.rs +++ b/crates/cxx-qt-lib-extras/build.rs @@ -4,53 +4,9 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use cxx_qt_build::CxxQtBuilder; -use std::path::PathBuf; - -fn header_dir() -> PathBuf { - PathBuf::from(std::env::var("OUT_DIR").unwrap()) - .join("include") - .join("cxx-qt-lib-extras") -} - -fn write_headers_in(subfolder: &str) { - println!("cargo::rerun-if-changed=include/{subfolder}"); - - for entry in - std::fs::read_dir(format!("include/{subfolder}")).expect("Failed to read include directory") - { - let entry = entry.expect("Failed to read header file!"); - let header_name = entry.file_name(); - println!( - "cargo::rerun-if-changed=include/{subfolder}/{header_name}", - header_name = header_name.to_string_lossy() - ); - - // TODO: Do we want to add the headers into a subdirectory? - std::fs::copy(entry.path(), header_dir().join(header_name)) - .expect("Failed to copy header file!"); - } -} - -fn write_headers() { - println!("cargo::rerun-if-changed=include/"); - std::fs::create_dir_all(header_dir()).expect("Failed to create include directory"); - - write_headers_in("core"); - write_headers_in("gui"); -} fn main() { - write_headers(); - - let interface = cxx_qt_build::Interface::default() - // Disable exporting the standard include directory, as we are exporting custom headers - .export_include_prefixes([]) - .export_include_directory(header_dir(), "cxx-qt-lib-extras") - .reexport_dependency("cxx-qt-lib"); - - let mut builder = CxxQtBuilder::library(interface) - .qt_module("Gui") - .qt_module("Widgets"); + let mut builder = CxxQtBuilder::new().qt_module("Gui").qt_module("Widgets"); let rust_bridges = vec![ "core/qelapsedtimer", @@ -80,7 +36,16 @@ fn main() { }); println!("cargo::rerun-if-changed=src/assertion_utils.h"); - // Use a short name due to the Windows file path limit! - // We don't re-export these headers anyway. - builder.include_prefix("private").build(); + let interface = builder + // Use a short name due to the Windows file path limit! + // We don't re-export these headers anyway. + .include_prefix("private") + .build(); + + // Disable exporting the standard include directory, as we are exporting custom header + interface + .export_include_prefixes([]) + .export_include_directory("cxx-qt-lib-extras", "cxx-qt-lib-extras") + .reexport_dependency("cxx-qt-lib") + .export(); } diff --git a/crates/cxx-qt-lib-extras/include/gui/qapplication.h b/crates/cxx-qt-lib-extras/include/qapplication.h similarity index 100% rename from crates/cxx-qt-lib-extras/include/gui/qapplication.h rename to crates/cxx-qt-lib-extras/include/qapplication.h diff --git a/crates/cxx-qt-lib-extras/include/core/qcommandlineoption.h b/crates/cxx-qt-lib-extras/include/qcommandlineoption.h similarity index 100% rename from crates/cxx-qt-lib-extras/include/core/qcommandlineoption.h rename to crates/cxx-qt-lib-extras/include/qcommandlineoption.h diff --git a/crates/cxx-qt-lib-extras/include/core/qcommandlineparser.h b/crates/cxx-qt-lib-extras/include/qcommandlineparser.h similarity index 100% rename from crates/cxx-qt-lib-extras/include/core/qcommandlineparser.h rename to crates/cxx-qt-lib-extras/include/qcommandlineparser.h diff --git a/crates/cxx-qt-lib-extras/include/core/qelapsedtimer.h b/crates/cxx-qt-lib-extras/include/qelapsedtimer.h similarity index 100% rename from crates/cxx-qt-lib-extras/include/core/qelapsedtimer.h rename to crates/cxx-qt-lib-extras/include/qelapsedtimer.h diff --git a/crates/cxx-qt-lib-extras/src/core/qcommandlineoption.cpp b/crates/cxx-qt-lib-extras/src/core/qcommandlineoption.cpp index cb39b7981..fb75762b2 100644 --- a/crates/cxx-qt-lib-extras/src/core/qcommandlineoption.cpp +++ b/crates/cxx-qt-lib-extras/src/core/qcommandlineoption.cpp @@ -4,7 +4,7 @@ // SPDX-FileContributor: Laurent Montel // // SPDX-License-Identifier: MIT OR Apache-2.0 -#include "cxx-qt-lib-extras/qcommandlineoption.h" +#include "cxx-qt-lib-extras/include/qcommandlineoption.h" #include diff --git a/crates/cxx-qt-lib-extras/src/core/qcommandlineoption.rs b/crates/cxx-qt-lib-extras/src/core/qcommandlineoption.rs index 6eca63227..36c2fc46d 100644 --- a/crates/cxx-qt-lib-extras/src/core/qcommandlineoption.rs +++ b/crates/cxx-qt-lib-extras/src/core/qcommandlineoption.rs @@ -9,7 +9,7 @@ use std::mem::MaybeUninit; #[cxx::bridge] mod ffi { unsafe extern "C++" { - include!("cxx-qt-lib-extras/qcommandlineoption.h"); + include!("cxx-qt-lib-extras/include/qcommandlineoption.h"); type QCommandLineOption = super::QCommandLineOption; include!("cxx-qt-lib/qstring.h"); type QString = cxx_qt_lib::QString; diff --git a/crates/cxx-qt-lib-extras/src/core/qcommandlineparser.cpp b/crates/cxx-qt-lib-extras/src/core/qcommandlineparser.cpp index 7904ce552..06b79cadd 100644 --- a/crates/cxx-qt-lib-extras/src/core/qcommandlineparser.cpp +++ b/crates/cxx-qt-lib-extras/src/core/qcommandlineparser.cpp @@ -4,7 +4,7 @@ // SPDX-FileContributor: Laurent Montel // // SPDX-License-Identifier: MIT OR Apache-2.0 -#include "cxx-qt-lib-extras/qcommandlineparser.h" +#include "cxx-qt-lib-extras/include/qcommandlineparser.h" #include diff --git a/crates/cxx-qt-lib-extras/src/core/qcommandlineparser.rs b/crates/cxx-qt-lib-extras/src/core/qcommandlineparser.rs index 9487197da..086a5729d 100644 --- a/crates/cxx-qt-lib-extras/src/core/qcommandlineparser.rs +++ b/crates/cxx-qt-lib-extras/src/core/qcommandlineparser.rs @@ -33,9 +33,9 @@ mod ffi { } unsafe extern "C++" { - include!("cxx-qt-lib-extras/qcommandlineparser.h"); + include!("cxx-qt-lib-extras/include/qcommandlineparser.h"); type QCommandLineParser = super::QCommandLineParser; - include!("cxx-qt-lib-extras/qcommandlineoption.h"); + include!("cxx-qt-lib-extras/include/qcommandlineoption.h"); type QCommandLineOption = crate::QCommandLineOption; include!("cxx-qt-lib/qstring.h"); diff --git a/crates/cxx-qt-lib-extras/src/core/qelapsedtimer.cpp b/crates/cxx-qt-lib-extras/src/core/qelapsedtimer.cpp index 74b438ef7..ea81a0843 100644 --- a/crates/cxx-qt-lib-extras/src/core/qelapsedtimer.cpp +++ b/crates/cxx-qt-lib-extras/src/core/qelapsedtimer.cpp @@ -4,7 +4,7 @@ // SPDX-FileContributor: Laurent Montel // // SPDX-License-Identifier: MIT OR Apache-2.0 -#include "cxx-qt-lib-extras/qelapsedtimer.h" +#include "cxx-qt-lib-extras/include/qelapsedtimer.h" #include diff --git a/crates/cxx-qt-lib-extras/src/core/qelapsedtimer.rs b/crates/cxx-qt-lib-extras/src/core/qelapsedtimer.rs index 6235c941a..1e2bac370 100644 --- a/crates/cxx-qt-lib-extras/src/core/qelapsedtimer.rs +++ b/crates/cxx-qt-lib-extras/src/core/qelapsedtimer.rs @@ -8,7 +8,7 @@ use cxx::{type_id, ExternType}; #[cxx::bridge] mod ffi { unsafe extern "C++" { - include!("cxx-qt-lib-extras/qelapsedtimer.h"); + include!("cxx-qt-lib-extras/include/qelapsedtimer.h"); type QElapsedTimer = crate::QElapsedTimer; /// Returns false if the timer has never been started or invalidated by a call to invalidate(). diff --git a/crates/cxx-qt-lib-extras/src/gui/qapplication.cpp b/crates/cxx-qt-lib-extras/src/gui/qapplication.cpp index 6a64ad836..1933ca835 100644 --- a/crates/cxx-qt-lib-extras/src/gui/qapplication.cpp +++ b/crates/cxx-qt-lib-extras/src/gui/qapplication.cpp @@ -5,7 +5,7 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -#include "cxx-qt-lib-extras/qapplication.h" +#include "cxx-qt-lib-extras/include/qapplication.h" #include "cxx-qt-lib/qcoreapplication.h" diff --git a/crates/cxx-qt-lib-extras/src/gui/qapplication.rs b/crates/cxx-qt-lib-extras/src/gui/qapplication.rs index 3cc9a9f7b..b917cfeca 100644 --- a/crates/cxx-qt-lib-extras/src/gui/qapplication.rs +++ b/crates/cxx-qt-lib-extras/src/gui/qapplication.rs @@ -20,7 +20,7 @@ mod ffi { include!("cxx-qt-lib/qfont.h"); type QFont = cxx_qt_lib::QFont; - include!("cxx-qt-lib-extras/qapplication.h"); + include!("cxx-qt-lib-extras/include/qapplication.h"); type QApplication; } diff --git a/crates/cxx-qt-lib/build.rs b/crates/cxx-qt-lib/build.rs index 99932b43c..5d82b05c2 100644 --- a/crates/cxx-qt-lib/build.rs +++ b/crates/cxx-qt-lib/build.rs @@ -346,12 +346,7 @@ fn main() { cpp_files.extend(["core/qdatetime", "core/qtimezone"]); } - let interface = cxx_qt_build::Interface::default() - .export_include_prefixes([]) - .export_include_directory(header_dir(), "cxx-qt-lib") - .reexport_dependency("cxx-qt"); - - let mut builder = CxxQtBuilder::library(interface) + let mut builder = CxxQtBuilder::new() // Use a short name due to the Windows file path limit! // We don't re-export these headers anyway .include_prefix("private") @@ -388,6 +383,16 @@ fn main() { } cc.file("src/qt_types.cpp"); println!("cargo::rerun-if-changed=src/qt_types.cpp"); + + // With cxx-qt-lib we need to have generated headers in the include folder + // so we copy them into the OUT_DIR and construct a folder + cc.include(header_dir().parent().expect("header_dir has a parent")); }); - builder.build(); + + let interface = builder.build(); + interface + .export_include_prefixes([]) + .export_include_directory(header_dir(), "cxx-qt-lib") + .reexport_dependency("cxx-qt") + .export(); } diff --git a/crates/cxx-qt-lib/include/core/qmetaobjectconnection.h b/crates/cxx-qt-lib/include/core/qmetaobjectconnection.h index e0160428e..6494d28b0 100644 --- a/crates/cxx-qt-lib/include/core/qmetaobjectconnection.h +++ b/crates/cxx-qt-lib/include/core/qmetaobjectconnection.h @@ -7,4 +7,4 @@ #pragma once // Re-export QMetaObjectConnection from cxx-qt -#include "cxx-qt/connection.h" +#include "cxx-qt/include/connection.h" diff --git a/crates/cxx-qt-lib/src/core/qstringlist.rs b/crates/cxx-qt-lib/src/core/qstringlist.rs index fbb6eb806..19c3e05a0 100644 --- a/crates/cxx-qt-lib/src/core/qstringlist.rs +++ b/crates/cxx-qt-lib/src/core/qstringlist.rs @@ -28,7 +28,7 @@ mod ffi { include!("cxx-qt-lib/qstringlist.h"); type QStringList = super::QStringList; - include!("cxx-qt/casting.h"); + include!("cxx-qt/include/casting.h"); #[doc(hidden)] #[rust_name = "upcast_qstringlist"] diff --git a/crates/cxx-qt/build.rs b/crates/cxx-qt/build.rs index 0f0f2956d..01c501b57 100644 --- a/crates/cxx-qt/build.rs +++ b/crates/cxx-qt/build.rs @@ -3,42 +3,10 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -use std::path::PathBuf; - -use cxx_qt_build::{CxxQtBuilder, Interface}; - -fn header_dir() -> PathBuf { - PathBuf::from(std::env::var("OUT_DIR").unwrap()) - .join("include") - .join("cxx-qt") -} - -fn write_headers() { - println!("cargo::rerun-if-changed=include/"); - std::fs::create_dir_all(header_dir()).expect("Failed to create include directory"); - - for file_path in [ - "connection.h", - "casting.h", - "signalhandler.h", - "thread.h", - "threading.h", - "type.h", - ] { - println!("cargo::rerun-if-changed=include/{file_path}"); - std::fs::copy(format!("include/{file_path}"), header_dir().join(file_path)) - .expect("Failed to copy header file!"); - } -} +use cxx_qt_build::CxxQtBuilder; fn main() { - write_headers(); - - let interface = Interface::default() - .export_include_prefixes([]) - .export_include_directory(header_dir(), "cxx-qt"); - - let mut builder = CxxQtBuilder::library(interface); + let mut builder = CxxQtBuilder::new(); let cpp_files = ["src/connection.cpp"]; let rust_bridges = ["src/connection.rs", "src/qobject.rs"]; @@ -58,5 +26,9 @@ fn main() { ..qt_build_utils::Initializer::default_signature("init_cxx_qt_core") }); - builder.build(); + let interface = builder.build(); + interface + .export_include_prefixes([]) + .export_include_directory("cxx-qt", "cxx-qt") + .export(); } diff --git a/crates/cxx-qt/include/threading.h b/crates/cxx-qt/include/threading.h index c8205a94c..75502c3f0 100644 --- a/crates/cxx-qt/include/threading.h +++ b/crates/cxx-qt/include/threading.h @@ -10,7 +10,7 @@ #include #include -#include +#include namespace rust::cxxqt1 { diff --git a/crates/cxx-qt/src/connection.cpp b/crates/cxx-qt/src/connection.cpp index 90f4f2973..dcee904f8 100644 --- a/crates/cxx-qt/src/connection.cpp +++ b/crates/cxx-qt/src/connection.cpp @@ -4,7 +4,7 @@ // SPDX-FileContributor: Andrew Hayzen // // SPDX-License-Identifier: MIT OR Apache-2.0 -#include "cxx-qt/connection.h" +#include "cxx-qt/include/connection.h" #include diff --git a/crates/cxx-qt/src/connection.rs b/crates/cxx-qt/src/connection.rs index f4ad9fdc1..b184e32b9 100644 --- a/crates/cxx-qt/src/connection.rs +++ b/crates/cxx-qt/src/connection.rs @@ -9,7 +9,7 @@ use std::mem::MaybeUninit; mod ffi { #[namespace = "rust::cxxqt1"] unsafe extern "C++" { - include!("cxx-qt/connection.h"); + include!("cxx-qt/include/connection.h"); #[doc(hidden)] type QMetaObjectConnection = crate::QMetaObjectConnection; diff --git a/crates/cxx-qt/src/lib.rs b/crates/cxx-qt/src/lib.rs index ea6f18ae9..18998435a 100644 --- a/crates/cxx-qt/src/lib.rs +++ b/crates/cxx-qt/src/lib.rs @@ -11,7 +11,6 @@ use std::ops::Deref; use std::pin::Pin; -use std::{fs::File, io::Write, path::Path}; mod connection; mod connectionguard; @@ -522,28 +521,3 @@ where Self::initialize(self); } } - -#[doc(hidden)] -// Write the cxx-qt headers to the specified directory. -pub fn write_headers(directory: impl AsRef) { - let directory = directory.as_ref(); - std::fs::create_dir_all(directory).expect("Could not create cxx-qt header directory"); - // Note ensure that the build script is consistent with files that are copied - for (file_contents, file_name) in [ - (include_str!("../include/connection.h"), "connection.h"), - ( - include_str!("../include/signalhandler.h"), - "signalhandler.h", - ), - (include_str!("../include/thread.h"), "thread.h"), - (include_str!("../include/threading.h"), "threading.h"), - (include_str!("../include/type.h"), "type.h"), - ] { - // Note that we do not need rerun-if-changed for these files - // as include_str causes a rerun when the header changes - // and the files are always written to the target. - let h_path = format!("{}/{file_name}", directory.display()); - let mut header = File::create(h_path).expect("Could not create cxx-qt header"); - write!(header, "{file_contents}").expect("Could not write cxx-qt header"); - } -} diff --git a/examples/qml_multi_crates/rust/sub1/build.rs b/examples/qml_multi_crates/rust/sub1/build.rs index 6652b1c0d..bc6dca6f7 100644 --- a/examples/qml_multi_crates/rust/sub1/build.rs +++ b/examples/qml_multi_crates/rust/sub1/build.rs @@ -3,16 +3,16 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -use cxx_qt_build::{CxxQtBuilder, Interface, QmlModule}; +use cxx_qt_build::{CxxQtBuilder, QmlModule}; fn main() { - let interface = Interface::default(); - CxxQtBuilder::library(interface) + CxxQtBuilder::new() .qt_module("Network") .qml_module(QmlModule::<_, &str> { uri: "com.kdab.cxx_qt.demo.sub1", rust_files: &["src/sub1_object.rs"], ..Default::default() }) - .build(); + .build() + .export(); } diff --git a/examples/qml_multi_crates/rust/sub2/build.rs b/examples/qml_multi_crates/rust/sub2/build.rs index cdbb1c9a2..844eb37b1 100644 --- a/examples/qml_multi_crates/rust/sub2/build.rs +++ b/examples/qml_multi_crates/rust/sub2/build.rs @@ -3,15 +3,15 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -use cxx_qt_build::{CxxQtBuilder, Interface, QmlModule}; +use cxx_qt_build::{CxxQtBuilder, QmlModule}; fn main() { - let interface = Interface::default(); - CxxQtBuilder::library(interface) + CxxQtBuilder::new() .qml_module(QmlModule::<_, &str> { uri: "com.kdab.cxx_qt.demo.sub2", rust_files: &["src/sub2_object.rs"], ..Default::default() }) - .build(); + .build() + .export(); }