Skip to content

Commit

Permalink
actual linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
ToyVo committed Dec 5, 2024
1 parent 0c7c3c7 commit 9bc7fa7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/darwin.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,21 +32,27 @@ fn get_hostname(hostname: Option<String>) -> Result<String> {
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)
}
}
}
Expand Down

0 comments on commit 9bc7fa7

Please sign in to comment.