Isaac Woods | 79c80c4 | 2018-09-17 19:33:52 +0100 | [diff] [blame] | 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 | */ |
Mike Hommey | fdb9726 | 2018-11-21 16:43:24 +0900 | [diff] [blame] | 10 | if rustc_minor_version().expect("Failed to get rustc version") >= 30 { |
Isaac Woods | 79c80c4 | 2018-09-17 19:33:52 +0100 | [diff] [blame] | 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 | } |