/
build.rs
66 lines (61 loc) · 2.15 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
extern crate bindgen;
extern crate cmake;
use cmake::Config;
use std::env;
use std::path::PathBuf;
fn main() {
// tell cargo to build our taglib branch
let dst = Config::new("talamel")
.static_crt(true)
.very_verbose(true)
.define("CMAKE_C_FLAGS", "-fPIC -Wall -O3")
.define("CMAKE_CXX_FLAGS", "-fPIC -Wall -O3")
.build();
// tell cargo to look for it when trying to link
println!("cargo:rustc-link-search={}", dst.display());
// if cfg!(target_os = "windows") {
// println!(
// "cargo:rustc-link-search={}\\build\\taglib\\install\\lib",
// dst.display()
// );
// println!(
// "cargo:rustc-link-search={}\\build\\zlib\\install\\lib",
// dst.display()
// );
// } else {
println!(
"cargo:rustc-link-search={}/build/taglib/install/lib",
dst.display()
);
println!(
"cargo:rustc-link-search={}/build/zlib/install/lib",
dst.display()
);
// }
println!("cargo:rustc-link-lib=static=talamel");
println!("cargo:rustc-link-lib=static=tag_c");
println!("cargo:rustc-link-lib=static=tag");
if cfg!(target_os = "macos") {
println!("cargo:rustc-link-lib=static=z");
println!("cargo:rustc-link-lib=c++");
} else if cfg!(target_os = "windows") {
println!("cargo:rustc-link-lib=static=zlib");
} else {
println!("cargo:rustc-link-lib=static=z");
println!("cargo:rustc-link-lib=stdc++");
}
// create bindings for the static c library
let header = dst.join("talamel.h");
let bindings = bindgen::Builder::default()
// use the header from the dst, where cmake has writen the headers
.header(header.to_str().unwrap())
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}