Fix build.rs formatting and prep it for further feature detections

This commit is contained in:
Mahmoud Al-Qudsi 2023-03-19 18:11:09 -05:00
parent 99c6c76c5e
commit 3fab931e86

View file

@ -83,9 +83,11 @@ fn main() -> miette::Result<()> {
/// [0]: https://github.com/rust-lang/cargo/issues/5499
fn detect_features() {
for (feature, detector) in [
("bsd", detect_bsd),
]
{
// Ignore the first line, it just sets up the type inference. Model new entries after the
// second line.
("", &(|| Ok(false)) as &dyn Fn() -> miette::Result<bool>),
("bsd", &detect_bsd),
] {
match detector() {
Err(e) => eprintln!("{feature} detect: {e}"),
Ok(true) => println!("cargo:rustc-cfg=feature=\"{feature}\""),
@ -101,7 +103,8 @@ fn detect_features() {
/// doesn't necessarily include less-popular forks nor does it group them into families more
/// specific than "windows" vs "unix" so we can conditionally compile code for BSD systems.
fn detect_bsd() -> miette::Result<bool> {
let uname = std::process::Command::new("uname").output()
let uname = std::process::Command::new("uname")
.output()
.map_err(|_| miette!("Error executing uname!"))?;
Ok(std::str::from_utf8(&uname.stdout)
.map(|s| s.to_ascii_lowercase())