Skip to content

Commit

Permalink
WIP: cxx-qt-gen: override default trycatch when we do not have except…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
ahayzen-kdab committed Nov 15, 2024
1 parent cc21463 commit ed0c926
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/cxx-qt-gen/src/writer/cpp/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ pub fn write_cpp_header(generated: &GeneratedCppBlocks, include_path: &str) -> S
formatdoc! {r#"
#pragma once
#include <cxx-qt/trycatch.h>
{includes}
{forward_declare}
Expand Down Expand Up @@ -255,6 +256,7 @@ mod tests {
let expected = indoc! {r#"
#pragma once
#include <cxx-qt/trycatch.h>
#include <cxx-qt/type.h>
class MyObject;
Expand Down
3 changes: 3 additions & 0 deletions crates/cxx-qt-gen/src/writer/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ mod tests {
indoc! {r#"
#pragma once
#include <cxx-qt/trycatch.h>
#include <test>
namespace cxx_qt::my_object {
Expand Down Expand Up @@ -390,6 +391,7 @@ mod tests {
indoc! {r#"
#pragma once
#include <cxx-qt/trycatch.h>
#include <test>
namespace cxx_qt {
Expand Down Expand Up @@ -469,6 +471,7 @@ mod tests {
indoc! {r#"
#pragma once
#include <cxx-qt/trycatch.h>
#include <test>
class MyObject;
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/test_outputs/inheritance.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cxx-qt/trycatch.h>
#include <cxx-qt/type.h>

class MyObject;
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/test_outputs/invokables.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cxx-qt/threading.h>
#include <cxx-qt/trycatch.h>
#include <cxx-qt/type.h>

namespace cxx_qt::my_object {
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cxx-qt/signalhandler.h>
#include <cxx-qt/trycatch.h>
#include <cxx-qt/type.h>

namespace cxx_qt::multi_object {
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/test_outputs/properties.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cxx-qt/signalhandler.h>
#include <cxx-qt/trycatch.h>
#include <cxx-qt/type.h>

namespace cxx_qt::my_object {
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/test_outputs/qenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QtCore/QObject>
#include <QtQml/QQmlEngine>
#include <cstdint>
#include <cxx-qt/trycatch.h>
#include <cxx-qt/type.h>

namespace cxx_qt::my_object {
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-gen/test_outputs/signals.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cxx-qt/signalhandler.h>
#include <cxx-qt/trycatch.h>
#include <cxx-qt/type.h>

namespace cxx_qt::my_object {
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn write_headers() {
"signalhandler.h",
"thread.h",
"threading.h",
"trycatch.h",
"type.h",
] {
println!("cargo::rerun-if-changed=include/{file_path}");
Expand Down
24 changes: 24 additions & 0 deletions crates/cxx-qt/include/trycatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// clang-format off
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// clang-format on
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

// When building with no exceptions ensure we do not have a try catch
// error: cannot use 'try' with exceptions disabled
// So override the default trycatch from CXX
#if defined(RUST_CXX_NO_EXCEPTIONS)
namespace rust {
namespace behavior {

template<typename Try, typename Fail>
static void
trycatch(Try&& func, Fail&& fail) noexcept
{
func();
}

} // namespace behavior
} // namespace rust
#endif
1 change: 1 addition & 0 deletions crates/cxx-qt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ pub fn write_headers(directory: impl AsRef<Path>) {
),
(include_str!("../include/thread.h"), "thread.h"),
(include_str!("../include/threading.h"), "threading.h"),
(include_str!("../include/trycatch.h"), "trycatch.h"),
(include_str!("../include/type.h"), "type.h"),
] {
// Note that we do not need rerun-if-changed for these files
Expand Down

0 comments on commit ed0c926

Please sign in to comment.