-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
75 lines (62 loc) · 2.19 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
73
74
75
extern crate bindgen;
extern crate cc;
use std::env;
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let clips_core_dir = PathBuf::from("CLIPS/core");
let files =
std::fs::read_dir(&clips_core_dir)
.expect("CLIPS core dir not found")
.map(|entry| entry.expect("not a valid entry"))
.filter(|entry| {
!entry.file_type().expect("not a valid filetype").is_dir()
})
.map(|entry| PathBuf::from(entry.path()))
.filter(|path| match path.extension() {
None => false,
Some(extension) => extension == "c",
})
// suppress developer.c because it causes empty .o warning
.filter(|path| cfg!(feature = "developer") || !path.ends_with("developr.c"));
eprintln!("{:?}", files);
let mut build = cc::Build::new();
build
.files(files)
.include(&clips_core_dir)
// .warnings(false)
.out_dir(&out_dir)
// Exclude current CLIPS compile warnings
.flag("-Wno-unused-parameter")
.flag("-Wno-missing-field-initializers");
if cfg!(feature = "developer") {
build.define("DEVELOPER", "1");
}
build
.compile("clips");
let _res = std::fs::copy(PathBuf::from("wrapper.h"), &out_dir.join("wrapper.h"));
println!("cargo:rustc-link-lib=static=clips");
println!("cargo:rustc-link-search={}", &out_dir.join("CLIPS/core").display());
let out_path = out_dir.join("bindings.rs");
if !out_path.exists() {
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
// use the copy in out_dir
.header("CLIPS/core/clips.h")
.derive_debug(true)
.impl_debug(true)
.derive_default(true)
// 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.
bindings
.write_to_file(out_path)
.expect("Couldn't write bindings!");
}
}