Skip to content

Commit

Permalink
qttype: fix build when qt is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
ogoffart committed Nov 19, 2021
1 parent 9a32cf5 commit 2135f28
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qttypes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qttypes"
version = "0.2.5"
version = "0.2.6"
edition = "2018"
authors = ["Olivier Goffart <ogoffart@woboq.com>"]
build = "build.rs"
Expand Down
7 changes: 2 additions & 5 deletions qttypes/src/core/qbytearray.rs
Original file line number Diff line number Diff line change
@@ -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 <QtCore/QString>
#include <QtCore/QByteArray>
Expand Down
4 changes: 1 addition & 3 deletions qttypes/src/core/qstring.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 2 additions & 4 deletions qttypes/src/core/qurl.rs
Original file line number Diff line number Diff line change
@@ -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 <QtCore/QString>
Expand Down
6 changes: 2 additions & 4 deletions qttypes/src/gui/qcolor.rs
Original file line number Diff line number Diff line change
@@ -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 <QtGui/QColor>
Expand Down
59 changes: 33 additions & 26 deletions qttypes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>() -> 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 <QtCore/QByteArray>
Expand Down

0 comments on commit 2135f28

Please sign in to comment.