fix(lib): enable building for windows targets

- conditionally build diag_device.rs only for unix
- use build time target for runtime metadata on unix
This commit is contained in:
oopsbagel
2025-04-07 16:29:35 -07:00
committed by Cooper Quintin
parent fa9e9319c2
commit 01e762a3d6
2 changed files with 18 additions and 7 deletions

View File

@@ -1,6 +1,5 @@
pub mod hdlc;
pub mod diag;
pub mod diag_device;
pub mod qmdl;
pub mod log_codes;
pub mod gsmtap;
@@ -9,5 +8,9 @@ pub mod pcap;
pub mod analysis;
pub mod util;
// bin/check.rs may target windows and does not use this mod
#[cfg(target_family = "unix")]
pub mod diag_device;
// re-export telcom_parser, since we use its types in our API
pub use telcom_parser;

View File

@@ -1,6 +1,8 @@
use nix::sys::utsname::uname;
use serde::Serialize;
#[cfg(target_family = "unix")]
use nix::sys::utsname::uname;
/// Expose binary and system information.
#[derive(Serialize, Debug)]
pub struct RuntimeMetadata {
@@ -23,6 +25,16 @@ impl RuntimeMetadata {
/// attributes from `uname(2)` and falling back to values from
/// `std::env::consts`.
pub fn new() -> Self {
let build_target = RuntimeMetadata {
rayhunter_version: env!("CARGO_PKG_VERSION").to_owned(),
arch: std::env::consts::ARCH.to_string(),
system_os: std::env::consts::OS.to_string(),
};
#[cfg(target_family = "windows")]
return build_target;
#[cfg(target_family = "unix")]
match uname() {
Ok(utsname) => RuntimeMetadata {
rayhunter_version: env!("CARGO_PKG_VERSION").to_owned(),
@@ -33,11 +45,7 @@ impl RuntimeMetadata {
utsname.release().to_string_lossy(),
),
},
Err(_) => RuntimeMetadata {
rayhunter_version: env!("CARGO_PKG_VERSION").to_owned(),
arch: std::env::consts::ARCH.to_string(),
system_os: std::env::consts::OS.to_string(),
},
Err(_) => build_target,
}
}
}