• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::env;
2 use std::process::Command;
3 use std::str::{self, FromStr};
4 
5 // The rustc-cfg strings below are *not* public API. Please let us know by
6 // opening a GitHub issue if your build environment requires some way to enable
7 // these cfgs other than by executing our build script.
main()8 fn main() {
9     let minor = match rustc_minor_version() {
10         Some(minor) => minor,
11         None => return,
12     };
13 
14     // #[track_caller] stabilized in Rust 1.46:
15     // https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html#track_caller
16     if minor >= 46 {
17         println!("cargo:rustc-cfg=track_caller");
18     }
19 }
20 
rustc_minor_version() -> Option<u32>21 fn rustc_minor_version() -> Option<u32> {
22     let rustc = match env::var_os("RUSTC") {
23         Some(rustc) => rustc,
24         None => return None,
25     };
26 
27     let output = match Command::new(rustc).arg("--version").output() {
28         Ok(output) => output,
29         Err(_) => return None,
30     };
31 
32     let version = match str::from_utf8(&output.stdout) {
33         Ok(version) => version,
34         Err(_) => return None,
35     };
36 
37     let mut pieces = version.split('.');
38     if pieces.next() != Some("rustc 1") {
39         return None;
40     }
41 
42     let next = match pieces.next() {
43         Some(next) => next,
44         None => return None,
45     };
46 
47     u32::from_str(next).ok()
48 }
49