diff --git a/src/darwin.rs b/src/darwin.rs index 157929c..f4e2fa8 100644 --- a/src/darwin.rs +++ b/src/darwin.rs @@ -1,4 +1,9 @@ use color_eyre::eyre::{bail, Context}; +#[cfg(target_os = "macos")] +use system_configuration::{ + core_foundation::{base::TCFType, string::CFString}, + sys::dynamic_store_copy_specific::SCDynamicStoreCopyLocalHostName, +}; use tracing::{debug, info}; use crate::commands; @@ -32,12 +37,7 @@ fn get_hostname(hostname: Option) -> Result { match &hostname { Some(h) => Ok(h.to_owned()), None => { - let hostname = if cfg!(target_os = "macos") { - use system_configuration::{ - core_foundation::{base::TCFType, string::CFString}, - sys::dynamic_store_copy_specific::SCDynamicStoreCopyLocalHostName, - }; - + let hostname = if cfg!(target_os = "macos") { let ptr = unsafe { SCDynamicStoreCopyLocalHostName(std::ptr::null()) }; if ptr.is_null() { bail!("Failed to get hostname");