forked from indianakernick/The-Fat-Controller
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.rs
38 lines (34 loc) · 1.03 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn main() {
#[cfg(all(feature = "check-x11", target_os = "linux"))]
if linux_session_type()
.map(|x| x.contains("x11"))
.unwrap_or(false)
{
println!("cargo:rustc-cfg=x11");
}
#[cfg(feature = "x11")]
println!("cargo:rustc-cfg=x11");
}
#[cfg(all(feature = "check-x11", target_os = "linux"))]
fn linux_session_type() -> Result<String, Box<dyn std::error::Error>> {
use std::process::Command;
// Really rough implementation of this:
// https://unix.stackexchange.com/a/325972/356153
let output = Command::new("loginctl").output()?;
let user = std::env::var("USER")?;
let session = std::str::from_utf8(&output.stdout)?
.lines()
.find(|x| x.contains(&user))
.unwrap_or("")
.trim()
.split(' ')
.next()
.unwrap_or("");
let output = Command::new("loginctl")
.arg("show-session")
.arg(session)
.arg("-p")
.arg("Type")
.output()?;
Ok(std::str::from_utf8(&output.stdout)?.to_string())
}