-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
36 lines (34 loc) · 1.03 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
use std::env;
use std::process::Command;
fn main() {
let mut make = Command::new("make");
make.arg("libvl53l1x_api.a");
// Support explicit CC and AR for cross compilation.
if let Ok(cc) = env::var("VL53L1X_CC") {
make.env("CC", cc);
}
if let Ok(ar) = env::var("VL53L1X_AR") {
make.env("AR", ar);
}
// Optionally enable 2.8 Volt mode.
if cfg!(feature = "i2c-2v8-mode") {
make.env("CFLAGS", "-DUSE_I2C_2V8");
}
// Makefile uses OUT_DIR as target.
run(&mut make);
let out_dir = env::var("OUT_DIR").expect("Need OUT_DIR specified by cargo.");
println!("{}", format!("cargo:rustc-link-search={}", out_dir));
println!("cargo:rustc-link-lib=static=vl53l1x_api");
}
fn run(command: &mut Command) {
match command.status() {
Ok(status) => {
if !status.success() {
panic!("Failed: `{:?}` ({})", command, status);
}
}
Err(error) => {
panic!("Failed: `{:?}` ({})", command, error);
}
}
}