-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.rs
48 lines (43 loc) · 1.76 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
use std::env;
use std::path::{Path, PathBuf};
fn main() {
let red4ext_dir = Path::new("deps/RED4ext.SDK");
let red4ext_include_dir = red4ext_dir.join("include");
let red4ext_target = cmake::Config::new(red4ext_dir).profile("Release").build();
println!(
"cargo:rustc-link-search=native={}",
red4ext_target.join("lib").display()
);
println!("cargo:rustc-link-lib=user32");
println!("cargo:rustc-link-lib=RED4ext.SDK");
let bindings = bindgen::Builder::default()
.clang_arg("-std=c++20")
.clang_arg(format!("-I{}", red4ext_include_dir.display()))
.header("deps/wrapper.hpp")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.default_enum_style(bindgen::EnumVariation::ModuleConsts)
.derive_default(true)
.enable_cxx_namespaces()
.wrap_static_fns(true)
.vtable_generation(true)
// std types get generated incorrectly for some reason, so they need to be opaque
.opaque_type("std::(vector|string|filesystem).*")
.allowlist_item("RED4ext::[^:]+")
.allowlist_item("RED4ext::(Detail|ent)::.+")
.allowlist_item("RED4ext::Memory::(Vault|IAllocator)")
.allowlist_item("versioning::.+")
// callback handlers generate incorrect Rust code
.blocklist_item("RED4ext::(Detail::)?CallbackHandler.*")
.generate_comments(false)
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
#[cfg(debug_assertions)]
println!(
"cargo:warning=Generated bindings: {}",
out_path.join("bindings.rs").display()
);
}