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
extern crate bindgen;
use std::env;
use std::path::PathBuf;
use std::process::Command;
const H_FILE_NAME: &str = "/libpros.h";
const CC: &str = "gcc";
pub fn bindgen(){
println!("cargo:rerun-if-changed=include");
println!("Generating PROS bindings");
let out_dir =env::var("OUT_DIR").unwrap();
let out_h_loc = out_dir + H_FILE_NAME;
Command::new(CC)
.arg("-I").arg("./include/")
.arg("-E").arg("include/rust.h")
.arg("-o").arg(out_h_loc.clone())
.output()
.expect("failed to preprocess code");
let bindings = bindgen::Builder::default()
.header(out_h_loc.clone())
.ctypes_prefix("::libc")
.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!");
println!("Generated PROS bindings")
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}