-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
56 lines (50 loc) · 2 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
use std::{env, path::PathBuf};
fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let lib_dir = PathBuf::from(&manifest_dir).join("lib");
let wrapper_path = PathBuf::from(&lib_dir).join("wrapper.h");
println!("cargo:rustc-link-lib=embree4");
println!("cargo:rerun-if-changed={}", wrapper_path.display());
let bindings = bindgen::Builder::default()
.header(format!("{}", wrapper_path.display()))
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.allowlist_function("rtc.*")
.allowlist_type("RTC.*")
.allowlist_var("RTC.*")
.rustified_enum("RTCFormat")
.rustified_enum("RTCBuildQuality")
.rustified_enum("RTCDeviceProperty")
.rustified_enum("RTCError")
.rustified_enum("RTCBufferType")
.rustified_enum("RTCGeometryType")
.rustified_enum("RTCSubdivisionMode")
.bitfield_enum("RTC.*Flags")
.blocklist_type("RTCPointQueryN")
.generate()
.expect("Unable to generate bindings");
let bindings_source = bindings
.to_string()
.replace("RTC_FORMAT_", "")
.replace("RTC_BUILD_QUALITY_", "")
.replace("RTC_RAY_QUERY_FLAG_", "")
.replace("RTC_DEVICE_PROPERTY_", "")
.replace("RTC_ERROR_", "")
.replace("RTC_BUFFER_TYPE_", "")
.replace("RTC_GEOMETRY_TYPE_", "")
.replace("RTC_SUBDIVISION_MODE_", "")
.replace("RTC_CURVE_FLAG_", "")
.replace("RTC_SCENE_FLAG_", "")
.replace("RTC_BUILD_FLAG_", "")
.replace("RTC_FORMAT_", "")
.replace(
"pub type size_t = ::std::os::raw::c_ulong",
"pub type size_t = usize",
)
.replace(
"pub type __ssize_t = ::std::os::raw::c_long",
"pub type __ssize_t = isize",
);
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_path = out_dir.join("bindings.rs");
std::fs::write(out_path, bindings_source).expect("Couldn't write bindings!");
}