Skip to content

Commit

Permalink
fix build failure with empty qml bridges (closes #1033)
Browse files Browse the repository at this point in the history
  • Loading branch information
aambrosano authored and ahayzen-kdab committed Sep 13, 2024
1 parent 64d84f3 commit 7be811b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
24 changes: 18 additions & 6 deletions crates/qt-build-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,23 @@ prefer :/qt/qml/{qml_uri_dirs}/
// Run qmltyperegistrar
let qmltyperegistrar_output_path =
qml_plugin_dir.join(format!("{qml_uri_underscores}_qmltyperegistration.cpp"));
{

// Filter out empty jsons
let metatypes_json: Vec<_> = metatypes_json
.iter()
.filter(|f| {
std::fs::metadata(f)
.unwrap_or_else(|_| {
panic!("couldn't open json file {}", f.as_ref().to_string_lossy())
})
.len()
> 0
})
.map(|f| f.as_ref().to_string_lossy().to_string())
.collect();

// Only run qmltyperegistrar if we have valid json files left out
if !metatypes_json.is_empty() {
let mut args = vec![
"--generate-qmltypes".to_string(),
qmltypes_path.to_string_lossy().to_string(),
Expand All @@ -862,11 +878,7 @@ prefer :/qt/qml/{qml_uri_dirs}/
"-o".to_string(),
qmltyperegistrar_output_path.to_string_lossy().to_string(),
];
args.extend(
metatypes_json
.iter()
.map(|f| f.as_ref().to_string_lossy().to_string()),
);
args.extend(metatypes_json);
let cmd = Command::new(self.qmltyperegistrar_executable.as_ref().unwrap())
.args(args)
.output()
Expand Down
1 change: 1 addition & 0 deletions examples/qml_features/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn main() {
"src/containers.rs",
"src/custom_base_class.rs",
"src/custom_parent_class.rs",
"src/empty_bridge.rs",
"src/externcxxqt.rs",
"src/invokables.rs",
"src/multiple_qobjects.rs",
Expand Down
11 changes: 11 additions & 0 deletions examples/qml_features/rust/src/empty_bridge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
// SPDX-FileContributor: Alessandro Ambrosano <alessandro.ambrosano@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

//! This example implements an empty bridge, and it's used as a corner case to test
//! the build procedure
/// An empty CXX-Qt bridge
#[cxx_qt::bridge]
pub mod qobject {
}

0 comments on commit 7be811b

Please sign in to comment.