-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
64 lines (58 loc) · 2.51 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
62
63
64
extern crate bindgen;
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
// HAL
Command::new("mvn")
.arg("dependency:get")
.arg(format!("-Ddest={}", out_path.join("hal.zip").as_os_str().to_str().unwrap()))
.arg("-DremoteRepositories=http://first.wpi.edu/FRC/roborio/maven/release")
.arg("-DgroupId=edu.wpi.first.wpilib")
.arg("-DartifactId=hal")
.arg("-Dversion=2017.3.1")
.arg("-Dpackaging=zip")
.output()
.expect("Failed to download FRC HAL via Maven");
Command::new("unzip")
.arg(out_path.join("hal.zip").as_os_str().to_str().unwrap())
.arg("-d")
.arg(out_path.join("hal").as_os_str().to_str().unwrap())
.output()
.expect("Failed to unzip FRC HAL");
println!("cargo:rustc-link-search={}", out_path.join("hal/lib").as_os_str().to_str().unwrap());
// Athena runtime libraries
Command::new("mvn")
.arg("dependency:get")
.arg(format!("-Ddest={}", out_path.join("athena-runtime.zip").as_os_str().to_str().unwrap()))
.arg("-DremoteRepositories=http://first.wpi.edu/FRC/roborio/maven/release")
.arg("-DgroupId=edu.wpi.first.wpilib")
.arg("-DartifactId=athena-runtime")
.arg("-Dversion=2017.3.1")
.arg("-Dpackaging=zip")
.output()
.expect("Failed to download Athena Runtime via Maven");
Command::new("unzip")
.arg(out_path.join("athena-runtime.zip").as_os_str().to_str().unwrap())
.arg("-d")
.arg(out_path.join("athena-runtime").as_os_str().to_str().unwrap())
.output()
.expect("Failed to unzip Athena Runtime");
println!("cargo:rustc-link-search={}", out_path.join("athena-runtime/lib").as_os_str().to_str().unwrap());
println!("cargo:rustc-link-lib=nilibraries");
println!("cargo:rustc-link-lib=wpiutil");
println!("cargo:rustc-link-lib=HALAthena");
let bindings = bindgen::Builder::default()
.header("hal-wrapper.hpp")
.whitelisted_type("HAL_.*")
.whitelisted_function("HAL_.*")
.whitelisted_var("HAL_.*")
.trust_clang_mangling(false)
.clang_arg("-std=c++14")
.clang_arg(format!("-I{}", out_path.join("hal/include").as_os_str().to_str().unwrap()))
.generate()
.expect("Unable to generate bindings for FRC HAL");
bindings.write_to_file(out_path.join("hal-bindings.rs"))
.expect("Failed to write bindings to file");
}