This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.rs
50 lines (43 loc) · 1.7 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
extern crate bindgen;
extern crate cbindgen;
use std::env;
fn main() {
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo:rustc-link-search={}/deps/root/lib", project_dir); // the "-L" flag
if env::var("AG2PC").is_ok() {
println!("cargo:rustc-link-lib=tokenm-utils"); // the "-l" flag
println!("cargo:rustc-link-lib=test-e2e"); // the "-l" flag
} else {
println!("cargo:rustc-link-lib=token-utils"); // the "-l" flag
}
// Create bindings
let header_file: &str;
if env::var("AG2PC").is_ok() {
header_file = "deps/root/include/update-state/ag2pc/tokens.h";
} else {
header_file = "deps/root/include/update-state/tokens.h";
}
let path_to_header_file = format!("{}/{}", project_dir, header_file);
//println!("token header file path: {}", path_to_header_file);
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header(path_to_header_file)
.clang_arg("-x")
.clang_arg("c++")
.clang_arg("-Ideps/root/include")
.trust_clang_mangling(false)
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
bindings
.write_to_file("src/bindings.rs")
.expect("Couldn't write bindings!");
// TODO: Create build for libtoken-utils here
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cbindgen::generate(crate_dir)
.expect("Unable to generate bindings")
.write_to_file("include/bindings.h");
}