Skip to content

Commit f38b52c

Browse files
author
Hugo Laloge
committed
Hide the netlink monitoring behind cfg(target_os = "linux")
1 parent 3c34747 commit f38b52c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

zenoh/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ petgraph = { workspace = true }
9999
phf = { workspace = true }
100100
rand = { workspace = true, features = ["default"] }
101101
ref-cast = { workspace = true }
102-
rtnetlink = { workspace = true }
103102
serde = { workspace = true, features = ["default"] }
104103
serde_json = { workspace = true }
105104
socket2 = { workspace = true }
@@ -124,6 +123,9 @@ zenoh-runtime = { workspace = true }
124123
zenoh-task = { workspace = true }
125124
once_cell = { workspace = true }
126125

126+
[target.'cfg(target_os = "linux")'.dependencies]
127+
rtnetlink = { workspace = true }
128+
127129
[dev-dependencies]
128130
tokio = { workspace = true }
129131
libc = { workspace = true }

zenoh/src/net/runtime/mod.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
//!
1919
//! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh)
2020
mod adminspace;
21-
#[cfg(unix)]
21+
#[cfg(target_os = "linux")]
2222
mod netlink;
2323
pub mod orchestrator;
2424
mod scouting;
2525

2626
#[cfg(feature = "plugins")]
2727
use std::sync::{Mutex, MutexGuard};
28+
#[cfg(target_os = "linux")]
29+
use std::time::Duration;
2830
use std::{
2931
any::Any,
3032
collections::HashSet,
@@ -33,12 +35,12 @@ use std::{
3335
atomic::{AtomicU32, Ordering},
3436
Arc, Weak,
3537
},
36-
time::Duration,
3738
};
3839

3940
pub use adminspace::AdminSpace;
4041
use async_trait::async_trait;
4142
use futures::{stream::StreamExt, Future};
43+
#[cfg(target_os = "linux")]
4244
use rtnetlink::packet_route::{
4345
address::{AddressAttribute, AddressMessage},
4446
RouteNetlinkMessage,
@@ -65,6 +67,7 @@ use zenoh_transport::{
6567
multicast::TransportMulticast, unicast::TransportUnicast, TransportEventHandler,
6668
TransportManager, TransportMulticastEventHandler, TransportPeer, TransportPeerEventHandler,
6769
};
70+
#[cfg(target_os = "linux")]
6871
use zenoh_util::net::update_iface_cache;
6972

7073
use self::orchestrator::StartConditions;
@@ -83,7 +86,7 @@ use crate::{
8386
GIT_VERSION, LONG_VERSION,
8487
};
8588

86-
#[cfg(unix)]
89+
#[cfg(target_os = "linux")]
8790
const NETLINK_TIMEOUT: Duration = Duration::from_millis(500);
8891

8992
pub(crate) struct RuntimeState {
@@ -256,7 +259,7 @@ impl RuntimeBuilder {
256259
zenoh_config::ShmInitMode::Lazy => {}
257260
};
258261

259-
#[cfg(unix)]
262+
#[cfg(target_os = "linux")]
260263
runtime.spawn({
261264
let netlink_monitor = netlink::NetlinkMonitor::new()?;
262265
let runtime2 = runtime.clone();
@@ -390,7 +393,7 @@ impl Runtime {
390393
self.state.pending_connections.lock().await.remove(zid)
391394
}
392395

393-
#[cfg(unix)]
396+
#[cfg(target_os = "linux")]
394397
async fn monitor_netlink_socket(&self, mut netlink: netlink::NetlinkMonitor) {
395398
fn add_addr_to_set(
396399
message: &AddressMessage,

0 commit comments

Comments
 (0)