Skip to content

Commit

Permalink
Drop dependency on rustc_version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Dec 1, 2018
1 parent a96048c commit a8339e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ repository = "https://github.com/srijs/rust-crc32fast"
readme = "README.md"
keywords = ["checksum", "crc", "crc32", "simd", "fast"]

[build-dependencies]
rustc_version = "0.2"

[dev-dependencies]
bencher = "0.1"
quickcheck = { version = "0.6", default-features = false }
Expand Down
30 changes: 27 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
extern crate rustc_version;
use std::env;
use std::process::Command;
use std::str;

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

let version = rustc_version::version().unwrap();
let minor = match rustc_minor_version() {
Some(n) => n,
None => return,
};

if version >= (1, 27, 0).into() {
if minor >= 27 {
println!("cargo:rustc-cfg=crc32fast_stdarchx86");
}
}

fn rustc_minor_version() -> Option<u32> {
macro_rules! otry {
($e:expr) => {
match $e {
Some(e) => e,
None => return None,
}
};
}
let rustc = otry!(env::var_os("RUSTC"));
let output = otry!(Command::new(rustc).arg("--version").output().ok());
let version = otry!(str::from_utf8(&output.stdout).ok());
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
otry!(pieces.next()).parse().ok()
}

0 comments on commit a8339e7

Please sign in to comment.