-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.rs
79 lines (68 loc) · 2.42 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
extern crate bindgen;
extern crate cmake;
use cmake::Config;
use std::env;
use std::path::PathBuf;
fn main() {
let dst = Config::new("solidity")
.define("TESTS", "OFF")
.define("TOOLS", "OFF")
.define("USE_Z3", "OFF")
.define("USE_CVC4", "OFF")
.build();
for lib in vec!["solc", "solidity", "yul", "langutil", "evmasm", "devcore"] {
println!(
"cargo:rustc-link-search=native={}/build/lib{}",
dst.display(),
lib
);
println!("cargo:rustc-link-lib=static={}", lib);
}
println!("cargo:rustc-link-search=native={}/lib", dst.display());
// jsoncpp dependency
println!(
"cargo:rustc-link-search=native={}/build/deps/lib",
dst.display()
);
println!("cargo:rustc-link-lib=static=jsoncpp");
println!("cargo:rustc-link-search=/usr/lib/");
println!("cargo:rustc-link-lib=boost_system");
println!("cargo:rustc-link-lib=boost_filesystem");
println!("cargo:rustc-link-lib=boost_regex");
// We need to link against C++ std lib
if let Some(cpp_stdlib) = get_cpp_stdlib() {
println!("cargo:rustc-link-lib={}", cpp_stdlib);
}
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("solidity/libsolc/libsolc.h")
// 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!");
}
// See https://github.com/alexcrichton/gcc-rs/blob/88ac58e25/src/lib.rs#L1197
fn get_cpp_stdlib() -> Option<String> {
env::var("TARGET").ok().and_then(|target| {
if target.contains("msvc") {
None
} else if target.contains("darwin") {
Some("c++".to_string())
} else if target.contains("freebsd") {
Some("c++".to_string())
} else if target.contains("musl") {
Some("static=stdc++".to_string())
} else {
Some("stdc++".to_string())
}
})
}