-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbuild.rs
85 lines (73 loc) · 2.65 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use std::env;
use std::path::PathBuf;
fn main() {
check_arch();
cc::Build::new()
.file("src/bridge/bridge.cpp")
.cpp(true)
.warnings(false)
.flag("-std=c++11")
.compile("bridge");
add_search_path();
add_llvm_path();
println!("cargo:rustc-link-lib=xtptraderapi");
println!("cargo:rustc-link-lib=xtpquoteapi");
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=src/wrapper.hpp");
println!("cargo:rerun-if-changed=src/bridge/bridge.hpp");
println!("cargo:rerun-if-changed=src/bridge/bridge.cpp");
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("src/wrapper.hpp")
/* // Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks)) */
.ignore_methods()
.rustified_enum(".*")
.blacklist_item("XTP_SIDE_TYPE")
.blacklist_item("XTP_POSITION_EFFECT_TYPE")
.blacklist_item("TXTPTradeTypeType")
.blacklist_item("TXTPOrderTypeType")
.blacklist_function("TraderSpiStub_Rust.*")
.blacklist_function("QuoteSpiStub_Rust.*")
/* .default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: true,
}) */
// 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.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings.write_to_file(out_path.join("bindings.rs")).expect("Couldn't write bindings!");
}
#[cfg(not(target_os = "windows"))]
fn add_search_path() {
for path in std::env::var("LD_LIBRARY_PATH").unwrap_or_else(|_| "".to_string()).split(":") {
if path.trim().len() == 0 {
continue;
}
println!("cargo:rustc-link-search={}", path);
}
}
#[cfg(target_os = "windows")]
fn add_search_path() {
for path in std::env::var("PATH").unwrap_or_else(|_| "".to_string()).split(";") {
if path.trim().len() == 0 {
continue;
}
println!("cargo:rustc-link-search={}", path);
}
}
#[cfg(target_arch = "x86_64")]
fn check_arch() {}
#[cfg(target_arch = "x86")]
fn check_arch() {
unimplemented!("Not implemented for 32 bit system!");
}
fn add_llvm_path() {
if let Some(llvm_config_path) = option_env!("LLVM_CONFIG_PATH") {
println!("cargo:rustc-env=LLVM_CONFIG_PATH={}", llvm_config_path);
}
}