This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
77 lines (64 loc) · 2.25 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std::env::var;
use std::process::Command;
use which::which;
use std::path::Path;
// I got a lot of inspiration from this example:
// https://github.com/AFLplusplus/LibAFL/blob/main/libafl_qemu/build.rs
const REPO_URL: &str = "https://gitlab.com/akihe/radamsa/";
const REPO_REV: &str = "ba1b18bbf8f89c9f727030845c7a4e859a0069d8";
fn build_dep_check(tools: &[&str]) {
for tool in tools {
which(tool).unwrap_or_else(|_| panic!("Build tool {} not found", tool));
}
}
fn main() {
if let Ok(_) = var("DOCS_RS") {
// no clone for building docs
return;
}
println!("cargo:rerun-if-changed=build.rs");
let target_os =
var("CARGO_CFG_TARGET_OS").expect("Could not find CARG_CFG_TARGET_OS");
if target_os != "linux" {
return;
}
let jobs = var("CARGO_BUILD_JOBS").unwrap_or(String::from("1"));
build_dep_check(&["make", "git"]);
let out = var("OUT_DIR").expect("Could not resolve OUT_DIR");
let out_path = Path::new(&out);
let radamsa_path = out_path.join("radamsa");
if !radamsa_path.is_dir(){
println!("radamsa not found. Cloning with git from {} @ {}", REPO_URL, REPO_REV);
Command::new("git")
.current_dir(&out_path)
.arg("clone")
.arg(REPO_URL)
.status()
.unwrap();
Command::new("git")
.current_dir(&out_path)
.arg("checkout")
.arg(REPO_REV)
.status()
.unwrap();
}
let out_lib = out_path.join("radamsa/lib/libradamsa.a");
if !out_lib.is_file(){
println!("building libradamsa.a");
Command::new("make")
.arg("-j")
.arg(format!("{}",&jobs))
.current_dir(&radamsa_path)
.output()
.expect("make in radamsa failed");
Command::new("make")
.arg("-j")
.arg(format!("{}", &jobs))
.arg("lib/libradamsa.a")
.current_dir(&radamsa_path)
.output()
.expect("make in radamsa failed");
}
println!("cargo:rustc-link-search={}/lib/", radamsa_path.display());
println!("cargo:rustc-link-lib=static=radamsa");
}