From 2135f28868a68d40f4245bd5188f9f9465e03ab7 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 19 Nov 2021 14:11:30 +0100 Subject: [PATCH] qttype: fix build when qt is not found --- CHANGELOG.md | 4 +++ qttypes/Cargo.toml | 2 +- qttypes/src/core/qbytearray.rs | 7 ++-- qttypes/src/core/qstring.rs | 4 +-- qttypes/src/core/qurl.rs | 6 ++-- qttypes/src/gui/qcolor.rs | 6 ++-- qttypes/src/lib.rs | 59 +++++++++++++++++++--------------- 7 files changed, 45 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f7bfbf5..32a3c024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## 0.2.6 2021-11-19 (qttype only) + + - Fix build when Qt is not found and the required feature is off + ## 0.2.5 2021-11-19 - Completed QColor API diff --git a/qttypes/Cargo.toml b/qttypes/Cargo.toml index 75af5736..b58ad71a 100644 --- a/qttypes/Cargo.toml +++ b/qttypes/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "qttypes" -version = "0.2.5" +version = "0.2.6" edition = "2018" authors = ["Olivier Goffart "] build = "build.rs" diff --git a/qttypes/src/core/qbytearray.rs b/qttypes/src/core/qbytearray.rs index b390eeb4..64d930de 100644 --- a/qttypes/src/core/qbytearray.rs +++ b/qttypes/src/core/qbytearray.rs @@ -1,12 +1,9 @@ -#[cfg(not(no_qt))] -use cpp::{cpp, cpp_class}; - +use crate::internal_prelude::*; +use crate::QString; use std::fmt::Display; use std::os::raw::c_char; use std::str::Utf8Error; -use crate::core::QString; - cpp! {{ #include #include diff --git a/qttypes/src/core/qstring.rs b/qttypes/src/core/qstring.rs index f9c3c2e4..ff7a822b 100644 --- a/qttypes/src/core/qstring.rs +++ b/qttypes/src/core/qstring.rs @@ -1,8 +1,6 @@ -#[cfg(not(no_qt))] -use cpp::{cpp, cpp_class}; - use crate::core::QByteArray; use crate::core::QUrl; +use crate::internal_prelude::*; use std::fmt::Display; diff --git a/qttypes/src/core/qurl.rs b/qttypes/src/core/qurl.rs index 0833c3e2..b667e95b 100644 --- a/qttypes/src/core/qurl.rs +++ b/qttypes/src/core/qurl.rs @@ -1,7 +1,5 @@ -#[cfg(not(no_qt))] -use cpp::{cpp, cpp_class}; - -use crate::core::QString; +use crate::internal_prelude::*; +use crate::QString; cpp! {{ #include diff --git a/qttypes/src/gui/qcolor.rs b/qttypes/src/gui/qcolor.rs index 443abb52..ccb87a51 100644 --- a/qttypes/src/gui/qcolor.rs +++ b/qttypes/src/gui/qcolor.rs @@ -1,7 +1,5 @@ -pub use crate::core::{qreal, QString}; - -#[cfg(not(no_qt))] -use cpp::{cpp, cpp_class}; +use crate::internal_prelude::*; +use crate::{qreal, QString}; cpp! {{ #include diff --git a/qttypes/src/lib.rs b/qttypes/src/lib.rs index 2b832a5d..fcae3906 100644 --- a/qttypes/src/lib.rs +++ b/qttypes/src/lib.rs @@ -128,40 +128,47 @@ use std::ops::{Index, IndexMut}; #[cfg(feature = "chrono")] use chrono::prelude::*; -#[cfg(not(no_qt))] -use cpp::{cpp, cpp_class}; - -mod core; -pub use crate::core::{qreal, QByteArray, QString, QUrl}; - -mod gui; -pub use crate::gui::{QColor, QColorNameFormat, QColorSpec, QRgb, QRgba64}; #[cfg(no_qt)] -mod no_qt { +pub(crate) mod no_qt { pub fn panic() -> T { panic!("Qt was not found during build") } } -#[cfg(no_qt)] -macro_rules! cpp { - {{ $($t:tt)* }} => {}; - {$(unsafe)? [$($a:tt)*] -> $ret:ty as $b:tt { $($t:tt)* } } => { - crate::no_qt::panic::<$ret>() - }; - { $($t:tt)* } => { - crate::no_qt::panic::<()>() - }; -} +pub(crate) mod internal_prelude { + #[cfg(not(no_qt))] + pub(crate) use cpp::{cpp, cpp_class}; + #[cfg(no_qt)] + macro_rules! cpp { + {{ $($t:tt)* }} => {}; + {$(unsafe)? [$($a:tt)*] -> $ret:ty as $b:tt { $($t:tt)* } } => { + crate::no_qt::panic::<$ret>() + }; + { $($t:tt)* } => { + crate::no_qt::panic::<()>() + }; + } -#[cfg(no_qt)] -macro_rules! cpp_class { - ($(#[$($attrs:tt)*])* $vis:vis unsafe struct $name:ident as $type:expr) => { - #[derive(Default, Ord, Eq, PartialEq, PartialOrd, Clone, Copy)] - #[repr(C)] - $vis struct $name; - }; + #[cfg(no_qt)] + macro_rules! cpp_class { + ($(#[$($attrs:tt)*])* $vis:vis unsafe struct $name:ident as $type:expr) => { + #[derive(Default, Ord, Eq, PartialEq, PartialOrd, Clone, Copy)] + #[repr(C)] + $vis struct $name; + }; + } + #[cfg(no_qt)] + pub(crate) use cpp; + #[cfg(no_qt)] + pub(crate) use cpp_class; } +use internal_prelude::*; + +mod core; +pub use crate::core::{qreal, QByteArray, QString, QUrl}; + +mod gui; +pub use crate::gui::{QColor, QColorNameFormat, QColorSpec, QRgb, QRgba64}; cpp! {{ #include