Skip to content

Commit

Permalink
Disabled QDateTime and QTimeZone for unsupported target emscripten.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyvanhest authored and ahayzen-kdab committed Jul 3, 2023
1 parent b5e05c2 commit b1f7da5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
27 changes: 19 additions & 8 deletions crates/cxx-qt-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
fn main() {
let feature_qt_gui_enabled = std::env::var("CARGO_FEATURE_QT_GUI").is_ok();
let feature_qt_qml_enabled = std::env::var("CARGO_FEATURE_QT_QML").is_ok();
let emscripten_targeted = match std::env::var("CARGO_CFG_TARGET_OS") {
Ok(val) => val == "emscripten",
Err(_) => false,
};

let mut qt_modules = vec!["Core".to_owned()];
if feature_qt_gui_enabled {
Expand All @@ -31,7 +35,6 @@ fn main() {
"core/qbytearray",
"core/qcoreapplication",
"core/qdate",
"core/qdatetime",
"core/qhash/qhash_i32_qbytearray",
"core/qhash/qhash_qstring_qvariant",
"core/qlist/qlist_bool",
Expand All @@ -43,7 +46,6 @@ fn main() {
"core/qlist/qlist_i64",
"core/qlist/qlist_qbytearray",
"core/qlist/qlist_qdate",
"core/qlist/qlist_qdatetime",
"core/qlist/qlist_qmargins",
"core/qlist/qlist_qmarginsf",
"core/qlist/qlist_qpersistentmodelindex",
Expand Down Expand Up @@ -80,7 +82,6 @@ fn main() {
"core/qset/qset_i64",
"core/qset/qset_qbytearray",
"core/qset/qset_qdate",
"core/qset/qset_qdatetime",
"core/qset/qset_qpersistentmodelindex",
"core/qset/qset_qstring",
"core/qset/qset_qtime",
Expand All @@ -95,7 +96,6 @@ fn main() {
"core/qstringlist",
"core/qt",
"core/qtime",
"core/qtimezone",
"core/qurl",
"core/qvariant/mod",
"core/qvariant/qvariant_bool",
Expand All @@ -107,7 +107,6 @@ fn main() {
"core/qvariant/qvariant_i64",
"core/qvariant/qvariant_qbytearray",
"core/qvariant/qvariant_qdate",
"core/qvariant/qvariant_qdatetime",
"core/qvariant/qvariant_qmodelindex",
"core/qvariant/qvariant_qpersistentmodelindex",
"core/qvariant/qvariant_qpoint",
Expand All @@ -133,7 +132,6 @@ fn main() {
"core/qvector/qvector_i64",
"core/qvector/qvector_qbytearray",
"core/qvector/qvector_qdate",
"core/qvector/qvector_qdatetime",
"core/qvector/qvector_qmargins",
"core/qvector/qvector_qmarginsf",
"core/qvector/qvector_qpersistentmodelindex",
Expand Down Expand Up @@ -170,6 +168,17 @@ fn main() {
rust_bridges.extend(["qml/qqmlapplicationengine", "qml/qqmlengine"]);
}

if !emscripten_targeted {
rust_bridges.extend([
"core/qdatetime",
"core/qtimezone",
"core/qlist/qlist_qdatetime",
"core/qset/qset_qdatetime",
"core/qvariant/qvariant_qdatetime",
"core/qvector/qvector_qdatetime",
]);
}

for bridge in &rust_bridges {
println!("cargo:rerun-if-changed=src/{bridge}.rs");
}
Expand All @@ -187,7 +196,6 @@ fn main() {
"core/qbytearray",
"core/qcoreapplication",
"core/qdate",
"core/qdatetime",
"core/qhash/qhash",
"core/qlist/qlist",
"core/qmap/qmap",
Expand All @@ -206,7 +214,6 @@ fn main() {
"core/qstring",
"core/qstringlist",
"core/qtime",
"core/qtimezone",
"core/qurl",
"core/qvariant/qvariant",
"core/qvector/qvector",
Expand All @@ -226,6 +233,10 @@ fn main() {
cpp_files.extend(["qml/qqmlapplicationengine", "qml/qqmlengine"]);
}

if !emscripten_targeted {
cpp_files.extend(["core/qdatetime", "core/qtimezone"]);
}

for cpp_file in &cpp_files {
builder.file(format!("src/{cpp_file}.cpp"));
println!("cargo:rerun-if-changed=src/{cpp_file}.cpp");
Expand Down
4 changes: 4 additions & 0 deletions crates/cxx-qt-lib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pub use qcoreapplication::QCoreApplication;
mod qdate;
pub use qdate::QDate;

#[cfg(not(target_os = "emscripten"))]
mod qdatetime;
#[cfg(not(target_os = "emscripten"))]
pub use qdatetime::QDateTime;

mod qhash;
Expand Down Expand Up @@ -68,7 +70,9 @@ pub use qt::{
mod qtime;
pub use qtime::QTime;

#[cfg(not(target_os = "emscripten"))]
mod qtimezone;
#[cfg(not(target_os = "emscripten"))]
pub use qtimezone::QTimeZone;

mod qpoint;
Expand Down
7 changes: 5 additions & 2 deletions crates/cxx-qt-lib/src/core/qlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

#[cfg(feature = "qt_gui")]
use crate::QColor;
#[cfg(not(target_os = "emscripten"))]
use crate::QDateTime;
use crate::{
QByteArray, QDate, QDateTime, QMargins, QMarginsF, QPersistentModelIndex, QPoint, QPointF,
QRect, QRectF, QSize, QSizeF, QString, QTime, QUrl, QVariant,
QByteArray, QDate, QMargins, QMarginsF, QPersistentModelIndex, QPoint, QPointF, QRect, QRectF,
QSize, QSizeF, QString, QTime, QUrl, QVariant,
};
use core::{marker::PhantomData, mem::MaybeUninit};
use cxx::{type_id, ExternType};
Expand Down Expand Up @@ -351,6 +353,7 @@ impl_qlist_element!(QByteArray, qlist_qbytearray, "QList_QByteArray");
#[cfg(feature = "qt_gui")]
impl_qlist_element!(QColor, qlist_qcolor, "QList_QColor");
impl_qlist_element!(QDate, qlist_qdate, "QList_QDate");
#[cfg(not(target_os = "emscripten"))]
impl_qlist_element!(QDateTime, qlist_qdatetime, "QList_QDateTime");
impl_qlist_element!(QMargins, qlist_qmargins, "QList_QMargins");
impl_qlist_element!(QMarginsF, qlist_qmarginsf, "QList_QMarginsF");
Expand Down
5 changes: 4 additions & 1 deletion crates/cxx-qt-lib/src/core/qset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::{QByteArray, QDate, QDateTime, QPersistentModelIndex, QString, QTime, QUrl};
#[cfg(not(target_os = "emscripten"))]
use crate::QDateTime;
use crate::{QByteArray, QDate, QPersistentModelIndex, QString, QTime, QUrl};
use core::{marker::PhantomData, mem::MaybeUninit};
use cxx::{type_id, ExternType};

Expand Down Expand Up @@ -250,6 +252,7 @@ impl_qset_element!(i32, qset_i32, "QSet_i32");
impl_qset_element!(i64, qset_i64, "QSet_i64");
impl_qset_element!(QByteArray, qset_qbytearray, "QSet_QByteArray");
impl_qset_element!(QDate, qset_qdate, "QSet_QDate");
#[cfg(not(target_os = "emscripten"))]
impl_qset_element!(QDateTime, qset_qdatetime, "QSet_QDateTime");
impl_qset_element!(
QPersistentModelIndex,
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-lib/src/core/qvariant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl_qvariant_value!(crate::QByteArray, qvariant_qbytearray);
#[cfg(feature = "qt_gui")]
impl_qvariant_value!(crate::QColor, qvariant_qcolor);
impl_qvariant_value!(crate::QDate, qvariant_qdate);
#[cfg(not(target_os = "emscripten"))]
impl_qvariant_value!(crate::QDateTime, qvariant_qdatetime);
impl_qvariant_value!(crate::QModelIndex, qvariant_qmodelindex);
impl_qvariant_value!(crate::QPersistentModelIndex, qvariant_qpersistentmodelindex);
Expand Down
7 changes: 5 additions & 2 deletions crates/cxx-qt-lib/src/core/qvector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

#[cfg(feature = "qt_gui")]
use crate::QColor;
#[cfg(not(target_os = "emscripten"))]
use crate::QDateTime;
use crate::{
QByteArray, QDate, QDateTime, QMargins, QMarginsF, QPersistentModelIndex, QPoint, QPointF,
QRect, QRectF, QSize, QSizeF, QString, QTime, QUrl, QVariant,
QByteArray, QDate, QMargins, QMarginsF, QPersistentModelIndex, QPoint, QPointF, QRect, QRectF,
QSize, QSizeF, QString, QTime, QUrl, QVariant,
};
use core::{marker::PhantomData, mem::MaybeUninit};
use cxx::{type_id, ExternType};
Expand Down Expand Up @@ -351,6 +353,7 @@ impl_qvector_element!(QByteArray, qvector_qbytearray, "QVector_QByteArray");
#[cfg(feature = "qt_gui")]
impl_qvector_element!(QColor, qvector_qcolor, "QVector_QColor");
impl_qvector_element!(QDate, qvector_qdate, "QVector_QDate");
#[cfg(not(target_os = "emscripten"))]
impl_qvector_element!(QDateTime, qvector_qdatetime, "QVector_QDateTime");
impl_qvector_element!(QMargins, qvector_qmargins, "QVector_QMargins");
impl_qvector_element!(QMarginsF, qvector_qmarginsf, "QVector_QMarginsF");
Expand Down

0 comments on commit b1f7da5

Please sign in to comment.