From 8f6be7984af03bc5457966b416d7a240b2c31d4e Mon Sep 17 00:00:00 2001 From: leyoda Date: Fri, 24 Apr 2026 06:24:15 +0200 Subject: [PATCH] yoda: gate iced_wgpu x11 backend behind an opt-in feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit iced_wgpu's unix block unconditionally depended on as-raw-xcb-connection, tiny-xlib and x11rb for a DRI3 device-id fallback in window/compositor.rs that only fires when wayland can't determine the GPU. On a Wayland-only build this code path never runs, so the deps are pure bloat. Changes: - Cargo.toml: move the 3 x11 crates to optional + new feature `x11` (not in default — wayland-only is the yoda target; users who need X11 opt in). - window.rs: cfg-gate `mod x11;` on feature = "x11" - window/compositor.rs: cfg-gate `use super::x11::get_x11_device_ids` + the or_else fallback on feature = "x11" (wrapped in a let-binding so the non-x11 branch compiles cleanly). Result: iced_wgpu no longer pulls any x11 crate when built without the feature. --- wgpu/Cargo.toml | 11 ++++++++--- wgpu/src/window.rs | 2 +- wgpu/src/window/compositor.rs | 8 +++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 48fca1b8..ffbcd293 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -25,6 +25,11 @@ svg = ["iced_graphics/svg", "resvg/text"] web-colors = ["iced_graphics/web-colors"] webgl = ["wgpu/webgl"] strict-assertions = [] +# Yoda: opt-in X11 backend. Pulls tiny-xlib/as-raw-xcb-connection/x11rb +# (which otherwise were unconditional direct deps on unix). Wayland-only +# builds just leave this off — window/x11.rs and the DRI3 device-id +# fallback in window/compositor.rs are cfg-gated on it. +x11 = ["dep:as-raw-xcb-connection", "dep:tiny-xlib", "dep:x11rb"] [dependencies] iced_debug.workspace = true @@ -57,9 +62,9 @@ wayland-protocols.workspace = true wayland-backend = { version = "0.3.3", features = ["client_system"] } wayland-client = { version = "0.31.2" } wayland-sys = { version = "0.31.1", features = ["dlopen"] } -as-raw-xcb-connection = "1.0.1" -tiny-xlib = "0.2.3" -x11rb = { version = "0.13.1", features = [ +as-raw-xcb-connection = { version = "1.0.1", optional = true } +tiny-xlib = { version = "0.2.3", optional = true } +x11rb = { version = "0.13.1", optional = true, features = [ "allow-unsafe-code", "dl-libxcb", "dri3", diff --git a/wgpu/src/window.rs b/wgpu/src/window.rs index b9ec54bd..f71b7d3f 100644 --- a/wgpu/src/window.rs +++ b/wgpu/src/window.rs @@ -7,7 +7,7 @@ pub mod compositor; not(target_os = "redox") ))] mod wayland; -#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] +#[cfg(all(unix, feature = "x11", not(target_os = "macos"), not(target_os = "redox")))] mod x11; pub use compositor::Compositor; diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 833a642e..15a13905 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -16,7 +16,7 @@ use crate::{Engine, Renderer}; not(target_os = "redox") ))] use super::wayland::get_wayland_device_ids; -#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] +#[cfg(all(unix, feature = "x11", not(target_os = "macos"), not(target_os = "redox")))] use super::x11::get_x11_device_ids; use std::future::Future; @@ -72,8 +72,10 @@ impl Compositor { not(target_os = "redox") ))] let ids = compatible_window.as_ref().and_then(|window| { - get_wayland_device_ids(window) - .or_else(|| get_x11_device_ids(window)) + let w = get_wayland_device_ids(window); + #[cfg(feature = "x11")] + let w = w.or_else(|| get_x11_device_ids(window)); + w }); // HACK: