forked from srijs/rust-crc32fast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
a96048c
commit a8339e7
Showing
2 changed files
with
27 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |