This repository has been archived by the owner on Jun 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
85 lines (76 loc) · 2.74 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
76
77
78
79
80
81
82
83
84
85
extern crate bindgen;
use std::env;
use std::io::{Read, Write};
use std::path::PathBuf;
fn main() {
let mut args = vec!["-x", "c++", "-std=c++11"];
// Tell cargo to tell rustc to link the system bzip2
// shared library.
println!("cargo:rustc-link-lib=embree3");
if cfg!(target_os = "windows") {
println!("cargo:rustc-link-search=native=C:\\Program Files\\Intel\\Embree3 x64\\lib");
args.push("-IC:\\Program Files\\Intel\\Embree3 x64\\include");
}
// 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()
.clang_args(args.iter())
.enable_cxx_namespaces()
.whitelist_function("rtc.*")
.whitelist_type("RTC.*")
.whitelist_var("rtc.*")
.whitelist_var("RTC.*")
.rust_target(bindgen::RustTarget::Stable_1_25)
.header("wrapper.h")
.bitfield_enum("RTC.*Flags")
.rustified_enum("RTCDeviceProperty")
.rustified_enum("RTCError")
.rustified_enum("RTCBufferType")
.rustified_enum("RTCGeometryType")
.rustified_enum("RTCSubdivisionMode")
.rustified_enum("RTCFormat")
.rustified_enum("RTCBuildQuality")
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = env::var("OUT_DIR").unwrap();
let out_path = PathBuf::from(out_path);
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
println!(
"Generating output bindings: {:?}",
out_path.join("bindings.rs")
);
// Simplify bindgen output
let names = [
"RTC_FORMAT_",
"RTC_BUILD_QUALITY_",
"RTC_DEVICE_PROPERTY_",
"RTC_ERROR_",
"RTC_BUFFER_TYPE_",
"RTC_GEOMETRY_TYPE_",
"RTC_SUBDIVISION_MODE_",
"RTC_INTERSECT_CONTEXT_FLAG_",
"RTC_CURVE_FLAG_",
"RTC_SCENE_FLAG_",
"RTC_BUILD_FLAG_",
];
// Open and read the file entirely
let mut src = std::fs::File::open(out_path.join("bindings.rs"))
.expect("Impossible to reopen binding file");
let mut data = String::new();
src.read_to_string(&mut data)
.expect("Impossible to read the binding file");
drop(src); // Close the file early
// Do the replacement
for name in &names {
data = data.replace(name, "");
}
// Recreate the file and dump the processed contents to it
let mut dst = std::fs::File::create(out_path.join("bindings.rs"))
.expect("Impossible to rewrite the binding file");
dst.write(data.as_bytes())
.expect("Impossible to write the binding file");
}