Skip to content

Commit a8339e7

Browse files
committed
Drop dependency on rustc_version
Unfortunately this has upstream bugs like djc/rustc-version-rs#11 which make the output non-robust in the face of changing rustc's output, so switch to a more flexible manual implementation.
1 parent a96048c commit a8339e7

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ repository = "https://github.com/srijs/rust-crc32fast"
1111
readme = "README.md"
1212
keywords = ["checksum", "crc", "crc32", "simd", "fast"]
1313

14-
[build-dependencies]
15-
rustc_version = "0.2"
16-
1714
[dev-dependencies]
1815
bencher = "0.1"
1916
quickcheck = { version = "0.6", default-features = false }

build.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
extern crate rustc_version;
1+
use std::env;
2+
use std::process::Command;
3+
use std::str;
24

35
fn main() {
46
println!("cargo:rerun-if-changed=build.rs");
57

6-
let version = rustc_version::version().unwrap();
8+
let minor = match rustc_minor_version() {
9+
Some(n) => n,
10+
None => return,
11+
};
712

8-
if version >= (1, 27, 0).into() {
13+
if minor >= 27 {
914
println!("cargo:rustc-cfg=crc32fast_stdarchx86");
1015
}
1116
}
17+
18+
fn rustc_minor_version() -> Option<u32> {
19+
macro_rules! otry {
20+
($e:expr) => {
21+
match $e {
22+
Some(e) => e,
23+
None => return None,
24+
}
25+
};
26+
}
27+
let rustc = otry!(env::var_os("RUSTC"));
28+
let output = otry!(Command::new(rustc).arg("--version").output().ok());
29+
let version = otry!(str::from_utf8(&output.stdout).ok());
30+
let mut pieces = version.split('.');
31+
if pieces.next() != Some("rustc 1") {
32+
return None;
33+
}
34+
otry!(pieces.next()).parse().ok()
35+
}

0 commit comments

Comments
 (0)