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

Commit 5bebaac

Browse files
author
bors-servo
committed
Auto merge of #49 - servo:source-tarball-rust, r=larsbergstrom
Fix build script when the rustc commit date is unknown. Hopefully fixes #44 (comment). <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/heapsize/49) <!-- Reviewable:end -->
2 parents 09e2d6d + 64f9d7c commit 5bebaac

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ license = "MPL-2.0"
77
repository = "https://github.com/servo/heapsize"
88
build = "build.rs"
99

10-
[build-dependencies]
11-
regex = "0.1"
12-
1310
[dependencies]
1411
kernel32-sys = "0.2.1"
1512

build.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
1-
extern crate regex;
2-
31
use std::env::var;
42
use std::process::Command;
53
use std::str;
64

75
fn main() {
8-
let version_line = Command::new(var("RUSTC").unwrap_or("rustc".into()))
6+
let verbose = Command::new(var("RUSTC").unwrap_or("rustc".into()))
97
.arg("--version")
8+
.arg("--verbose")
109
.output()
1110
.unwrap()
1211
.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())
16-
.unwrap();
12+
let verbose = str::from_utf8(&verbose).unwrap();
13+
let mut commit_date = None;
14+
let mut release = None;
15+
for line in verbose.lines() {
16+
let mut parts = line.split(':');
17+
match parts.next().unwrap().trim() {
18+
"commit-date" => commit_date = Some(parts.next().unwrap().trim()),
19+
"release" => release = Some(parts.next().unwrap().trim()),
20+
_ => {}
21+
}
22+
}
23+
let version = release.unwrap().split('-').next().unwrap();;
24+
let mut version_components = version.split('.').map(|s| s.parse::<u32>().unwrap());
1725
let version = (
18-
captures[1].parse::<u32>().unwrap(),
19-
captures[2].parse::<u32>().unwrap(),
20-
captures[3].parse::<u32>().unwrap(),
21-
&captures[4],
26+
version_components.next().unwrap(),
27+
version_components.next().unwrap(),
28+
version_components.next().unwrap(),
29+
// "unknown" sorts after "2016-02-14", which is what we want to defaut to unprefixed
30+
// https://github.com/servo/heapsize/pull/44#issuecomment-187935883
31+
commit_date.unwrap()
2232
);
33+
assert_eq!(version_components.next(), None);
2334
if version < (1, 8, 0, "2016-02-14") {
2435
println!("cargo:rustc-cfg=prefixed_jemalloc");
2536
}

0 commit comments

Comments
 (0)