From e08cba3799bfdf7cd2b9acede205dc90e9931b1c Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Fri, 3 Nov 2023 13:34:22 -0400 Subject: [PATCH] Fix feature flags --- .githooks/pre-commit | 2 ++ .github/workflows/main.yml | 6 ++++-- Cargo.toml | 2 +- src/iter.rs | 1 + src/socket/asynchronous.rs | 2 +- src/socket/shared.rs | 17 ++++++++++++++--- src/utils.rs | 2 ++ 7 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 10752c3b..f7eafe59 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -4,6 +4,8 @@ cargo fmt -- --check \ && cargo clippy --all-targets --all-features -- -D warnings \ && RUSTDOCFLAGS="-D warnings" cargo doc \ && cargo build \ + && cargo build --no-default-features \ + && cargo build --no-default-features --features=async \ && cargo build --all-targets --all-features \ && cargo build --examples \ && ./target/debug/examples/getips \ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cf112d4a..a3c492ae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,8 @@ jobs: - cargo fmt -- --check - cargo build - RUSTDOCFLAGS="-D warnings" cargo doc - - cargo build --features=async + - cargo build --no-default-features + - cargo build --no-default-features --features=async - cargo build --all-features - cargo build --examples - cargo build --examples --all-features @@ -89,7 +90,8 @@ jobs: matrix: task: - cargo build - - cargo build --features=async + - cargo build --no-default-features + - cargo build --no-default-features --features=async - cargo build --all-features - cargo build --examples - cargo build --examples --all-features diff --git a/Cargo.toml b/Cargo.toml index ea5d469d..14046f8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,5 +52,5 @@ features = ["macros", "rt-multi-thread"] [features] default = ["sync"] sync = ["parking_lot"] -async = ["tokio"] +async = ["parking_lot", "tokio"] netfilter = [] diff --git a/src/iter.rs b/src/iter.rs index 1b6c61c9..f7514b37 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -20,6 +20,7 @@ impl NlBufferIter where B: AsRef<[u8]>, { + #[cfg(any(feature = "sync", feature = "async"))] pub(crate) fn new(buffer: Cursor) -> Self { NlBufferIter { buffer, diff --git a/src/socket/asynchronous.rs b/src/socket/asynchronous.rs index 0ea55b1c..a4f01b7d 100644 --- a/src/socket/asynchronous.rs +++ b/src/socket/asynchronous.rs @@ -23,7 +23,7 @@ use crate::{ /// Tokio-enabled Netlink socket struct pub struct NlSocketHandle { - socket: AsyncFd, + pub(super) socket: AsyncFd, pool: BufferPool, pid: u32, } diff --git a/src/socket/shared.rs b/src/socket/shared.rs index 4bcef9d9..2189f97d 100644 --- a/src/socket/shared.rs +++ b/src/socket/shared.rs @@ -6,9 +6,12 @@ use std::{ use libc::{c_int, c_void, sockaddr, sockaddr_nl}; +#[cfg(feature = "async")] +use crate::socket::asynchronous; +#[cfg(feature = "sync")] +use crate::socket::synchronous; use crate::{ consts::socket::*, - socket::synchronous::NlSocketHandle, utils::{Groups, NetlinkBitArray}, }; @@ -269,12 +272,20 @@ impl NlSocket { } } -impl From for NlSocket { - fn from(s: NlSocketHandle) -> Self { +#[cfg(feature = "sync")] +impl From for NlSocket { + fn from(s: synchronous::NlSocketHandle) -> Self { s.socket } } +#[cfg(feature = "async")] +impl From for NlSocket { + fn from(s: asynchronous::NlSocketHandle) -> Self { + s.socket.into_inner() + } +} + impl AsRawFd for NlSocket { fn as_raw_fd(&self) -> RawFd { self.fd diff --git a/src/utils.rs b/src/utils.rs index 5b9396f8..2e6ce344 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,6 +8,7 @@ use std::mem::size_of; +#[cfg(any(feature = "sync", feature = "async"))] use crate::consts::MAX_NL_LENGTH; type BitArrayType = u32; @@ -184,6 +185,7 @@ impl Groups { } /// Synchronous (blocking) utils. +#[cfg(feature = "sync")] pub mod synchronous { use super::*;