File: build.rs

package info (click to toggle)
rust-heapsize 0.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 124 kB
  • sloc: makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download
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
use std::env::var;
use std::process::Command;
use std::str;

fn main() {
    let verbose = Command::new(var("RUSTC").unwrap_or("rustc".into()))
        .arg("--version")
        .arg("--verbose")
        .output()
        .unwrap()
        .stdout;
    let verbose = str::from_utf8(&verbose).unwrap();
    let mut commit_date = None;
    let mut release = None;
    for line in verbose.lines() {
        let mut parts = line.split(':');
        match parts.next().unwrap().trim() {
            "commit-date" => commit_date = Some(parts.next().unwrap().trim()),
            "release" => release = Some(parts.next().unwrap().trim()),
            _ => {}
        }
    }
    let version = release.unwrap().split('-').next().unwrap();;
    let mut version_components = version.split('.').map(|s| s.parse::<u32>().unwrap());
    let version = (
        version_components.next().unwrap(),
        version_components.next().unwrap(),
        version_components.next().unwrap(),
        // "unknown" sorts after "2016-02-14", which is what we want to defaut to unprefixed
        // https://github.com/servo/heapsize/pull/44#issuecomment-187935883
        commit_date.unwrap()
    );
    assert_eq!(version_components.next(), None);
    if version < (1, 8, 0, "2016-02-14") {
        println!("cargo:rustc-cfg=prefixed_jemalloc");
    }
}