Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 879ae75

Browse files
committed
Simplify rustc version parsing
1 parent bf7f697 commit 879ae75

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ repository = "https://github.com/servo/heapsize"
88
build = "build.rs"
99

1010
[build-dependencies]
11-
semver = "0.2"
12-
chrono = "0.2"
11+
regex = "0.1"
1312

1413
[features]
1514
unstable = []

build.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
1-
extern crate semver;
2-
extern crate chrono;
1+
extern crate regex;
32

43
use std::env::var;
54
use std::process::Command;
6-
use semver::Version;
7-
use chrono::NaiveDate;
5+
use std::str;
86

97
fn main() {
10-
let unprefixed_jemalloc_version: Version = "1.8.0-dev".parse().unwrap();
11-
let unprefixed_jemalloc_day: NaiveDate = "2016-02-16".parse().unwrap();
12-
13-
let rustc_version_string = Command::new(var("RUSTC").unwrap_or("rustc".into()))
14-
.arg("--version").output().ok()
15-
.and_then(|o| String::from_utf8(o.stdout).ok())
16-
.unwrap();
17-
let rustc_version: Version = rustc_version_string.split_whitespace()
18-
.skip(1).next()
19-
.and_then(|r| r.parse().ok())
8+
let version_line = Command::new(var("RUSTC").unwrap_or("rustc".into()))
9+
.arg("--version")
10+
.output()
11+
.unwrap()
12+
.stdout;
13+
let captures = regex::Regex::new(r"rustc (\d+)\.(\d+)\.(\d+).+(\d{4}-\d{2}-\d{2})\)")
14+
.unwrap()
15+
.captures(str::from_utf8(&version_line).unwrap())
2016
.unwrap();
21-
let rustc_day: NaiveDate = rustc_version_string.split_whitespace()
22-
.last()
23-
.and_then(|r| r[..r.len()-1].parse().ok())
24-
.unwrap();
25-
26-
if rustc_day < unprefixed_jemalloc_day
27-
|| rustc_version < unprefixed_jemalloc_version
28-
{
17+
let version = (
18+
captures[1].parse::<u32>().unwrap(),
19+
captures[2].parse::<u32>().unwrap(),
20+
captures[3].parse::<u32>().unwrap(),
21+
&captures[4],
22+
);
23+
if version < (1, 8, 0, "2016-02-14") {
2924
println!("cargo:rustc-cfg=prefixed_jemalloc");
3025
}
3126
}

0 commit comments

Comments
 (0)