From 0fe170f015f3b7a6918e337760d3b6171852c9ad Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Mon, 18 Nov 2024 13:13:09 +0000 Subject: [PATCH] examples: cfg so we do not generate exceptions for wasm --- examples/qml_features/rust/src/invokables.rs | 18 ++++++++++++++++-- tests/basic_cxx_qt/cpp/main.cpp | 2 ++ tests/basic_cxx_qt/rust/src/lib.rs | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/examples/qml_features/rust/src/invokables.rs b/examples/qml_features/rust/src/invokables.rs index 65adb5148..e0fed64c4 100644 --- a/examples/qml_features/rust/src/invokables.rs +++ b/examples/qml_features/rust/src/invokables.rs @@ -45,7 +45,14 @@ pub mod qobject { /// Immutable invokable method that returns the QColor #[qinvokable] #[cxx_name = "loadColor"] - fn load_color(self: &RustInvokables) -> Result; + #[cfg(not(target_family = "wasm"))] + fn load_color_result(self: &RustInvokables) -> Result; + + /// Immutable invokable method that returns the QColor + #[qinvokable] + #[cxx_name = "loadColor"] + #[cfg(target_family = "wasm")] + fn load_color(self: &RustInvokables) -> QColor; /// Mutable invokable method that stores a color #[qinvokable] @@ -96,7 +103,14 @@ impl Default for RustInvokablesRust { // ANCHOR: book_invokable_impl impl qobject::RustInvokables { /// Immutable invokable method that returns the QColor - pub fn load_color(&self) -> Result { + #[cfg(target_family = "wasm")] + pub fn load_color(&self) -> QColor { + self.as_qcolor() + } + + /// Immutable invokable method that returns the QColor + #[cfg(not(target_family = "wasm"))] + pub fn load_color_result(&self) -> Result { Ok(self.as_qcolor()) } diff --git a/tests/basic_cxx_qt/cpp/main.cpp b/tests/basic_cxx_qt/cpp/main.cpp index dcf9516b7..a044c50ae 100644 --- a/tests/basic_cxx_qt/cpp/main.cpp +++ b/tests/basic_cxx_qt/cpp/main.cpp @@ -202,6 +202,7 @@ private Q_SLOTS: // Tests that we can build an empty QObject end to end void testEmpty() { Empty empty; } +#ifndef RUST_CXX_NO_EXCEPTION void testThrowException() { cxx_qt::my_object::MyObject obj; @@ -216,6 +217,7 @@ private Q_SLOTS: QCOMPARE(thrown, true); } +#endif }; QTEST_MAIN(CxxQtTest) diff --git a/tests/basic_cxx_qt/rust/src/lib.rs b/tests/basic_cxx_qt/rust/src/lib.rs index f426b49fb..f81b70e4d 100644 --- a/tests/basic_cxx_qt/rust/src/lib.rs +++ b/tests/basic_cxx_qt/rust/src/lib.rs @@ -47,6 +47,7 @@ mod qobject { #[cxx_name = "fetchUpdateCallCount"] fn fetch_update_call_count(self: &MyObject) -> i32; + #[cfg(not(target_family = "wasm"))] #[cxx_name = "throwException"] fn throw_exception(self: &MyObject) -> Result; } @@ -129,6 +130,7 @@ impl qobject::MyObject { self.update_call_count } + #[cfg(not(target_family = "wasm"))] fn throw_exception(&self) -> Result { Err("RustException".to_string()) }