forked from lelongg/clipper-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
66 lines (59 loc) · 2.26 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
use std::env;
fn main() {
println!("cargo:rerun-if-changed=clipper");
if cfg!(feature = "update-bindings") {
println!("cargo:rerun-if-changed=generated");
}
cc::Build::new()
.cpp(true)
.opt_level(3)
.file("clipper/clipper.cpp")
.file("clipper/wrapper.cpp")
.flag_if_supported("-std=c++14")
.compile("clipper");
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
match (target_os.as_str(), target_env.as_str()) {
("linux", _) | ("windows", "gnu") | ("android", _) => println!("cargo:rustc-link-lib=dylib=stdc++"),
("macos", _) | ("ios", _) => println!("cargo:rustc-link-lib=dylib=c++"),
("windows", "msvc") => {}
_ => unimplemented!(
"target_os: {}, target_env: {}",
target_os.as_str(),
target_env.as_str()
),
}
#[cfg(feature = "generate-bindings")]
{
let bindings = bindgen::Builder::default()
.header("clipper/wrapper.hpp")
.allowlist_type("Polygons")
.allowlist_type("ClipType")
.allowlist_type("JoinType")
.allowlist_type("EndType")
.allowlist_type("PolyType")
.allowlist_type("PolyFillType")
.allowlist_type("Vertice")
.allowlist_type("Path")
.allowlist_type("Polygon")
.allowlist_function("clean")
.allowlist_function("simplify")
.allowlist_function("execute")
.allowlist_function("offset")
.allowlist_function("offset_simplify_clean")
.allowlist_function("free_path")
.allowlist_function("free_polygon")
.allowlist_function("free_polygons")
.size_t_is_usize(true)
.generate()
.expect("unable to generate bindings");
let out_path = if cfg!(feature = "update-bindings") {
std::path::PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("generated")
} else {
std::path::PathBuf::from(env::var("OUT_DIR").unwrap())
};
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("couldn't write bindings!");
}
}