-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
88 lines (77 loc) · 2.38 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
86
87
88
use std::process::Command;
fn update_submodules() {
// call "git submodule update --init --recursive"
let git_update_result = Command::new("git")
.args(["submodule", "update", "--init", "--recursive", "-f"])
.output()
.expect("Failed to execute git");
println!("git submodule update --init --recursive: {}", String::from_utf8_lossy(&git_update_result.stderr));
}
fn build_linux() {
update_submodules();
// Build native bindings :: "bindgen lib/abieos/src/abieos.h -o src/bindings.rs"
bindgen::builder()
.header("lib/abieos/src/abieos.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings")
.write_to_file("src/bindings.rs")
.expect("Couldn't write bindings!");
// Build fpconv library
cc::Build::new()
.includes(&[
"lib/abieos/include",
])
.files(&[
"lib/abieos/include/eosio/fpconv.c",
])
.static_flag(true)
.out_dir("target/lib/fpconv")
.compile("fpconv");
// Build the native library with rust
cc::Build::new()
.cpp(true)
.includes(&[
"lib/abieos/external/rapidjson/include",
"lib/abieos/include"
])
.files(&[
"lib/abieos/src/abieos.cpp",
"lib/abieos/src/abi.cpp",
"lib/abieos/src/crypto.cpp"
])
.flag("-Wall")
.flag("-Wextra")
.flag("-Wno-unused-parameter")
.flag("-std=gnu++17")
.static_flag(true)
.cpp_link_stdlib("stdc++")
.out_dir("target/lib/abieos")
.compile("abieos");
println!("cargo:rustc-link-search=target/lib/build");
println!("cargo:rustc-link-lib=static=abieos");
println!("cargo:rustc-link-lib=stdc++");
}
fn main() {
if std::env::var("DOCS_RS").is_ok() {
// Skip building on docs.rs
return;
}
match sys_info::os_type() {
Ok(os_type) => {
match os_type.as_str() {
"Linux" => {
println!("OS Type: Linux");
build_linux();
}
_ => {
println!("OS Type: {}", os_type);
panic!("Unsupported OS");
}
}
}
Err(e) => {
println!("Error: {}", e);
}
}
}