• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::env;
2 use std::path::Path;
3 use std::process::Command;
4 
main()5 fn main() {
6     if let Some(rustc) = rustc_version() {
7         if rustc.minor < 60 {
8             println!("cargo:warning=The cxx crate requires a rustc version 1.60.0 or newer.");
9             println!(
10                 "cargo:warning=You appear to be building with: {}",
11                 rustc.version,
12             );
13         }
14     }
15 }
16 
17 struct RustVersion {
18     version: String,
19     minor: u32,
20 }
21 
rustc_version() -> Option<RustVersion>22 fn rustc_version() -> Option<RustVersion> {
23     let rustc = env::var_os("RUSTC")?;
24     let output = Command::new(rustc).arg("--version").output().ok()?;
25     let version = String::from_utf8(output.stdout).ok()?;
26     let mut pieces = version.split('.');
27     if pieces.next() != Some("rustc 1") {
28         return None;
29     }
30     let minor = pieces.next()?.parse().ok()?;
31     Some(RustVersion { version, minor })
32 }
33