File: build.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (27 lines) | stat: -rw-r--r-- 895 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::process::Command;
use std::str;

fn main() {
    // Temporary check to see if the rustc version >= 1.81 in which case the
    // `Error` trait is always available. This is temporary because in the
    // future the MSRV of this crate will be beyond 1.81 in which case this
    // build script can be deleted.
    let minor = rustc_minor_version().unwrap_or(0);
    if minor >= 81 {
        println!("cargo:rustc-cfg=core_error");
    }
    if minor >= 80 {
        println!("cargo:rustc-check-cfg=cfg(core_error)");
    }
}

fn rustc_minor_version() -> Option<u32> {
    let rustc = std::env::var("RUSTC").unwrap();
    let output = Command::new(rustc).arg("--version").output().ok()?;
    let version = str::from_utf8(&output.stdout).ok()?;
    let mut pieces = version.split('.');
    if pieces.next() != Some("rustc 1") {
        return None;
    }
    pieces.next()?.parse().ok()
}