• 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-changed=build.rs");
7 
8     let rustc = match rustc_minor_version() {
9         Some(rustc) => rustc,
10         None => return,
11     };
12 
13     if rustc >= 80 {
14         println!("cargo:rustc-check-cfg=cfg(exhaustive)");
15         println!("cargo:rustc-check-cfg=cfg(no_unsafe_extern_blocks)");
16     }
17 
18     if rustc < 82 {
19         // https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#safe-items-with-unsafe-extern
20         println!("cargo:rustc-cfg=no_unsafe_extern_blocks");
21     }
22 }
23 
rustc_minor_version() -> Option<u32>24 fn rustc_minor_version() -> Option<u32> {
25     let rustc = env::var_os("RUSTC").unwrap();
26     let output = Command::new(rustc).arg("--version").output().ok()?;
27     let version = str::from_utf8(&output.stdout).ok()?;
28     let mut pieces = version.split('.');
29     if pieces.next() != Some("rustc 1") {
30         return None;
31     }
32     pieces.next()?.parse().ok()
33 }
34