Skip to content

Commit

Permalink
Make serde_test build script buildable with older rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 21, 2022
1 parent d1d2594 commit c6057f8
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions serde_test/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;
use std::process::Command;
use std::str;
use std::str::{self, FromStr};

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
Expand All @@ -19,12 +19,30 @@ fn main() {
}

fn rustc_minor_version() -> Option<u32> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let rustc = match env::var_os("RUSTC") {
Some(rustc) => rustc,
None => return None,
};

let output = match Command::new(rustc).arg("--version").output() {
Ok(output) => output,
Err(_) => return None,
};

let version = match str::from_utf8(&output.stdout) {
Ok(version) => version,
Err(_) => return None,
};

let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
pieces.next()?.parse().ok()

let next = match pieces.next() {
Some(next) => next,
None => return None,
};

u32::from_str(next).ok()
}

0 comments on commit c6057f8

Please sign in to comment.