-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
53 lines (45 loc) · 1.61 KB
/
Copy pathbuild.rs
File metadata and controls
53 lines (45 loc) · 1.61 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
extern crate bindgen;
extern crate cmake;
use std::{env, path::PathBuf};
use cmake::Config;
fn main() {
println!("cargo:rerun-if-changed=wrapper.h");
let target = env::var("TARGET").unwrap();
let is_debug = env::var("DEBUG").unwrap() == "true";
// generate the bindings
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.allowlist_function("enet_.*")
.allowlist_type("_ENet_.*")
.generate()
.expect("failed to generate bindings.");
// write the generated bindings to ${OUT_DIR}/bindings.rs
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("could not write bindings");
// build ENet-CS to a static library
let built = Config::new("vendor/ENet-CSharp/Source/Native")
.define("ENET_STATIC", "1")
.build_target("enet_static")
.build();
// add the newly compiled static library to the library search path of rustc
if target.contains("windows") {
if is_debug {
println!(
"cargo:rustc-link-search=native={}/build/Debug",
built.display()
);
} else {
println!(
"cargo:rustc-link-search=native={}/build/Release",
built.display()
);
}
println!("cargo:rustc-link-lib=dylib=winmm");
} else {
println!("cargo:rustc-link-search=native={}/build", built.display());
}
println!("cargo:rustc-link-lib=static=enet_static");
}