Use cfg_aliases crate to make Wayland/X #[cfg(..)] less redundant
This commit is contained in:
parent
4f6542ceaa
commit
a90c7bca04
3 changed files with 19 additions and 54 deletions
|
|
@ -23,7 +23,7 @@ thiserror = "1.0.30"
|
|||
raw-window-handle = "0.5.0"
|
||||
log = "0.4.17"
|
||||
|
||||
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
|
||||
[target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox"))))'.dependencies]
|
||||
nix = { version = "0.26.1", optional = true }
|
||||
wayland-backend = { version = "0.1.0", features = ["client_system"], optional = true }
|
||||
wayland-client = { version = "0.30.0", optional = true }
|
||||
|
|
@ -32,7 +32,7 @@ bytemuck = { version = "1.12.3", optional = true }
|
|||
x11-dl = { version = "2.19.1", optional = true }
|
||||
x11rb = { version = "0.11.0", features = ["allow-unsafe-code", "dl-libxcb"], optional = true }
|
||||
|
||||
[target.'cfg(any(target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
|
||||
[target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox", target_os = "linux", target_os = "freebsd"))))'.dependencies]
|
||||
fastrand = { version = "1.8.0", optional = true }
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
|
||||
|
|
@ -55,6 +55,9 @@ features = ["CanvasRenderingContext2d", "Document", "Element", "HtmlCanvasElemen
|
|||
[target.'cfg(target_os = "redox")'.dependencies]
|
||||
redox_syscall = "0.3"
|
||||
|
||||
[build-dependencies]
|
||||
cfg_aliases = "0.1.1"
|
||||
|
||||
[dev-dependencies]
|
||||
instant = "0.1.12"
|
||||
winit = "0.27.2"
|
||||
|
|
|
|||
7
build.rs
Normal file
7
build.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fn main() {
|
||||
cfg_aliases::cfg_aliases! {
|
||||
free_unix: { all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox"))) },
|
||||
x11_platform: { all(feature = "x11", free_unix, not(target_arch = "wasm32")) },
|
||||
wayland_platform: { all(feature = "wayland", free_unix, not(target_arch = "wasm32")) },
|
||||
}
|
||||
}
|
||||
59
src/lib.rs
59
src/lib.rs
|
|
@ -10,31 +10,13 @@ extern crate core;
|
|||
mod cg;
|
||||
#[cfg(target_os = "redox")]
|
||||
mod orbital;
|
||||
#[cfg(all(
|
||||
feature = "wayland",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)
|
||||
))]
|
||||
#[cfg(wayland_platform)]
|
||||
mod wayland;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod web;
|
||||
#[cfg(target_os = "windows")]
|
||||
mod win32;
|
||||
#[cfg(all(
|
||||
feature = "x11",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)
|
||||
))]
|
||||
#[cfg(x11_platform)]
|
||||
mod x11;
|
||||
|
||||
mod error;
|
||||
|
|
@ -84,9 +66,9 @@ macro_rules! make_dispatch {
|
|||
}
|
||||
|
||||
make_dispatch! {
|
||||
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd")))]
|
||||
#[cfg(x11_platform)]
|
||||
X11(x11::X11Impl),
|
||||
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd")))]
|
||||
#[cfg(wayland_platform)]
|
||||
Wayland(wayland::WaylandImpl),
|
||||
#[cfg(target_os = "windows")]
|
||||
Win32(win32::Win32Impl),
|
||||
|
|
@ -123,48 +105,21 @@ impl GraphicsContext {
|
|||
raw_display_handle: RawDisplayHandle,
|
||||
) -> Result<Self, SoftBufferError> {
|
||||
let imple: Dispatch = match (raw_window_handle, raw_display_handle) {
|
||||
#[cfg(all(
|
||||
feature = "x11",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)
|
||||
))]
|
||||
#[cfg(x11_platform)]
|
||||
(
|
||||
RawWindowHandle::Xlib(xlib_window_handle),
|
||||
RawDisplayHandle::Xlib(xlib_display_handle),
|
||||
) => Dispatch::X11(unsafe {
|
||||
x11::X11Impl::from_xlib(xlib_window_handle, xlib_display_handle)?
|
||||
}),
|
||||
#[cfg(all(
|
||||
feature = "x11",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)
|
||||
))]
|
||||
#[cfg(x11_platform)]
|
||||
(
|
||||
RawWindowHandle::Xcb(xcb_window_handle),
|
||||
RawDisplayHandle::Xcb(xcb_display_handle),
|
||||
) => Dispatch::X11(unsafe {
|
||||
x11::X11Impl::from_xcb(xcb_window_handle, xcb_display_handle)?
|
||||
}),
|
||||
#[cfg(all(
|
||||
feature = "wayland",
|
||||
any(
|
||||
target_os = "linux",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)
|
||||
))]
|
||||
#[cfg(wayland_platform)]
|
||||
(
|
||||
RawWindowHandle::Wayland(wayland_window_handle),
|
||||
RawDisplayHandle::Wayland(wayland_display_handle),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue