-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
51 lines (41 loc) · 1.63 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
use std::path::PathBuf;
use std::{env, fs};
fn main() {
let mut out_path = PathBuf::from(env::var("OUT_DIR").expect("No out dir found"));
let bindings = bindgen::Builder::default()
.clang_args(&["-x", "c++", "-std=c++11"])
.header("./include/sgfplib.h")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(&out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
out_path.pop();
out_path.pop();
out_path.pop();
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
if cfg!(target_os = "windows") {
let source_path = format!("{}/libs/windows", manifest_dir);
for entry in fs::read_dir(source_path).expect("Failed to read source directory") {
let entry = entry.expect("Failed to read directory entry");
let file_path = entry.path();
if file_path.is_file() {
// Construct the target file path.
let target_file_path = out_path.join(file_path.file_name().unwrap());
fs::copy(file_path, target_file_path).expect("Failed to copy file");
}
}
}
println!("cargo:rustc-link-lib=sgfplib");
if cfg!(target_os = "linux") {
println!("cargo:rustc-link-search=native={}/libs/linux", manifest_dir);
println!("cargo:rustc-link-lib=jpeg");
println!("cargo:rustc-link-lib=stdc++");
} else if cfg!(target_os = "windows") {
println!(
"cargo:rustc-link-search=native={}/libs/windows",
manifest_dir
);
println!("cargo:rustc-link-lib=sgfplib");
}
}