From 151dd1100b054725abc6ae1d551b61ab05c4092f Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Mon, 18 May 2026 12:25:11 +0200 Subject: [PATCH] remaining feature flags --- AGENTS.md | 2 +- build.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/config.rs | 42 ++++++++++++++++++++-------------------- 3 files changed, 75 insertions(+), 22 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 05414c4..70e660c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -28,7 +28,7 @@ Lan Mouse is an open-source Software KVM sharing mouse/keyboard input across loc ## Feature & cfg discipline -- Feature flags live in root `Cargo.toml`. Gate OS-specific modules with tight cfgs (e.g., `cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))`). +- Feature flags live in root `Cargo.toml`. Gate OS-specific modules with the configs exported in build.rs (e.g., `cfg(layer_shell)`). - Prefer module-level gating over per-function cfgs to avoid empty stubs. - New backends: add feature in `Cargo.toml`, create gated module, log backend selection. diff --git a/build.rs b/build.rs index e6f0225..d8cb70a 100644 --- a/build.rs +++ b/build.rs @@ -5,4 +5,57 @@ fn main() { .deny_const(Default::default()) .build() .expect("shadow build"); + + let unix = cfg!(unix); + let macos = cfg!(target_os = "macos"); + + let layer_shell_capture = cfg!(feature = "layer_shell_capture"); + let libei_capture = cfg!(feature = "libei_capture"); + let x11_capture = cfg!(feature = "x11_capture"); + + let libei_emulation = cfg!(feature = "libei_emulation"); + let x11_emulation = cfg!(feature = "x11_emulation"); + let wlroots_emulation = cfg!(feature = "wlroots_emulation"); + let rdp_emulation = cfg!(feature = "rdp_emulation"); + + let layer_shell_capture = unix && !macos && layer_shell_capture; + let libei_capture = unix && !macos && libei_capture; + let x11_capture = unix && !macos && x11_capture; + + let libei_emulation = unix && !macos && libei_emulation; + let rdp_emulation = unix && !macos && rdp_emulation; + let wlroots_emulation = unix && !macos && wlroots_emulation; + let x11_emulation = unix && !macos && x11_emulation; + + println!("cargo::rustc-check-cfg=cfg(layer_shell_capture)"); + println!("cargo::rustc-check-cfg=cfg(libei_capture)"); + println!("cargo::rustc-check-cfg=cfg(x11_capture)"); + + println!("cargo::rustc-check-cfg=cfg(libei_emulation)"); + println!("cargo::rustc-check-cfg=cfg(rdp_emulation)"); + println!("cargo::rustc-check-cfg=cfg(wlroots_emulation)"); + println!("cargo::rustc-check-cfg=cfg(x11_emulation)"); + + if layer_shell_capture { + println!("cargo::rustc-cfg=layer_shell_capture"); + } + if libei_capture { + println!("cargo::rustc-cfg=libei_capture"); + } + if x11_capture { + println!("cargo::rustc-cfg=x11_capture"); + } + + if libei_emulation { + println!("cargo::rustc-cfg=libei_emulation"); + } + if rdp_emulation { + println!("cargo::rustc-cfg=rdp_emulation"); + } + if wlroots_emulation { + println!("cargo::rustc-cfg=wlroots_emulation"); + } + if x11_emulation { + println!("cargo::rustc-cfg=x11_emulation"); + } } diff --git a/src/config.rs b/src/config.rs index 3faa59b..ecce2b4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -118,13 +118,13 @@ pub enum Command { #[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)] pub enum CaptureBackend { - #[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))] + #[cfg(libei_capture)] #[serde(rename = "input-capture-portal")] InputCapturePortal, - #[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))] + #[cfg(layer_shell_capture)] #[serde(rename = "layer-shell")] LayerShell, - #[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))] + #[cfg(x11_capture)] #[serde(rename = "x11")] X11, #[cfg(windows)] @@ -140,11 +140,11 @@ pub enum CaptureBackend { impl Display for CaptureBackend { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - #[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))] + #[cfg(libei_capture)] CaptureBackend::InputCapturePortal => write!(f, "input-capture-portal"), - #[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))] + #[cfg(layer_shell_capture)] CaptureBackend::LayerShell => write!(f, "layer-shell"), - #[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))] + #[cfg(x11_capture)] CaptureBackend::X11 => write!(f, "X11"), #[cfg(windows)] CaptureBackend::Windows => write!(f, "windows"), @@ -158,11 +158,11 @@ impl Display for CaptureBackend { impl From for input_capture::Backend { fn from(backend: CaptureBackend) -> Self { match backend { - #[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))] + #[cfg(libei_capture)] CaptureBackend::InputCapturePortal => Self::InputCapturePortal, - #[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))] + #[cfg(layer_shell_capture)] CaptureBackend::LayerShell => Self::LayerShell, - #[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))] + #[cfg(x11_capture)] CaptureBackend::X11 => Self::X11, #[cfg(windows)] CaptureBackend::Windows => Self::Windows, @@ -175,16 +175,16 @@ impl From for input_capture::Backend { #[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)] pub enum EmulationBackend { - #[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))] + #[cfg(wlroots_emulation)] #[serde(rename = "wlroots")] Wlroots, - #[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))] + #[cfg(libei_emulation)] #[serde(rename = "libei")] Libei, - #[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))] + #[cfg(rdp_emulation)] #[serde(rename = "xdp")] Xdp, - #[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))] + #[cfg(x11_emulation)] #[serde(rename = "x11")] X11, #[cfg(windows)] @@ -200,13 +200,13 @@ pub enum EmulationBackend { impl From for input_emulation::Backend { fn from(backend: EmulationBackend) -> Self { match backend { - #[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))] + #[cfg(wlroots_emulation)] EmulationBackend::Wlroots => Self::Wlroots, - #[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))] + #[cfg(libei_emulation)] EmulationBackend::Libei => Self::Libei, - #[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))] + #[cfg(rdp_emulation)] EmulationBackend::Xdp => Self::Xdp, - #[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))] + #[cfg(x11_emulation)] EmulationBackend::X11 => Self::X11, #[cfg(windows)] EmulationBackend::Windows => Self::Windows, @@ -220,13 +220,13 @@ impl From for input_emulation::Backend { impl Display for EmulationBackend { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - #[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))] + #[cfg(wlroots_emulation)] EmulationBackend::Wlroots => write!(f, "wlroots"), - #[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))] + #[cfg(libei_emulation)] EmulationBackend::Libei => write!(f, "libei"), - #[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))] + #[cfg(rdp_emulation)] EmulationBackend::Xdp => write!(f, "xdg-desktop-portal"), - #[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))] + #[cfg(x11_emulation)] EmulationBackend::X11 => write!(f, "X11"), #[cfg(windows)] EmulationBackend::Windows => write!(f, "windows"),