From 06d8a44f180273db868f2ba3d92d58dc63185995 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 26 May 2018 17:18:14 -0700 Subject: [PATCH] Move unimportant code out of build script main --- serde/build.rs | 58 +++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/serde/build.rs b/serde/build.rs index fcff8e6d..c007135e 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -3,36 +3,11 @@ use std::process::Command; use std::str::{self, FromStr}; fn main() { - let rustc = match env::var_os("RUSTC") { - Some(rustc) => rustc, + let minor = match rustc_minor_version() { + Some(minor) => minor, None => return, }; - 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, - }; - // CString::into_boxed_c_str stabilized in Rust 1.20: // https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str if minor >= 20 { @@ -58,3 +33,32 @@ fn main() { println!("cargo:rustc-cfg=num_nonzero"); } } + +fn rustc_minor_version() -> Option { + 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; + } + + let next = match pieces.next() { + Some(next) => next, + None => return None, + }; + + u32::from_str(next).ok() +}