• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::env;
2 use std::process::Command;
3 use std::str::{self, FromStr};
4 
main()5 fn main(){
6     let minor = match rustc_minor_version() {
7         Some(minor) => minor,
8         None => return,
9     };
10 
11     // const fn stabilized in Rust 1.31:
12     if minor >= 31 {
13         println!("cargo:rustc-cfg=bitflags_const_fn");
14     }
15 }
16 
rustc_minor_version() -> Option<u32>17 fn rustc_minor_version() -> Option<u32> {
18     let rustc = match env::var_os("RUSTC") {
19         Some(rustc) => rustc,
20         None => return None,
21     };
22 
23     let output = match Command::new(rustc).arg("--version").output() {
24         Ok(output) => output,
25         Err(_) => return None,
26     };
27 
28     let version = match str::from_utf8(&output.stdout) {
29         Ok(version) => version,
30         Err(_) => return None,
31     };
32 
33     let mut pieces = version.split('.');
34     if pieces.next() != Some("rustc 1") {
35         return None;
36     }
37 
38     let next = match pieces.next() {
39         Some(next) => next,
40         None => return None,
41     };
42 
43     u32::from_str(next).ok()
44 }