-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.rs
More file actions
55 lines (46 loc) · 1.82 KB
/
build.rs
File metadata and controls
55 lines (46 loc) · 1.82 KB
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
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 allowlist = include_str!("deps/allowlist.txt")
.split('\n')
.map(str::trim)
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.collect::<Vec<_>>();
let builder = 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)
.generate_comments(false)
.layout_tests(false)
// std types get generated incorrectly for some reason, so they need to be opaque
.opaque_type("std::(vector|string|filesystem).*")
.allowlist_item("versioning::.+");
let builder = allowlist
.iter()
.fold(builder, bindgen::Builder::allowlist_item);
let bindings = builder.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()
);
}