Use version_check crate instead of handcrafted version parsing

This commit is contained in:
Oliver Schneider 2018-05-18 14:41:40 +02:00
parent 2c05518810
commit 8890061f82
2 changed files with 12 additions and 35 deletions

View File

@ -23,6 +23,9 @@ serde_derive = { version = "1.0", optional = true, path = "../serde_derive" }
[dev-dependencies]
serde_derive = { version = "1.0", path = "../serde_derive" }
[build-dependencies]
version_check = "0.1.3"
### FEATURES #################################################################

View File

@ -1,39 +1,13 @@
use std::env;
use std::process::Command;
use std::str::{self, FromStr};
extern crate version_check;
fn main() {
let rustc = match env::var_os("RUSTC") {
Some(rustc) => rustc,
None => return,
match version_check::is_min_version("1.26.0") {
Some((true, _)) => {
println!("cargo:rustc-cfg=integer128");
},
Some((false, _)) => {}
None => {
println!("could not figure out the rustc version");
},
};
let output = match Command::new(rustc).arg("--version").output() {
Ok(output) => output,
Err(_) => return,
};
let version = match str::from_utf8(&output.stdout) {
Ok(version) => version,
Err(_) => return,
};
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return;
}
let next = match pieces.next() {
Some(next) => next,
None => return,
};
let minor = match u32::from_str(next) {
Ok(minor) => minor,
Err(_) => return,
};
if minor >= 26 {
println!("cargo:rustc-cfg=integer128");
}
}