is_musl/
lib.rs

1pub fn is_musl() -> bool {
2    if std::env::consts::OS == "linux" {
3        if is_musl_from_filesystem() == Some(true) {
4            return true;
5        }
6        if is_musl_from_child_process() == Some(true) {
7            return true;
8        }
9    }
10
11    false
12}
13
14fn is_musl_from_filesystem() -> Option<bool> {
15    for i in ["/bin/sh", "/usr/bin/ldd"] {
16        if let Ok(found) = std::fs::read(i).map(|i| String::from_utf8_lossy(&i).contains("musl")) {
17            return Some(found);
18        }
19    }
20    None
21}
22
23fn is_musl_from_child_process() -> Option<bool> {
24    let s = std::process::Command::new("ldd").arg("--version").output();
25    s.ok()
26        .and_then(|i| String::from_utf8(i.stdout).ok().map(|s| s.contains("musl")))
27}