-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
48 lines (41 loc) · 1.69 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
use std::env;
use std::path::PathBuf;
// FIXME: get cross compatible with win/linux
/// Utility which sanitizes the comments
/// generated by bindgen so they aren't
/// mistakenly interpreted as tests:
/// https://github.com/rust-lang/rust-bindgen/issues/1313#issuecomment-1324102150
#[derive(Debug)]
struct CommentSanitizer;
impl bindgen::callbacks::ParseCallbacks for CommentSanitizer {
fn process_comment(&self, comment: &str) -> Option<String> {
Some(format!("````ignore\n{}\n````", comment))
}
}
fn main() {
// Ask Cargo to link the library.
let lib_path = format!("{}\\vendor\\winlibvicon", env!("CARGO_MANIFEST_DIR"));
println!("cargo:rustc-link-search=native={}", lib_path);
println!("cargo:rustc-link-lib=ViconDataStreamSDK_C");
// println!("cargo:rustc-link-search=native=vendor//winlibvicon");
// println!("cargo:rustc-link-lib=ViconDataStreamSDK_C");
// Ask Cargo to invalidate the build cache
// when the headers change.
println!("cargo:rerun-if-changed=vendor//winlibvicon//CClient.h");
// Generate C bindings.
let bindings = bindgen::Builder::default()
// Generate bindings for the header.
// .header("vendor/libvicon/CClient.h")
.header("vendor///winlibvicon///CClient.h")
// Clean generated comments so they aren't
// interpreted as tests.
.parse_callbacks(Box::new(CommentSanitizer))
// Generate bindings.
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("libvicon.rs"))
.expect("Couldn't write bindings!");
}