-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
56 lines (52 loc) · 2.04 KB
/
build.rs
File metadata and controls
56 lines (52 loc) · 2.04 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
56
extern crate cc;
use glob::glob;
fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-link-search={}", out_dir);
cc::Build::new()
.files(
glob("./vendor/mruby-compiler2/src/**/*.c")
.expect("cannot find c source")
.map(|x| x.unwrap()),
)
.files(
glob("./vendor/mruby-compiler2/lib/prism/src/**/*.c")
.expect("cannot find c source")
.map(|x| x.unwrap()),
)
.warnings(false)
.define("MRB_NO_PRESYM", "")
.define("MRB_INT64", "1")
.define("PRISM_XALLOCATOR", "")
.define("PRISM_BUILD_MINIMAL", "")
.define("PICORB_VM_MRUBYC", "")
.define("MRBC_ALLOC_LIBC", "")
.include("./vendor/include")
.include("./vendor/mruby-compiler2/include")
.include("./vendor/mruby-compiler2/lib/prism/include")
.flag("-fPIC")
.flag("-c")
.compile("mrubycompiler2");
println!("cargo:rustc-link-lib=mrubycompiler2");
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
let mut builder = bindgen::Builder::default()
.header("./vendor/mruby-compiler2/include/mruby_compiler.h")
.header("./vendor/mruby-compiler2/include/mrc_codedump.h")
.clang_arg("-I./vendor/mruby-compiler2/include")
.clang_arg("-I./vendor/mruby-compiler2/lib/prism/include")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
if target_arch == "wasm32" {
builder = builder.blocklist_type("max_align_t");
}
let bindings = builder.generate().expect("Unable to generate bindings");
let out = std::path::PathBuf::from(out_dir).join("bindings.rs");
bindings
.write_to_file(out)
.expect("Couldn't write bindings!");
}