blob: aa56ea054506c4f0947ec8aac5a20d62723b8e1a [file] [log] [blame]
Isaac Woods79c80c42018-09-17 19:33:52 +01001use std::env;
2use std::process::Command;
3use std::str;
4
5fn 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") >= 31 {
11 println!("cargo:rustc-cfg=core_cvoid");
12 }
13}
14
15fn 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}