-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
69 lines (59 loc) · 1.98 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
extern crate bindgen;
extern crate cmake;
use cmake::Config;
use std::env;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
fn main() {
println!("cargo:rustc-link-lib=ddsc");
println!("cargo:rustc-link-lib=cdds-util");
// OpenSSL libraries
if cfg!(target_os = "linux") {
println!("cargo:rustc-link-lib=crypto");
println!("cargo:rustc-link-lib=ssl");
}
if !Path::new("src/cyclonedds/.git").exists() {
let _ = Command::new("git")
.args(&["submodule", "update", "--init", "src/cyclonedds"])
.status();
}
if !Path::new("src/cdds-util/.git").exists() {
let _ = Command::new("git")
.args(&["submodule", "update", "--init", "src/cdds-util"])
.status();
}
let cyclonedds_dst = Config::new("src/cyclonedds")
.define("BUILD_IDLC", "OFF")
.define("BUILD_SHARED_LIBS", "OFF")
.define("BUILD_TESTING", "OFF")
.build();
let cdds_util_dst = Config::new("src/cdds-util")
.define(
"CMAKE_C_FLAGS",
format!("-I{}/include", cyclonedds_dst.display()),
)
.define("BUILD_SHARED_LIBS", "OFF")
.define("BUILD_CDDS_UTIL_EXAMPLES", "OFF")
.build();
println!(
"cargo:rustc-link-search=native={}/lib",
cyclonedds_dst.display()
);
println!(
"cargo:rustc-link-search=native={}/lib",
cdds_util_dst.display()
);
println!("cargo:rustc-link-lib=static=cdds-util");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.generate_comments(false)
.clang_arg(format!("-I{}/include", cyclonedds_dst.display()))
.clang_arg(format!("-I{}/include", cdds_util_dst.display()))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}