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.
This commit is contained in:
3 files changed
+23
-5
No files matched your search
+3
-1
@@ -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"]
|
||||
@@ -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");
|
||||
}
|
||||
+4
-4
@@ -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<String> {
|
||||
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<String> {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user