Skip to content

Commit fabb0bc

Browse files
committed
macos
1 parent af1dd71 commit fabb0bc

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

lib/bencher_fingerprint/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ authors.workspace = true
66
edition.workspace = true
77
license-file.workspace = true
88

9-
[target.'cfg(windows)'.dependencies]
9+
[target.'cfg(target_os = "macos")'.dependencies]
10+
uuid.workspace = true
11+
12+
[target.'cfg(target_os = "windows")'.dependencies]
1013
uuid.workspace = true
1114
windows = { version = "0.60", features = ["System_Profile"] }
1215

lib/bencher_fingerprint/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const BUF_SIZE: usize = 25;
55

66
#[cfg(target_os = "linux")]
77
mod linux;
8+
#[cfg(target_os = "macos")]
9+
mod macos;
810
#[cfg(target_os = "windows")]
911
mod windows;
1012

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::process::Command;
2+
3+
use uuid::Uuid;
4+
5+
impl crate::Fingerprint {
6+
pub fn new() -> Option<Self> {
7+
Command::new("ioreg")
8+
.arg("-d2")
9+
.arg("-c")
10+
.arg("IOPlatformExpertDevice")
11+
.output()
12+
.ok()
13+
.and_then(|out| String::from_utf8(out.stdout).ok())
14+
.and_then(|output| {
15+
for line in output.lines() {
16+
if let Some((_, uuid)) = line.split_once(r#""IOPlatformUUID" = ""#) {
17+
if let Some((uuid, _)) = uuid.split_once('"') {
18+
return Uuid::parse_str(uuid).ok();
19+
}
20+
}
21+
}
22+
None
23+
})
24+
.map(|uuid| uuid.as_u128())
25+
.map(Self)
26+
}
27+
}

0 commit comments

Comments
 (0)