Skip to content

Commit ae4ba67

Browse files
committed
cxx-qt-build: add ability to specify depends for QML module
1 parent 70675dd commit ae4ba67

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ impl CxxQtBuilder {
887887
&module_name_from_uri(&qml_module.uri),
888888
&qml_module.qml_files,
889889
&qml_module.qrc_files,
890+
&qml_module.depends,
890891
);
891892
if let Some(qmltyperegistrar) = qml_module_registration_files.qmltyperegistrar {
892893
cc_builder.file(qmltyperegistrar);

crates/cxx-qt-build/src/qml_modules.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ where
3131
// and an empty slice is likely desired in most cases; most users probably don't
3232
// care about this field.
3333
pub qrc_files: &'a [A],
34+
/// Dependencies of the QML module
35+
pub depends: &'a [&'a str],
3436
}
3537

3638
impl<A, B> Default for QmlModule<'_, A, B>
@@ -45,6 +47,7 @@ where
4547
version_minor: 0,
4648
qml_files: &[],
4749
qrc_files: &[],
50+
depends: &[],
4851
}
4952
}
5053
}
@@ -58,6 +61,7 @@ pub(crate) struct OwningQmlModule {
5861
pub version_minor: usize,
5962
pub qml_files: Vec<PathBuf>,
6063
pub qrc_files: Vec<PathBuf>,
64+
pub depends: Vec<String>,
6165
}
6266

6367
fn collect_pathbuf_vec(asref: &[impl AsRef<Path>]) -> Vec<PathBuf> {
@@ -72,6 +76,11 @@ impl<A: AsRef<Path>, B: AsRef<Path>> From<QmlModule<'_, A, B>> for OwningQmlModu
7276
version_minor: other.version_minor,
7377
qml_files: collect_pathbuf_vec(other.qml_files),
7478
qrc_files: collect_pathbuf_vec(other.qrc_files),
79+
depends: other
80+
.depends
81+
.into_iter()
82+
.map(|depend| depend.to_string())
83+
.collect(),
7584
}
7685
}
7786
}

crates/qt-build-utils/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ impl QtBuild {
160160
plugin_name: &str,
161161
qml_files: &[impl AsRef<Path>],
162162
qrc_files: &[impl AsRef<Path>],
163+
depends: impl IntoIterator<Item = impl Into<String>>,
163164
) -> QmlModuleRegistrationFiles {
164165
let qml_uri = QmlUri::new(uri.split('.'));
165166
let qml_uri_dirs = qml_uri.as_dirs();
@@ -181,6 +182,7 @@ impl QtBuild {
181182
{
182183
let mut file = File::create(&qmldir_file_path).expect("Could not create qmldir file");
183184
QmlDirBuilder::new(qml_uri.clone())
185+
.depends(depends)
184186
.plugin(plugin_name, true)
185187
.class_name(&plugin_class_name)
186188
.type_info(plugin_type_info)

examples/qml_features/qml/pages/MultipleQObjectsPage.qml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ Page {
5555
}
5656

5757
Label {
58-
// TODO: QColor needs a dependency in qmldir on QtQuick
5958
color: root.first.color
6059
Layout.fillWidth: true
6160
horizontalAlignment: Text.AlignHCenter

examples/qml_features/rust/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ fn main() {
2828
"../qml/pages/ThreadingPage.qml",
2929
"../qml/pages/TypesPage.qml",
3030
],
31+
// Need to depend on QtQuick for QColor to work with qmllint/qmlls
32+
depends: &["QtQuick"],
3133
..Default::default()
3234
})
3335
.files([

0 commit comments

Comments
 (0)