diff --git a/Cargo.toml b/Cargo.toml index 30bd0e2..a2c3724 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ netlink-sys = "0.8" [features] default = ["serde"] +check_dependencies = [] serde = ["dep:serde"] [profile.release] diff --git a/src/lib.rs b/src/lib.rs index 6cf5296..fc98ca1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,6 +61,7 @@ pub(crate) mod netlink; mod utils; mod wgapi; +#[cfg(feature = "check_dependencies")] mod dependencies; #[cfg(target_os = "freebsd")] mod wgapi_freebsd; diff --git a/src/wgapi.rs b/src/wgapi.rs index d02e196..d0b6fa2 100644 --- a/src/wgapi.rs +++ b/src/wgapi.rs @@ -1,7 +1,9 @@ //! Shared multi-platform management API abstraction use std::marker::PhantomData; -use crate::{dependencies::check_external_dependencies, error::WireguardInterfaceError}; +#[cfg(feature = "check_dependencies")] +use crate::dependencies::check_external_dependencies; +use crate::error::WireguardInterfaceError; pub struct Kernel; pub struct Userspace; @@ -18,6 +20,7 @@ pub struct WGApi { impl WGApi { /// Create new instance of `WGApi`. pub fn new(ifname: String) -> Result { + #[cfg(feature = "check_dependencies")] check_external_dependencies()?; Ok(WGApi { ifname, diff --git a/src/wgapi_userspace.rs b/src/wgapi_userspace.rs index ffb9881..fd6d86b 100644 --- a/src/wgapi_userspace.rs +++ b/src/wgapi_userspace.rs @@ -9,6 +9,8 @@ use std::{ time::Duration, }; +#[cfg(feature = "check_dependencies")] +use crate::dependencies::check_external_dependencies; #[cfg(target_os = "linux")] use crate::netlink; #[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "netbsd"))] @@ -17,7 +19,6 @@ use crate::utils::clear_dns; use crate::{bsd, utils::resolve}; use crate::{ check_command_output_status, - dependencies::check_external_dependencies, error::WireguardInterfaceError, utils::{add_peer_routing, configure_dns}, wgapi::{Userspace, WGApi}, @@ -37,6 +38,7 @@ impl WGApi { /// # Errors /// Will return `WireguardInterfaceError` if `wireguard-go` can't be found. pub fn new(ifname: String) -> Result { + #[cfg(feature = "check_dependencies")] check_external_dependencies()?; Ok(WGApi { ifname,