diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 0000000..3910034 --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,114 @@ +############################################################################ +# Cirrus workflow for testing on (Free)BSD. +# +# References: +# - https://cirrus-ci.org/guide/writing-tasks/ +# - https://github.com/tokio-rs/tokio/blob/master/.cirrus.yml +# - https://github.com/nix-rust/nix/blob/master/.cirrus.yml +# - https://github.com/jakewilliami/HiddenFiles.jl/blob/master/.cirrus.yml +# +# TODO: +# - Implement tests for other BSD OS's (will need to handle setup +# differently for Tier 3 support OS's) +############################################################################ + +# Specify container (FreeBSD) +# +# References: +# - https://cirrus-ci.org/guide/writing-tasks/#execution-environment +# - https://cirrus-ci.org/guide/FreeBSD/ +freebsd_instance: + image: freebsd-13-1-release-amd64 + +# Set up environment variables +env: + # The minimum supported Rust version (MSRV) + # https://github.com/foresterre/cargo-msrv + TOOLCHAIN: 1.56.1 + +# Define set up procedure by downloading Rustup (to consume later) +setup_common: &SETUP + setup_script: + - kldload mqueuefs + - fetch https://sh.rustup.rs -o rustup.sh + - sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN + - rm rustup.sh + - . $HOME/.cargo/env || true + - rustup --version + - cargo -Vv + - rustc -Vv + - ifconfig + +# Cache the Cargo directory between runs +cargo_cache: + folder: $CARGO_HOME/registry + fingerprint_script: cat Cargo.lock || echo "" + +# Test Cargo Build +task: + name: "Builds on FreeBSD 13" + <<: *SETUP + env: + RUSTFLAGS: "-D warnings" + test_script: + - . $HOME/.cargo/env || true + - cargo +$TOOLCHAIN build --release --all-targets + before_cache_script: rm -rf $CARGO_HOME/registry/index + +# Run Unit Tests +task: + name: "Runs \"cargo test\" on FreeBSD 13" + <<: *SETUP + env: + RUSTFLAGS: "-D warnings" + RUSTDOCFLAGS: -D warnings + test_script: + - . $HOME/.cargo/env || true + - cargo +$TOOLCHAIN test --all --all-features -- --nocapture + - cargo +$TOOLCHAIN doc --no-deps + before_cache_script: rm -rf $CARGO_HOME/registry/index + +# Run example +task: + name: "Runs \"cargo run --example demo\" on FreeBSD 13" + <<: *SETUP + env: + RUSTFLAGS: "-D warnings" + RUSTDOCFLAGS: -D warnings + test_script: + - . $HOME/.cargo/env || true + - cargo +$TOOLCHAIN run --example demo --all-features + before_cache_script: rm -rf $CARGO_HOME/registry/index + +# Test Cargo Clippy +task: + name: "Runs \"cargo clippy\" on FreeBSD 13" + <<: *SETUP + install_script: + - . $HOME/.cargo/env || true + - rustup component add --toolchain $TOOLCHAIN clippy + test_script: + - . $HOME/.cargo/env || true + - cargo +$TOOLCHAIN clippy --all-targets + before_cache_script: rm -rf $CARGO_HOME/registry/index + +# Test Cargo Fmt +task: + name: "Runs \"cargo fmt\" on FreeBSD 13" + <<: *SETUP + install_script: + - . $HOME/.cargo/env || true + - rustup +$TOOLCHAIN component add rustfmt + test_script: + - . $HOME/.cargo/env || true + - cargo +$TOOLCHAIN fmt --all -- --check + before_cache_script: rm -rf $CARGO_HOME/registry/index + +# Test Cargo Publish +task: + name: "Runs \"cargo publish --dry-run\" on FreeBSD 13" + <<: *SETUP + test_script: + - . $HOME/.cargo/env || true + - cargo +$TOOLCHAIN publish --dry-run + before_cache_script: rm -rf $CARGO_HOME/registry/index diff --git a/Cargo.toml b/Cargo.toml index 6b67c1c..01e96dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "network-interface" -description = "Retrieve system's Network Interfaces on Linux, macOS and Windows on a standarized manner" +description = "Retrieve system's Network Interfaces on Linux, FreeBSD, macOS and Windows on a standarized manner" version = "1.1.1" repository = "https://github.com/EstebanBorai/network-interface" categories = ["web-programming", "network-programming"] @@ -19,10 +19,10 @@ thiserror = "1.0" [target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] libc = "0.2.101" -[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] +[target.'cfg(any(target_os = "ios", target_os = "macos", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly"))'.dependencies] libc = "0.2.101" -[target.'cfg(target_os = "macos")'.build-dependencies] +[target.'cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly"))'.build-dependencies] cc = "1.0.73" [target.'cfg(target_os = "windows")'.dependencies] diff --git a/README.md b/README.md index e60f441..314bfbb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

network-interface

- Retrieve system's Network Interfaces/Adapters on Android, Linux, macOS, iOS and Windows + Retrieve system's Network Interfaces/Adapters on Android, FreeBSD, Linux, macOS, iOS and Windows on a standarized manner

diff --git a/build.rs b/build.rs index beb0b55..7b056f1 100644 --- a/build.rs +++ b/build.rs @@ -1,17 +1,37 @@ fn main() { - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd", + target_os = "dragonfly" + ))] { use cc::Build; use std::path::Path; const TARGET_MACOS: &str = "macos"; const TARGET_IOS: &str = "ios"; + const TARGET_FREEBSD: &str = "freebsd"; + const TARGET_OPENBSD: &str = "openbsd"; + const TARGET_NETBSD: &str = "netbsd"; + const TARGET_DRAGONFLY: &str = "dragonfly"; - // check cross-compile target. Only build lladdr.o when actually targeting macOS. + // check cross-compile target. Only build lladdr.o when actually targeting UNIX. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); - if [TARGET_MACOS, TARGET_IOS].contains(&target_os.as_str()) { + if [ + TARGET_MACOS, + TARGET_IOS, + TARGET_FREEBSD, + TARGET_OPENBSD, + TARGET_NETBSD, + TARGET_DRAGONFLY, + ] + .contains(&target_os.as_str()) + { let path = Path::new("src") .join("target") - .join("apple") + .join("unix") .join("ffi") .join("lladdr.c"); diff --git a/src/target/apple/ffi/mod.rs b/src/target/apple/ffi/mod.rs deleted file mode 100644 index 90a1e91..0000000 --- a/src/target/apple/ffi/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -use libc::ifaddrs; - -#[cfg(any(target_os = "macos", target_os = "ios"))] -extern "C" { - pub fn lladdr(ptr: *mut ifaddrs) -> *const u8; -} diff --git a/src/target/mod.rs b/src/target/mod.rs index 9226cf3..aa1abbc 100644 --- a/src/target/mod.rs +++ b/src/target/mod.rs @@ -4,11 +4,25 @@ mod linux; #[cfg(any(target_os = "android", target_os = "linux"))] pub use linux::*; -#[cfg(any(target_os = "macos", target_os = "ios"))] -mod apple; +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd", + target_os = "dragonfly" +))] +mod unix; -#[cfg(any(target_os = "macos", target_os = "ios"))] -pub use apple::*; +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd", + target_os = "dragonfly" +))] +pub use unix::*; #[cfg(target_os = "windows")] mod windows; diff --git a/src/target/apple/ffi/lladdr.c b/src/target/unix/ffi/lladdr.c similarity index 100% rename from src/target/apple/ffi/lladdr.c rename to src/target/unix/ffi/lladdr.c diff --git a/src/target/unix/ffi/mod.rs b/src/target/unix/ffi/mod.rs new file mode 100644 index 0000000..42f6d98 --- /dev/null +++ b/src/target/unix/ffi/mod.rs @@ -0,0 +1,13 @@ +use libc::ifaddrs; + +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd", + target_os = "dragonfly" +))] +extern "C" { + pub fn lladdr(ptr: *mut ifaddrs) -> *const u8; +} diff --git a/src/target/apple/mod.rs b/src/target/unix/mod.rs similarity index 100% rename from src/target/apple/mod.rs rename to src/target/unix/mod.rs diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 2b765b7..4d23250 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,10 +1,15 @@ #[cfg(windows)] pub mod hex; + #[cfg(any( target_os = "android", target_os = "linux", target_os = "ios", - target_os = "macos" + target_os = "macos", + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd", + target_os = "dragonfly" ))] mod unix; @@ -12,6 +17,10 @@ mod unix; target_os = "android", target_os = "linux", target_os = "ios", - target_os = "macos" + target_os = "macos", + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd", + target_os = "dragonfly" ))] pub use unix::*;