forked from dekellum/hyperx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
59 lines (52 loc) · 1.55 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![cfg_attr(feature = "cargo-clippy", allow(clippy::all))]
use std::env;
use std::process::Command;
fn main() {
static PACKAGE: &'static str = "hyperx";
let msrv = vec![1, 46];
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
static M_V: &'static str = "minimum supported rust version (MSRV)";
let rustv = rustc_version();
if rustv < msrv {
panic!(
"{} v{} {} is {} > {} (this rustc)",
PACKAGE,
VERSION,
M_V,
join(&msrv),
join(&rustv)
);
}
}
fn join(ver: &Vec<u16>) -> String {
let mut out = String::new();
for v in ver {
if !out.is_empty() {
out.push('.');
}
out.push_str(&v.to_string());
}
out
}
// Parse `rustc --version` and return as vector of integers, or panic.
fn rustc_version() -> Vec<u16> {
let rustc = env::var("RUSTC").unwrap_or("rustc".to_owned());
let out = Command::new(rustc).arg("--version").output().unwrap();
let out = String::from_utf8(out.stdout).unwrap();
for l in out.lines() {
if l.starts_with("rustc ") {
let mut v = &l[6..];
if let Some(e) = v.find(" ") {
v = &v[..e];
}
let mut vp = v.split("-");
if let Some(v) = vp.next() {
let vs: Vec<u16> = v.split(".").filter_map(|vss| vss.parse().ok()).collect();
if !vs.is_empty() {
return vs;
}
}
}
}
panic!("rustc version not found")
}