-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
61 lines (54 loc) · 1.58 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
use pkg_config::Config;
use std::env;
use std::path::PathBuf;
fn main() {
let luau = Config::new().probe("luau").unwrap();
for link_path in luau.link_paths {
println!("cargo:rustc-link-search={}", link_path.display());
}
println!("cargo:rustc-link-search=luau/build");
println!("cargo:rustc-link-lib=Luau.Analysis");
println!("cargo:rustc-link-lib=Luau.Ast");
println!("cargo:rustc-link-lib=Luau.Config");
println!("cargo:rustc-link-lib=Luau.Compiler");
println!("cargo:rustc-link-lib=Luau.CodeGen");
println!("cargo:rustc-link-lib=Luau.VM");
let cxx_stdlib = if let Ok(cxx_stdlib) = env::var("CXX_STDLIB") {
match cxx_stdlib.as_str() {
"stdc++" | "libstdc++" => vec!["stdc++".to_string()],
"c++" | "libc++" => vec!["c++".to_string(), "c++abi".to_string()],
_ => vec![cxx_stdlib],
}
} else {
vec!["stdc++".to_string()]
};
for lib in &cxx_stdlib {
println!("cargo:rustc-link-lib={}", lib);
}
let mut args = vec![
"src/wrapper.h".to_string(),
"--use-core".to_string(),
"--no-layout-tests".to_string(),
"--".to_string(),
"-x".to_string(),
"c++".to_string(),
];
for include_path in luau.include_paths {
args.push("-I".to_string());
args.push(include_path.to_string_lossy().to_string());
}
for cxx_stdlib in &cxx_stdlib {
args.push("-l".to_string());
args.push(cxx_stdlib.clone());
}
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
std::fs::write(
out_path.join("bindings.rs"),
std::process::Command::new("bindgen")
.args(args)
.output()
.expect("Failed to execute bindgen")
.stdout,
)
.expect("Failed to write bindings");
}