xref: /third_party/rust/crates/cxx/build.rs (revision 33d722a9)
1use std::env;
2use std::path::Path;
3use std::process::Command;
4
5fn 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
17struct RustVersion {
18    version: String,
19    minor: u32,
20}
21
22fn 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