xref: /rust-libc-0.2.174/build.rs (revision b46b6e2e)
1 use std::env;
2 use std::process::Command;
3 use std::str;
4 
5 fn main() {
6     /*
7      * If `core::ffi::c_void` exists, libc can just re-export it. Otherwise, it
8      * must define an incompatible type to retain backwards-compatibility.
9      */
10     if rustc_minor_version().expect("Failed to get rustc version") >= 30 {
11         println!("cargo:rustc-cfg=core_cvoid");
12     }
13 }
14 
15 fn rustc_minor_version() -> Option<u32> {
16     macro_rules! otry {
17         ($e:expr) => {
18             match $e {
19                 Some(e) => e,
20                 None => return None,
21             }
22         };
23     }
24 
25     let rustc = otry!(env::var_os("RUSTC"));
26     let output = otry!(Command::new(rustc).arg("--version").output().ok());
27     let version = otry!(str::from_utf8(&output.stdout).ok());
28     let mut pieces = version.split('.');
29 
30     if pieces.next() != Some("rustc 1") {
31         return None;
32     }
33 
34     otry!(pieces.next()).parse().ok()
35 }
36