Skip to content

Commit 6eec0c6

Browse files
authored
Get rid of cfg_aliases (#294)
These were used in examples (which they shouldn't, that makes those harder to copy) and in two places in the implementation, which feels like too few for it to be worth it. They also can't be used in Cargo.toml, so we are forced to have at least _some_ duplication.
1 parent f68ac2f commit 6eec0c6

File tree

6 files changed

+115
-34
lines changed

6 files changed

+115
-34
lines changed

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tracing = { version = "0.1.41", default-features = false }
4848
bytemuck = "1.12.3"
4949
ndk = "0.9.0"
5050

51-
[target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox"))))'.dependencies]
51+
[target.'cfg(not(any(target_os = "android", target_vendor = "apple", target_os = "redox", target_family = "wasm", target_os = "windows")))'.dependencies]
5252
as-raw-xcb-connection = { version = "1.0.0", optional = true }
5353
bytemuck = { version = "1.12.3", optional = true }
5454
drm = { version = "0.14.1", default-features = false, optional = true }
@@ -130,9 +130,6 @@ features = [
130130
[target.'cfg(target_os = "redox")'.dependencies]
131131
redox_syscall = "0.5"
132132

133-
[build-dependencies]
134-
cfg_aliases = "0.2.0"
135-
136133
[dev-dependencies]
137134
colorous = "1.0.12"
138135
criterion = { version = "0.4.0", default-features = false, features = [
@@ -158,7 +155,7 @@ rayon = "1.5.1"
158155
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
159156
wasm-bindgen-test = "0.3"
160157

161-
[target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox"))))'.dev-dependencies]
158+
[target.'cfg(not(any(target_os = "android", target_vendor = "apple", target_os = "redox", target_family = "wasm", target_os = "windows")))'.dev-dependencies]
162159
rustix = { version = "1.0.1", features = ["event"] }
163160

164161
[workspace]

build.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/drm.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
//! Example of using softbuffer with drm-rs.
22
3-
#[cfg(kms_platform)]
3+
#[cfg(all(
4+
feature = "kms",
5+
not(any(
6+
target_os = "android",
7+
target_vendor = "apple",
8+
target_os = "redox",
9+
target_family = "wasm",
10+
target_os = "windows"
11+
))
12+
))]
413
mod imple {
514
use drm::control::{connector, Device as CtrlDevice, Event, ModeTypeFlags, PlaneType};
615
use drm::Device;
@@ -210,7 +219,16 @@ mod imple {
210219
impl CtrlDevice for Card {}
211220
}
212221

213-
#[cfg(not(kms_platform))]
222+
#[cfg(not(all(
223+
feature = "kms",
224+
not(any(
225+
target_os = "android",
226+
target_vendor = "apple",
227+
target_os = "redox",
228+
target_family = "wasm",
229+
target_os = "windows"
230+
))
231+
)))]
214232
mod imple {
215233
pub(super) fn entry() -> Result<(), Box<dyn std::error::Error>> {
216234
eprintln!("This example requires the `kms` feature.");

examples/libxcb.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
//! Example of using `softbuffer` with `libxcb`.
22
3-
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
3+
#[cfg(all(
4+
feature = "x11",
5+
not(any(
6+
target_os = "android",
7+
target_vendor = "apple",
8+
target_os = "redox",
9+
target_family = "wasm",
10+
target_os = "windows"
11+
))
12+
))]
413
mod example {
514
use raw_window_handle::{
615
DisplayHandle, RawDisplayHandle, RawWindowHandle, WindowHandle, XcbDisplayHandle,
@@ -135,12 +144,30 @@ mod example {
135144
}
136145
}
137146

138-
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
147+
#[cfg(all(
148+
feature = "x11",
149+
not(any(
150+
target_os = "android",
151+
target_vendor = "apple",
152+
target_os = "redox",
153+
target_family = "wasm",
154+
target_os = "windows"
155+
))
156+
))]
139157
fn main() {
140158
example::run();
141159
}
142160

143-
#[cfg(not(all(feature = "x11", any(target_os = "linux", target_os = "freebsd"))))]
161+
#[cfg(not(all(
162+
feature = "x11",
163+
not(any(
164+
target_os = "android",
165+
target_vendor = "apple",
166+
target_os = "redox",
167+
target_family = "wasm",
168+
target_os = "windows"
169+
))
170+
)))]
144171
fn main() {
145172
eprintln!("This example requires the `x11` feature to be enabled on a supported platform.");
146173
}

src/backend_dispatch.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use crate::{backend_interface::*, backends, InitError, Rect, SoftBufferError};
44

55
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
66
use std::num::NonZeroU32;
7-
#[cfg(any(wayland_platform, x11_platform, kms_platform))]
8-
use std::sync::Arc;
97

108
/// A macro for creating the enum used to statically dispatch to the platform-specific implementation.
119
macro_rules! make_dispatch {
@@ -201,12 +199,39 @@ make_dispatch! {
201199
<D, W> =>
202200
#[cfg(target_os = "android")]
203201
Android(D, backends::android::AndroidImpl<D, W>, backends::android::BufferImpl<'a, D, W>),
204-
#[cfg(x11_platform)]
205-
X11(Arc<backends::x11::X11DisplayImpl<D>>, backends::x11::X11Impl<D, W>, backends::x11::BufferImpl<'a, D, W>),
206-
#[cfg(wayland_platform)]
207-
Wayland(Arc<backends::wayland::WaylandDisplayImpl<D>>, backends::wayland::WaylandImpl<D, W>, backends::wayland::BufferImpl<'a, D, W>),
208-
#[cfg(kms_platform)]
209-
Kms(Arc<backends::kms::KmsDisplayImpl<D>>, backends::kms::KmsImpl<D, W>, backends::kms::BufferImpl<'a, D, W>),
202+
#[cfg(all(
203+
feature = "x11",
204+
not(any(
205+
target_os = "android",
206+
target_vendor = "apple",
207+
target_os = "redox",
208+
target_family = "wasm",
209+
target_os = "windows"
210+
))
211+
))]
212+
X11(std::sync::Arc<backends::x11::X11DisplayImpl<D>>, backends::x11::X11Impl<D, W>, backends::x11::BufferImpl<'a, D, W>),
213+
#[cfg(all(
214+
feature = "wayland",
215+
not(any(
216+
target_os = "android",
217+
target_vendor = "apple",
218+
target_os = "redox",
219+
target_family = "wasm",
220+
target_os = "windows"
221+
))
222+
))]
223+
Wayland(std::sync::Arc<backends::wayland::WaylandDisplayImpl<D>>, backends::wayland::WaylandImpl<D, W>, backends::wayland::BufferImpl<'a, D, W>),
224+
#[cfg(all(
225+
feature = "kms",
226+
not(any(
227+
target_os = "android",
228+
target_vendor = "apple",
229+
target_os = "redox",
230+
target_family = "wasm",
231+
target_os = "windows"
232+
))
233+
))]
234+
Kms(std::sync::Arc<backends::kms::KmsDisplayImpl<D>>, backends::kms::KmsImpl<D, W>, backends::kms::BufferImpl<'a, D, W>),
210235
#[cfg(target_os = "windows")]
211236
Win32(D, backends::win32::Win32Impl<D, W>, backends::win32::BufferImpl<'a, D, W>),
212237
#[cfg(target_vendor = "apple")]

src/backends/mod.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,44 @@ use raw_window_handle::HasDisplayHandle;
55
pub(crate) mod android;
66
#[cfg(target_vendor = "apple")]
77
pub(crate) mod cg;
8-
#[cfg(kms_platform)]
8+
#[cfg(all(
9+
feature = "kms",
10+
not(any(
11+
target_os = "android",
12+
target_vendor = "apple",
13+
target_os = "redox",
14+
target_family = "wasm",
15+
target_os = "windows"
16+
))
17+
))]
918
pub(crate) mod kms;
1019
#[cfg(target_os = "redox")]
1120
pub(crate) mod orbital;
12-
#[cfg(wayland_platform)]
21+
#[cfg(all(
22+
feature = "wayland",
23+
not(any(
24+
target_os = "android",
25+
target_vendor = "apple",
26+
target_os = "redox",
27+
target_family = "wasm",
28+
target_os = "windows"
29+
))
30+
))]
1331
pub(crate) mod wayland;
1432
#[cfg(target_arch = "wasm32")]
1533
pub(crate) mod web;
1634
#[cfg(target_os = "windows")]
1735
pub(crate) mod win32;
18-
#[cfg(x11_platform)]
36+
#[cfg(all(
37+
feature = "x11",
38+
not(any(
39+
target_os = "android",
40+
target_vendor = "apple",
41+
target_os = "redox",
42+
target_family = "wasm",
43+
target_os = "windows"
44+
))
45+
))]
1946
pub(crate) mod x11;
2047

2148
impl<D: HasDisplayHandle> ContextInterface<D> for D {

0 commit comments

Comments
 (0)