From 9bc7fa707f0d958bc1fb3f3d276987a52edcb992 Mon Sep 17 00:00:00 2001 From: Collin Diekvoss Date: Thu, 5 Dec 2024 00:39:25 -0600 Subject: [PATCH] actual linux build --- src/darwin.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/darwin.rs b/src/darwin.rs index f4e2fa8..4b77413 100644 --- a/src/darwin.rs +++ b/src/darwin.rs @@ -1,9 +1,4 @@ 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; @@ -37,21 +32,27 @@ fn get_hostname(hostname: Option) -> Result { match &hostname { Some(h) => Ok(h.to_owned()), None => { - let hostname = if cfg!(target_os = "macos") { + #[cfg(target_os = "macos")] + { + use system_configuration::{ + core_foundation::{base::TCFType, string::CFString}, + sys::dynamic_store_copy_specific::SCDynamicStoreCopyLocalHostName, + }; let ptr = unsafe { SCDynamicStoreCopyLocalHostName(std::ptr::null()) }; if ptr.is_null() { bail!("Failed to get hostname"); } let name = unsafe { CFString::wrap_under_get_rule(ptr) }; - name.to_string() - } else { - hostname::get() + Ok(name.to_string()) + } + #[cfg(not(target_os = "macos"))] + { + Ok(hostname::get() .context("Failed to get hostname")? .to_str() .unwrap() - .to_string() + .to_string()) }; - Ok(hostname) } } }