-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.rs
75 lines (64 loc) · 2.47 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
extern crate bindgen;
use std::env;
use std::path::PathBuf;
use std::process::Command;
#[derive(Debug)]
struct IgnoreMacros(String);
impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
if name == self.0 {
bindgen::callbacks::MacroParsingBehavior::Ignore
} else {
bindgen::callbacks::MacroParsingBehavior::Default
}
}
}
fn main() {
// fetch deps
std::process::Command::new("git")
.args([
"submodule",
"update",
"--init",
"--depth 1",
"--recommend-shallow",
])
.output()
.expect("Failed to fetch git submodules!");
// Build the library
Command::new("make").status()
.expect("Failed to build library");
// Copy library
let lib_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let input_path = lib_path.join("lnsocket.a");
let output_path = lib_path.join("liblnsocket.a");
let res = std::fs::copy(input_path, output_path);
println!("cargo:warning={:#?}",res);
// Tell cargo to look for shared libraries in the specified directory
println!("cargo:rustc-link-search={}", lib_path.display());
// Tell cargo to tell rustc to link the shared library.
println!("cargo:rustc-link-lib=static=lnsocket");
println!("cargo:rustc-link-lib=static=secp256k1");
println!("cargo:rustc-link-lib=static=sodium");
let ignored_macros = IgnoreMacros("IPPORT_RESERVED".to_string());
// 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("lnsocket.h")
.header("lnsocket_internal.h")
.clang_arg(format!("-I{}", lib_path.join("deps/secp256k1/include").display()))
.clang_arg(format!("-I{}", lib_path.join("deps/libsodium/src/libsodium/include").display()))
.parse_callbacks(Box::new(ignored_macros))
.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("./rust/bindings.rs")
.expect("Couldn't write bindings!");
}