Debian Codegraph @

crates/wasm-encoder/build.rs

raw
1 use std::process::Command;
2 use std::str;
3
4 fn main() {
5 // Temporary check to see if the rustc version >= 1.81 in which case the
6 // `Error` trait is always available. This is temporary because in the
7 // future the MSRV of this crate will be beyond 1.81 in which case this
8 // build script can be deleted.
9 let minor = rustc_minor_version().unwrap_or(0);
10 if minor >= 81 {
11 println!("cargo:rustc-cfg=core_error");
12 }
13 if minor >= 80 {
14 println!("cargo:rustc-check-cfg=cfg(core_error)");
15 }
16 }
17
18 fn rustc_minor_version() -> Option<u32> {
19 let rustc = std::env::var("RUSTC").unwrap();
20 let output = Command::new(rustc).arg("--version").output().ok()?;
21 let version = str::from_utf8(&output.stdout).ok()?;
22 let mut pieces = version.split('.');
23 if pieces.next() != Some("rustc 1") {
24 return None;
25 }
26 pieces.next()?.parse().ok()
27 }