Skip to content

Commit

Permalink
Add check_dependencies feature
Browse files Browse the repository at this point in the history
  • Loading branch information
moubctez committed Dec 11, 2024
1 parent 4f01b6c commit d25a186
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ netlink-sys = "0.8"

[features]
default = ["serde"]
check_dependencies = []
serde = ["dep:serde"]

[profile.release]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/wgapi.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,6 +20,7 @@ pub struct WGApi<API = Kernel> {
impl WGApi {
/// Create new instance of `WGApi`.
pub fn new(ifname: String) -> Result<Self, WireguardInterfaceError> {
#[cfg(feature = "check_dependencies")]
check_external_dependencies()?;
Ok(WGApi {
ifname,
Expand Down
4 changes: 3 additions & 1 deletion src/wgapi_userspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand All @@ -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},
Expand All @@ -37,6 +38,7 @@ impl WGApi<Userspace> {
/// # Errors
/// Will return `WireguardInterfaceError` if `wireguard-go` can't be found.
pub fn new(ifname: String) -> Result<Self, WireguardInterfaceError> {
#[cfg(feature = "check_dependencies")]
check_external_dependencies()?;
Ok(WGApi {
ifname,
Expand Down

0 comments on commit d25a186

Please sign in to comment.