• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::env;
2 use std::process::Command;
3 use std::str;
4 
main()5 fn main() {
6     println!("cargo:rerun-if-env-changed=DOCS_RS");
7 
8     let compiler = match rustc_minor_version() {
9         Some(compiler) => compiler,
10         None => return,
11     };
12 
13     if compiler < 45 {
14         println!("cargo:rustc-cfg=no_span_mixed_site");
15     }
16 
17     if compiler < 47 {
18         println!("cargo:rustc-cfg=self_span_hack");
19     }
20 
21     if compiler >= 75 && env::var_os("DOCS_RS").is_none() {
22         println!("cargo:rustc-cfg=native_async_fn_in_trait");
23     }
24 }
25 
rustc_minor_version() -> Option<u32>26 fn rustc_minor_version() -> Option<u32> {
27     let rustc = env::var_os("RUSTC")?;
28     let output = Command::new(rustc).arg("--version").output().ok()?;
29     let version = str::from_utf8(&output.stdout).ok()?;
30     let mut pieces = version.split('.');
31     if pieces.next() != Some("rustc 1") {
32         return None;
33     }
34     pieces.next()?.parse().ok()
35 }
36