diff --git a/Cargo.toml b/Cargo.toml index 43fac26..380f9ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..5113eeb --- /dev/null +++ b/build.rs @@ -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")) }, + } +} diff --git a/src/lib.rs b/src/lib.rs index 9366ac9..5e42408 100644 --- a/src/lib.rs +++ b/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 { 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),