-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
72 lines (61 loc) · 2.14 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
use std::env;
use std::path::Path;
use std::process::Command;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let num_jobs = env::var("NUM_JOBS").unwrap();
let c_src_path = Path::new("ksw2");
Command::new("cp")
.current_dir(&c_src_path)
.arg("Makefile")
.arg("Makefile.old")
.output()
.expect("Failed to backup ksw2 makefile.");
// modify makefile to compile with -fPIC, required for rust
Command::new("sed")
.current_dir(&c_src_path)
.arg("-i")
.arg("s/-g -Wall -Wextra -Wc++-compat -O2/ -g -Wall -Wextra -Wc++-compat -O2 -fPIC/g")
.arg("Makefile")
.output()
.expect("Failed to modify ksw2 makefile.");
// build the library
Command::new("make")
.arg(format!("-j{}", num_jobs))
.current_dir(&c_src_path)
.output()
.expect("Failed to build ksw2.");
//println!("ls {:?}",String::from_utf8(Command::new("ls").current_dir(&c_src_path).output().unwrap().stdout));
let files = "cli.o kalloc.o ksw2_gg.o ksw2_gg2.o ksw2_gg2_sse.o ksw2_extz.o ksw2_extz2_sse.o ksw2_extd.o ksw2_extd2_sse.o ksw2_extf2_sse.o ksw2_exts2_sse.o";
for file in files.split(" ")
{
Command::new("cp")
.arg(file)
.arg(&out_dir)
.current_dir(&c_src_path)
.output()
.expect("Failed to copy ksw2 object files.");
}
// package all .o files into a static library
Command::new("sh")
.arg("-c")
.arg("ar rcs libksw2.a *.o")
.current_dir(&out_dir)
.output()
.unwrap();
// clean up the temporary build files
Command::new("make")
.current_dir(&c_src_path)
.arg("clean")
.output()
.expect("Failed to clean up ksw2 build files.");
Command::new("mv")
.current_dir(&c_src_path)
.arg("Makefile.old")
.arg("Makefile")
.output()
.expect("Failed to restore ksw2 makefile.");
// let cargo know that it can find the file in the out directory
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=ksw2");
}