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-lib: remove cxx-qt-lib-headers and store in cxx-qt-lib #842

Closed
Closed
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: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ members = [
"crates/cxx-qt-build",
"crates/cxx-qt-gen",
"crates/cxx-qt-lib",
"crates/cxx-qt-lib-headers",
"crates/qt-build-utils",

"examples/cargo_without_cmake",
Expand Down Expand Up @@ -37,7 +36,6 @@ cxx-qt-macro = { path = "crates/cxx-qt-macro", version = "0.6.0" }
cxx-qt-build = { path = "crates/cxx-qt-build" }
cxx-qt-gen = { path = "crates/cxx-qt-gen", version = "0.6.0" }
cxx-qt-lib = { path = "crates/cxx-qt-lib" }
cxx-qt-lib-headers = { path = "crates/cxx-qt-lib-headers", version = "0.6.0" }
qt-build-utils = { path = "crates/qt-build-utils", version = "0.6.0" }

cc = { version = "1.0.86", features = ["parallel"] }
Expand Down
20 changes: 0 additions & 20 deletions crates/cxx-qt-lib-headers/Cargo.toml

This file was deleted.

117 changes: 0 additions & 117 deletions crates/cxx-qt-lib-headers/src/lib.rs

This file was deleted.

6 changes: 3 additions & 3 deletions crates/cxx-qt-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exclude = [ "**/generate.sh" ]
[dependencies]
cxx.workspace = true
cxx-qt.workspace = true
cxx-qt-build.workspace = true
bytes = { version = "1.4", optional = true }
chrono = { version = "0.4.27", optional = true }
http = { version = "1.0", optional = true }
Expand All @@ -25,7 +26,6 @@ url = { version = "2.3", optional = true }

[build-dependencies]
cxx-qt-build.workspace = true
cxx-qt-lib-headers.workspace = true
qt-build-utils.workspace = true

[features]
Expand All @@ -34,8 +34,8 @@ bytes = ["dep:bytes"]
chrono = ["dep:chrono"]
http = ["dep:http"]
rgb = ["dep:rgb"]
qt_gui = ["cxx-qt-lib-headers/qt_gui"]
qt_qml = ["cxx-qt-lib-headers/qt_qml"]
qt_gui = []
qt_qml = []
time = ["dep:time"]
url = ["dep:url"]
link_qt_object_files = ["qt-build-utils/link_qt_object_files"]
57 changes: 56 additions & 1 deletion crates/cxx-qt-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,60 @@ fn main() {
});
println!("cargo:rerun-if-changed=src/assertion_utils.h");

builder.with_opts(cxx_qt_lib_headers::build_opts()).build();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes cxx-qt-lib worse to build as we need to duplicate the header copy phase :-/

fn copy_dir(src: impl AsRef<std::path::Path>, dest: impl AsRef<std::path::Path>) {
let dest = dest.as_ref();
let src = src.as_ref();
if src.is_dir() {
std::fs::create_dir_all(dest).expect("could not create directory {dest}");
for entry in std::fs::read_dir(src).expect("could not read dir {src}") {
let entry = entry.expect("could not retrieve entry for dir {src}");
let path = entry.path();
let file_name = entry
.file_name()
.into_string()
.expect("cannot convert OsString to String");
let dest = dest.display();
if path.is_file() {
std::fs::copy(path, format!("{dest}/{file_name}"))
.expect("could not copy {path}");
}
}
}
}

// Write this library's manually written C++ headers to files and add them to include paths
let header_root = format!("{}/include", std::env::var("OUT_DIR").unwrap());
copy_dir("include/core", format!("{header_root}/cxx-qt-lib"));
copy_dir("include/gui", format!("{header_root}/cxx-qt-lib"));
copy_dir("include/qml", format!("{header_root}/cxx-qt-lib"));
std::fs::copy(
"include/common.h",
format!("{header_root}/cxx-qt-lib/common.h"),
)
.expect("could not copy common.h");

if feature_qt_gui_enabled {
builder = builder.qt_module("Gui");
}

if feature_qt_qml_enabled {
builder = builder.qt_module("Qml");
}

builder = builder.cc_builder(|cc| {
// Load the include path
cc.include(&header_root);

// Enable Qt Gui in C++ if the feature is enabled
if feature_qt_gui_enabled {
cc.define("CXX_QT_GUI_FEATURE", None);
}

// Enable Qt Qml in C++ if the feature is enabled
if feature_qt_gui_enabled {
cc.define("CXX_QT_QML_FEATURE", None);
}
});

builder.build();
}
107 changes: 107 additions & 0 deletions crates/cxx-qt-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,110 @@ pub use crate::gui::*;
mod qml;
#[cfg(feature = "qt_qml")]
pub use crate::qml::*;

/// Retrieves the headers for cxx-qt-lib
///
/// These can be passed into [cxx_qt_build::CxxQtBuilder].
pub fn build_opts() -> cxx_qt_build::CxxQtBuildersOpts {
let mut opts = cxx_qt_build::CxxQtBuildersOpts::default();

for (file_contents, file_name) in [
(include_str!("../include/core/qbytearray.h"), "qbytearray.h"),
(
include_str!("../include/core/qcoreapplication.h"),
"qcoreapplication.h",
),
(include_str!("../include/core/qdate.h"), "qdate.h"),
(include_str!("../include/core/qdatetime.h"), "qdatetime.h"),
(include_str!("../include/core/qhash.h"), "qhash.h"),
(include_str!("../include/core/qline.h"), "qline.h"),
(include_str!("../include/core/qlinef.h"), "qlinef.h"),
(include_str!("../include/core/qlist.h"), "qlist.h"),
(
include_str!("../include/core/qlist_qvector.h"),
"qlist_qvector.h",
),
(include_str!("../include/core/qmap.h"), "qmap.h"),
(include_str!("../include/core/qmargins.h"), "qmargins.h"),
(include_str!("../include/core/qmarginsf.h"), "qmarginsf.h"),
(
include_str!("../include/core/qmetaobjectconnection.h"),
"qmetaobjectconnection.h",
),
(
include_str!("../include/core/qmodelindex.h"),
"qmodelindex.h",
),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qpen.h"), "qpen.h"),
(
include_str!("../include/core/qpersistentmodelindex.h"),
"qpersistentmodelindex.h",
),
(include_str!("../include/core/qpoint.h"), "qpoint.h"),
(include_str!("../include/core/qpointf.h"), "qpointf.h"),
(include_str!("../include/core/qrect.h"), "qrect.h"),
(include_str!("../include/core/qrectf.h"), "qrectf.h"),
(include_str!("../include/core/qset.h"), "qset.h"),
(include_str!("../include/core/qsize.h"), "qsize.h"),
(include_str!("../include/core/qsizef.h"), "qsizef.h"),
(include_str!("../include/core/qstring.h"), "qstring.h"),
(
include_str!("../include/core/qstringlist.h"),
"qstringlist.h",
),
(include_str!("../include/core/qt.h"), "qt.h"),
(include_str!("../include/core/qtime.h"), "qtime.h"),
(include_str!("../include/core/qtimezone.h"), "qtimezone.h"),
(include_str!("../include/core/qurl.h"), "qurl.h"),
(include_str!("../include/core/qvariant.h"), "qvariant.h"),
(include_str!("../include/core/qvector.h"), "qvector.h"),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qcolor.h"), "qcolor.h"),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qfont.h"), "qfont.h"),
#[cfg(feature = "qt_gui")]
(
include_str!("../include/gui/qguiapplication.h"),
"qguiapplication.h",
),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qimage.h"), "qimage.h"),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qpolygon.h"), "qpolygon.h"),
(include_str!("../include/gui/qpolygonf.h"), "qpolygonf.h"),
(
include_str!("../include/gui/qpainterpath.h"),
"qpainterpath.h",
),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qpainter.h"), "qpainter.h"),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qvector2d.h"), "qvector2d.h"),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qvector3d.h"), "qvector3d.h"),
#[cfg(feature = "qt_gui")]
(include_str!("../include/gui/qvector4d.h"), "qvector4d.h"),
#[cfg(feature = "qt_qml")]
(
include_str!("../include/qml/qqmlapplicationengine.h"),
"qqmlapplicationengine.h",
),
#[cfg(feature = "qt_qml")]
(include_str!("../include/qml/qqmlengine.h"), "qqmlengine.h"),
(include_str!("../include/common.h"), "common.h"),
] {
opts = opts.header(file_contents, "cxx-qt-lib", file_name);
}

#[cfg(feature = "qt_gui")]
{
opts = opts.define("CXX_QT_GUI_FEATURE");
}
#[cfg(feature = "qt_qml")]
{
opts = opts.define("CXX_QT_QML_FEATURE");
}

opts
}
4 changes: 2 additions & 2 deletions examples/cargo_without_cmake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ cxx-qt-lib.workspace = true
# Use `cxx-qt-build = "0.6"` here instead!
# The link_qt_object_files feature is required for statically linking Qt 6.
cxx-qt-build = { workspace = true, features = [ "link_qt_object_files" ] }
# Use `cxx-qt-lib-headers = "0.6"` here instead!
cxx-qt-lib-headers.workspace = true
# Use `cxx-qt-lib = "0.6"` here instead!
cxx-qt-lib.workspace = true
2 changes: 1 addition & 1 deletion examples/cargo_without_cmake/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
qml_files: &["qml/main.qml"],
..Default::default()
})
.with_opts(cxx_qt_lib_headers::build_opts())
.with_opts(cxx_qt_lib::build_opts())
.build();
}
// ANCHOR_END: book_cargo_executable_build_rs
2 changes: 1 addition & 1 deletion examples/demo_threading/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ uuid = { version = "1.2", features = ["serde", "v4"] }

[build-dependencies]
cxx-qt-build.workspace = true
cxx-qt-lib-headers.workspace = true
cxx-qt-lib.workspace = true

[features]
link_qt_object_files = [ "cxx-qt-build/link_qt_object_files" ]
2 changes: 1 addition & 1 deletion examples/demo_threading/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ fn main() {
],
..Default::default()
})
.with_opts(cxx_qt_lib_headers::build_opts())
.with_opts(cxx_qt_lib::build_opts())
.build();
}
2 changes: 1 addition & 1 deletion examples/qml_features/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ serde_json.workspace = true

[build-dependencies]
cxx-qt-build.workspace = true
cxx-qt-lib-headers.workspace = true
cxx-qt-lib.workspace = true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this causes Windows builds to fail with a missing dll 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(note it works when using cxx-qt-lib-headers, so is something specific to the build.rs and note it happened when using cxx_build instead of cxx-qt-build too)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in #843 the same build failure occurred in qml-features, the issue turned out to be having a extern "Rust" type in the bridges, removing that from the cxx-qt crate resolved the build failure.


[features]
link_qt_object_files = [ "cxx-qt-build/link_qt_object_files" ]
Loading
Loading