-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
44 lines (36 loc) · 1.19 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
use std::env;
use std::fs::create_dir;
use std::path::Path;
use std::process::Command;
fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let cargo_dir = Path::new(manifest_dir.as_str());
let lib_dir = cargo_dir.join("lib");
let alloca_c = cargo_dir.join("src/alloca.c");
let alloca_o = lib_dir.join("alloca.o");
let liballoca_a = lib_dir.join("liballoca.a");
println!("cargo:rustc-link-search=native={}", lib_dir.display());
// No need to recompile alloca static lib every time. We could
// add a feature flag to do so if needed, though
if liballoca_a.is_file() {
return;
}
if !lib_dir.is_dir() {
create_dir(&lib_dir).unwrap();
}
let clang_output = Command::new("clang")
.arg("-c")
.arg(alloca_c)
.arg("-o")
.arg(&alloca_o)
.output()
.expect("Could not execute clang");
assert!(clang_output.status.success(), "{:?}", clang_output);
let ar_output = Command::new("ar")
.arg("-q")
.arg(liballoca_a)
.arg(alloca_o)
.output()
.expect("Could not execute ar");
assert!(ar_output.status.success(), "{:?}", ar_output);
}