File: build.rs

package info (click to toggle)
rust-process-control 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,469 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::env;
use std::ffi::OsStr;

macro_rules! cfg_var {
    ( $name:ident , $value:ident ) => {
        env::var_os(format!(
            "CARGO_{}_{}",
            stringify!($name),
            stringify!($value).to_uppercase(),
        ))
        .is_some()
    };
}

macro_rules! targets {
    ( $name:ident => $($value:ident),+ ) => {
        env::var_os(concat!("CARGO_CFG_TARGET_", stringify!($name)))
            .as_deref()
            .and_then(OsStr::to_str)
            .is_some_and(|values| {
                let values: Vec<_> = values.split(',').collect();
                [$(stringify!($value)),+]
                    .into_iter()
                    .any(|x| values.contains(&x))
            })
    };
}

macro_rules! new_cfg {
    ( $name:expr , $condition:expr ) => {{
        println!("cargo:rustc-check-cfg=cfg({})", $name);
        if $condition {
            println!("cargo:rustc-cfg={}", $name);
        }
    }};
}

macro_rules! new_crate_cfg {
    ( $name:ident , $condition:expr $(,)? ) => {
        new_cfg!(concat!("process_control_", stringify!($name)), $condition)
    };
}

fn main() {
    new_crate_cfg!(docs_rs, false);
    new_crate_cfg!(
        memory_limit,
        targets!(OS => android)
            || (targets!(OS => linux) && targets!(ENV => gnu, musl))
            || cfg_var!(CFG, windows),
    );
    new_crate_cfg!(
        unix_waitid,
        !targets!(OS => espidf, horizon, openbsd, redox, tvos, vxworks),
    );
}