File: build.rs

package info (click to toggle)
rust-tcmalloc-sys 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 92 kB
  • sloc: makefile: 4
file content (90 lines) | stat: -rw-r--r-- 2,907 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;

static TCMALLOC_REPO: &str = "https://github.com/gperftools/gperftools";
static TCMALLOC_TAG: &str = "gperftools-2.7";

// Platforms that _someone_ says works
static TESTED: &[&str] = &[
    "x86_64-unknown-linux-gnu",
];

fn main() {
    let target = env::var("TARGET").expect("TARGET was not set");
    let host = env::var("HOST").expect("HOST was not set");
    let num_jobs = env::var("NUM_JOBS").expect("NUM_JOBS was not set");
    let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR was not set"));
    let src_dir = env::current_dir().expect("failed to get current directory");
    let build_dir = out_dir.join("build");
    let gperftools_dir = out_dir.join("gperftools");

    println!("TARGET={}", target.clone());
    println!("HOST={}", host.clone());
    println!("NUM_JOBS={}", num_jobs.clone());
    println!("OUT_DIR={:?}", out_dir);
    println!("BUILD_DIR={:?}", build_dir);
    println!("SRC_DIR={:?}", src_dir);
    println!("GPERFTOOLS_DIR={:?}", gperftools_dir);

    if !TESTED.contains(&target.as_ref()) {
        println!("cargo:warning=tcmalloc-rs has not been verified to work on target {}", target);
        return;
    }
/*
    // Clone source to OUT_DIR
    if !out_dir.join("gperftools").exists() {
        assert!(out_dir.exists(), "OUT_DIR does not exist");
        let mut cmd = Command::new("git");
        cmd.current_dir(&out_dir)
            .args(&["clone", TCMALLOC_REPO, "--depth=1", "--branch", TCMALLOC_TAG]);
        run(&mut cmd);
    }

    fs::create_dir_all(&build_dir).unwrap();

    // Only run configure once
    if !build_dir.join("Makefile").exists() {
        let autogen = gperftools_dir.join("autogen.sh");
        let mut autogen_cmd = Command::new("sh");
        autogen_cmd.arg(autogen)
            .current_dir(&gperftools_dir);
        run(&mut autogen_cmd);

        let configure = gperftools_dir.join("configure");
        let mut configure_cmd = Command::new("sh");
        configure_cmd.arg(configure)
            .current_dir(&build_dir);
        run(&mut configure_cmd);
    }

    let mut make_cmd = Command::new("make");
    make_cmd.current_dir(&build_dir)
        .arg("srcroot=../gperftools/")
        .arg("-j")
        .arg(num_jobs);
    run(&mut make_cmd);

    println!("cargo:rustc-link-lib=static=tcmalloc");
    println!("cargo:rustc-link-search=native={}/.libs", build_dir.display());
    println!("cargo:rerun-if-changed=gperftools");
*/
}

fn run(cmd: &mut Command) {
    println!("running: {:?}", cmd);
    let status = match cmd.status() {
        Ok(status) => status,
        Err(e) => panic!("failed to execute command: {}", e),
    };
    if !status.success() {
        panic!(
            "command did not execute successfully: {:?}\n\
             expected success, got: {}",
            cmd, status
        );
    }
}