From c5d673fcb8539186d8f18e6c8b321bc582e98979 Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Fri, 17 Jul 2026 01:43:10 +0700 Subject: [PATCH] build(uci): restrict UCI dependency and feature to Linux targets Ensure the UCI integration is only compiled on Linux, as the underlying native dependency is platform-specific. Added a build script to warn users when the feature is enabled on unsupported platforms. --- Cargo.toml | 4 +++- build.rs | 16 ++++++++++++++++ src/config.rs | 8 ++++---- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 7971aec..bb852ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ netlink-bindings = { git = "https://github.com/one-d-wide/netlink-bindings.git", netlink-socket2 = { git = "https://github.com/one-d-wide/netlink-bindings.git", rev = "0b609e9380610e7da73f8c43cdf804a1d1bf5474" } fastrand = "2" rustix = { version = "1.1", features = ["fs", "system", "thread", "time"] } -rust-uci = { git = "https://github.com/namib-project/rust-uci.git", rev = "3e7b6153b6df92b45428c32bb6461756563deecb", optional = true } thiserror = "2.0" libc = "0.2" flume = { version = "0.12.0", default-features = false, features = ["eventual-fairness", "select"] } @@ -34,5 +33,8 @@ flume = { version = "0.12.0", default-features = false, features = ["eventual-f features = ["std"] version = "0.4" +[target.'cfg(target_os = "linux")'.dependencies] +rust-uci = { git = "https://github.com/namib-project/rust-uci.git", rev = "3e7b6153b6df92b45428c32bb6461756563deecb", optional = true } + [features] uci = ["dep:rust-uci"] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ab69a5e --- /dev/null +++ b/build.rs @@ -0,0 +1,16 @@ +use std::env; + +fn main() { + let uci_enabled = env::var_os("CARGO_FEATURE_UCI").is_some(); + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); + let target = env::var("TARGET").unwrap_or_else(|_| "unknown".into()); + + if uci_enabled && target_os != "linux" { + println!( + "cargo::warning=feature `uci` is unsupported for target `{target}`; \ + UCI integration will not be compiled" + ); + } + + println!("cargo::rerun-if-changed=build.rs"); +} diff --git a/src/config.rs b/src/config.rs index 69b3dcf..db9a2c8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,9 +7,9 @@ use anyhow::Result; use log::Level; -#[cfg(feature = "uci")] +#[cfg(all(target_os = "linux", feature = "uci"))] use log::warn; -#[cfg(feature = "uci")] +#[cfg(all(target_os = "linux", feature = "uci"))] use rust_uci::Uci; use std::fmt; use std::fmt::Display; @@ -391,7 +391,7 @@ impl Config { None } - #[cfg(feature = "uci")] + #[cfg(all(target_os = "linux", feature = "uci"))] fn get_from_uci(key: &str) -> Option { let mut uci = match Uci::new() { Ok(val) => val, @@ -410,7 +410,7 @@ impl Config { }; } - #[cfg(not(feature = "uci"))] + #[cfg(not(all(target_os = "linux", feature = "uci")))] fn get_from_uci(_: &str) -> Option { None }