1 // For the 'try!' macro, until we bump MSRV past 1.12.
5 use std
::ffi
::OsString
;
6 use std
::io
::{self, Write}
;
7 use std
::process
::Command
;
10 let version
= match Version
::read() {
11 Ok(version
) => version
,
15 "failed to parse `rustc --version`: {}",
24 fn enable_i128(version
: Version
) {
25 if version
< (Version { major: 1, minor: 26, patch: 0 }
) {
29 println
!("cargo:rustc-cfg=byteorder_i128");
32 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
40 fn read() -> Result
<Version
, String
> {
41 let rustc
= env
::var_os("RUSTC").unwrap_or(OsString
::from("rustc"));
42 let output
= Command
::new(&rustc
)
47 Version
::parse(&String
::from_utf8(output
).unwrap())
50 fn parse(mut s
: &str) -> Result
<Version
, String
> {
51 if !s
.starts_with("rustc ") {
52 return Err(format
!("unrecognized version string: {}", s
));
54 s
= &s
["rustc ".len()..];
56 let parts
: Vec
<&str> = s
.split(".").collect();
58 return Err(format
!("not enough version parts: {:?}", parts
));
61 let mut num
= String
::new();
62 for c
in parts
[0].chars() {
68 let major
= try
!(num
.parse
::<u32>().map_err(|e
| e
.to_string()));
71 for c
in parts
[1].chars() {
77 let minor
= try
!(num
.parse
::<u32>().map_err(|e
| e
.to_string()));
80 for c
in parts
[2].chars() {
86 let patch
= try
!(num
.parse
::<u32>().map_err(|e
| e
.to_string()));
88 Ok(Version { major: major, minor: minor, patch: patch }
)