Skip to content

Commit

Permalink
Avoid build failures of unsupported examples on freebsd
Browse files Browse the repository at this point in the history
I'm not really happy with the readability, there ought to be a real
way to mark an example as "non applicable in cfg so and so".

Signed-off-by: Yann Dirson <[email protected]>
  • Loading branch information
ydirson committed Jan 10, 2024
1 parent 9a16d8c commit 0c14bce
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/add_netns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: MIT

#[cfg(any(linux, android))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(not(any(linux, android)))]
fn main() -> () {}

#[cfg(any(linux, android))]
#[tokio::main]
async fn main() -> Result<(), String> {
env_logger::init();
Expand Down
5 changes: 5 additions & 0 deletions examples/add_netns_async.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: MIT

#[cfg(any(linux, android))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(not(any(linux, android)))]
fn main() -> () {}

#[cfg(any(linux, android))]
#[async_std::main]
async fn main() -> Result<(), String> {
env_logger::init();
Expand Down
4 changes: 4 additions & 0 deletions examples/add_tc_qdisc_ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use std::env;

use rtnetlink::new_connection;

#[cfg(not(any(linux, android)))]
fn main() -> () {}

#[cfg(any(linux, android))]
#[tokio::main]
async fn main() -> Result<(), ()> {
env_logger::init();
Expand Down
5 changes: 5 additions & 0 deletions examples/del_netns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: MIT

#[cfg(any(linux, android))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(not(any(linux, android)))]
fn main() -> () {}

#[cfg(any(linux, android))]
#[tokio::main]
async fn main() -> Result<(), String> {
let args: Vec<String> = env::args().collect();
Expand Down
5 changes: 5 additions & 0 deletions examples/del_netns_async.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: MIT

#[cfg(any(linux, android))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(not(any(linux, android)))]
fn main() -> () {}

#[cfg(any(linux, android))]
#[async_std::main]
async fn main() -> Result<(), String> {
let args: Vec<String> = env::args().collect();
Expand Down
5 changes: 5 additions & 0 deletions examples/get_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use netlink_packet_route::{
};
use rtnetlink::{new_connection, Error, Handle};

#[cfg(not(any(linux, android)))]
fn main() -> () {}

#[cfg(any(linux, android))]
#[tokio::main]
async fn main() -> Result<(), ()> {
env_logger::init();
Expand Down Expand Up @@ -90,6 +94,7 @@ async fn dump_links(handle: Handle) -> Result<(), Error> {
Ok(())
}

#[cfg(any(linux, android))]
async fn dump_bridge_filter_info(handle: Handle) -> Result<(), Error> {
let mut links = handle
.link()
Expand Down
5 changes: 5 additions & 0 deletions examples/get_links_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use netlink_packet_route::{
};
use rtnetlink::{new_connection, Error, Handle};

#[cfg(not(any(linux, android)))]
fn main() -> () {}

#[cfg(any(linux, android))]
#[async_std::main]
async fn main() -> Result<(), ()> {
env_logger::init();
Expand Down Expand Up @@ -90,6 +94,7 @@ async fn dump_links(handle: Handle) -> Result<(), Error> {
Ok(())
}

#[cfg(any(linux, android))]
async fn dump_bridge_filter_info(handle: Handle) -> Result<(), Error> {
let mut links = handle
.link()
Expand Down
10 changes: 9 additions & 1 deletion examples/get_links_thread_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use netlink_packet_route::{
link::{LinkAttribute, LinkExtentMask},
AddressFamily,
};
use rtnetlink::{new_connection, Error, Handle};
#[cfg(any(linux, android))]
use rtnetlink::new_connection;
use rtnetlink::{Error, Handle};

#[cfg(any(linux, android))]
async fn do_it(rt: &tokio::runtime::Runtime) -> Result<(), ()> {
env_logger::init();
let (connection, handle, _) = new_connection().unwrap();
Expand Down Expand Up @@ -89,6 +92,7 @@ async fn dump_links(handle: Handle) -> Result<(), Error> {
Ok(())
}

#[cfg(any(linux, android))]
async fn dump_bridge_filter_info(handle: Handle) -> Result<(), Error> {
let mut links = handle
.link()
Expand All @@ -109,6 +113,10 @@ async fn dump_bridge_filter_info(handle: Handle) -> Result<(), Error> {
Ok(())
}

#[cfg(not(any(linux, android)))]
fn main() -> () {}

#[cfg(any(linux, android))]
fn main() -> Result<(), String> {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_io()
Expand Down

0 comments on commit 0c14bce

Please sign in to comment.