-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
59 lines (50 loc) · 1.85 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
/// Build libspiro binding for Rust.
extern crate bindgen;
extern crate cc;
extern crate dos2unix;
use std::env;
use std::path::PathBuf;
fn do_bindgen() {
// Based on `bindgen` manual.
let bindings = bindgen::Builder::default()
.header("wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.derive_partialeq(true)
.derive_debug(true)
.derive_copy(true)
.derive_default(true)
// This function doesn't exist! Struct must be created.
.blacklist_function("new_bezctx")
// Avoids silly warnings about case of types. They're from C...
.raw_line("#![allow(non_camel_case_types, non_snake_case)]")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from("src");
let out_file = out_path.join("lib.rs");
bindings
.write_to_file(out_file.clone())
.expect("Couldn't write bindings!");
// Windows sanity - use \n even on Windows.
dos2unix::Dos2Unix::convert(&out_file.into_os_string().into_string().unwrap(), false);
}
fn main() {
cc::Build::new()
// We aren't using libspiro's autotools build, so I wrote a generic spiro-config.h which
// will work on all the systems I care about.
.include(".") // for spiro-config.h
.file("libspiro/bezctx.c")
.file("libspiro/spiro.c")
.file("libspiro/spiroentrypoints.c")
.static_flag(true)
.shared_flag(true)
.static_crt(true)
.compile("libspiro.a");
println!("cargo:rerun-if-changed=wrapper.h");
// Link built library. "lib" and ".a" are added back by Cargo.
println!("cargo:rustc-link-lib=static=spiro");
if env::var("DO_BINDGEN").is_ok() {
do_bindgen();
}
}