Skip to content

Commit abfb2ac

Browse files
authored
Merge pull request #18 from rust-windowing/x11-wayland-features
Add feature flags for `x11` and `wayland`
2 parents 80b45a9 + c73bd4b commit abfb2ac

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Cargo.toml

+9-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ keywords = ["framebuffer", "windowing"]
1111
categories = ["game-development", "graphics", "gui", "multimedia", "rendering"]
1212
exclude = ["examples"]
1313

14+
[features]
15+
default = ["x11", "wayland"]
16+
wayland = ["wayland-backend", "wayland-client", "nix"]
17+
x11 = ["x11-dl"]
18+
1419
[dependencies]
1520
thiserror = "1.0.30"
1621
raw-window-handle = "0.5.0"
1722

1823
[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies]
19-
nix = "0.26.1"
20-
wayland-backend = {version = "0.1.0-beta.14", features = ["client_system"]}
21-
wayland-client = {version = "0.30.0-beta.14"}
22-
x11-dl = "2.19.1"
24+
nix = { version = "0.26.1", optional = true }
25+
wayland-backend = { version = "0.1.0-beta.14", features = ["client_system"], optional = true }
26+
wayland-client = { version = "0.30.0-beta.14", optional = true }
27+
x11-dl = { version = "2.19.1", optional = true }
2328

2429
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
2530
version = "0.42.0"

src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ extern crate core;
99
mod win32;
1010
#[cfg(target_os = "macos")]
1111
mod cg;
12-
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
12+
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
1313
mod x11;
14-
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
14+
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "freebsd")))]
1515
mod wayland;
1616
#[cfg(target_arch = "wasm32")]
1717
mod web;
@@ -49,9 +49,9 @@ impl GraphicsContext {
4949
/// lifetime of the GraphicsContext
5050
pub unsafe fn from_raw(raw_window_handle: RawWindowHandle, raw_display_handle: RawDisplayHandle) -> Result<Self, SwBufError> {
5151
let imple: Box<dyn GraphicsContextImpl> = match (raw_window_handle, raw_display_handle) {
52-
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
52+
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
5353
(RawWindowHandle::Xlib(xlib_window_handle), RawDisplayHandle::Xlib(xlib_display_handle)) => Box::new(x11::X11Impl::new(xlib_window_handle, xlib_display_handle)?),
54-
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
54+
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "freebsd")))]
5555
(RawWindowHandle::Wayland(wayland_window_handle), RawDisplayHandle::Wayland(wayland_display_handle)) => Box::new(wayland::WaylandImpl::new(wayland_window_handle, wayland_display_handle)?),
5656
#[cfg(target_os = "windows")]
5757
(RawWindowHandle::Win32(win32_handle), _) => Box::new(win32::Win32Impl::new(&win32_handle)?),

0 commit comments

Comments
 (0)