-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
43 lines (38 loc) · 1.55 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
use std::env;
use std::path::PathBuf;
static WEBOTS_LINUX_PATH: &str = "/usr/local/webots";
static WEBOTS_MACOS_PATH: &str = "/Applications/Webots.app";
static WEBOTS_WINDOWS_PATH: &str = "C:\\Program Files\\Webots";
fn main() {
let env_path = env::var("WEBOTS_PATH").ok();
let webots_path = if let Some(path) = env_path {
path
} else if cfg!(target_os = "linux") {
WEBOTS_LINUX_PATH.to_string()
} else if cfg!(target_os = "macos") {
WEBOTS_MACOS_PATH.to_string()
} else if cfg!(target_os = "windows") {
WEBOTS_WINDOWS_PATH.to_string()
} else {
panic!(
"Unrecognized OS. Please set WEBOTS_PATH so that we can find your Webots installation."
);
};
let lib_path = PathBuf::from(&webots_path).join("lib/controller");
let include_path = PathBuf::from(&webots_path).join("include/controller/c");
println!("cargo:rustc-link-search={}", lib_path.display());
println!("cargo:rustc-link-lib=Controller");
println!("cargo:rustc-env=LD_LIBRARY_PATH={}", lib_path.display());
println!("cargo:rerun-if-changed=wrapper.h");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.clang_args(vec!["-I", include_path.to_str().unwrap()])
.allowlist_function("wb.*")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from("src");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Unable to write bindings");
}