-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
33 lines (26 loc) · 1.06 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
extern crate bindgen;
use std::env;
use std::path::{PathBuf, Path};
use std::process::Command;
fn main() {
println!("cargo:rustc-link-lib=kcp");
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let fulldir = Path::new(&dir).join("kcp");
Command::new("gcc").args(&["-c" , "ikcp.c", "-o" , "libkcp.o"])
.current_dir(fulldir.clone())
.status().unwrap();
Command::new("ar").args(&["rcs", "-o", "libkcp.a", "libkcp.o"])
.current_dir(fulldir.clone())
.status().unwrap();
println!("cargo:rustc-link-search=native={}", fulldir.display());
println!("cargo:rerun-if-changed=wrapper.h");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.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!");
}