Skip to content
Myr

Merge pull request #21 from dtolnay/build

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Detect compiler minor version in build script

authored by David Tolnay · committed by GitHub · parents f432c46, d782e42 · Browse files · 1 file+14 added−18 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−18 removed

  • other:+14 added−18 removed

1 file+14 added−18 removed

modified:build.rs+14 added-18 removed
1use std::env;2use std::process::Command;3use std::str;3use std::str::{self, FromStr};45fn main() {6 let compiler = match rustc_version() {7 Some(compiler) => compiler,8 None => return,9 };1011 if compiler.nightly {11 if compiler.minor >= 40 && compiler.nightly {12 println!("cargo:rustc-cfg=backtrace");13 }14}1516struct Compiler {17 minor: u32,18 nightly: bool,19}2021fn rustc_version() -> Option<Compiler> {21 let rustc = match env::var_os("RUSTC") {22 Some(rustc) => rustc,23 None => return None,24 };22 let rustc = env::var_os("RUSTC")?;23 let output = Command::new(rustc).arg("--version").output().ok()?;24 let version = str::from_utf8(&output.stdout).ok()?;2526 let output = match Command::new(rustc).arg("--version").output() {27 Ok(output) => output,28 Err(_) => return None,29 };26 let mut pieces = version.split('.');27 if pieces.next() != Some("rustc 1") {28 return None;29 }3031 let version = match str::from_utf8(&output.stdout) {32 Ok(version) => version,33 Err(_) => return None,34 };3536 Some(Compiler {37 nightly: version.contains("nightly") || version.contains("dev"),38 })31 let next = pieces.next()?;32 let minor = u32::from_str(next).ok()?;33 let nightly = version.contains("nightly") || version.contains("dev");34 Some(Compiler { minor, nightly })35}