Skip to content

Commit

Permalink
Merge branch 'lnsocket-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jb55 committed Aug 12, 2022
2 parents 3b6eb7e + b9ae7ce commit 93307d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ clean: fake
rm -rf $(BINS) config.h $(OBJS) $(ARM64_OBJS) $(X86_64_OBJS) $(WASM_OBJS) target

distclean: clean
rm -rf $(ARS) deps target
rm -rf $(ARS) liblnsocket.a deps target


.PHONY: fake
36 changes: 29 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate bindgen;

use std::env;
use std::path::PathBuf;
use std::process::Command;

#[derive(Debug)]
struct IgnoreMacros(String);
Expand All @@ -17,14 +18,36 @@ impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
}

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
let lib_path = PathBuf::from(env::current_dir().unwrap());
println!("cargo:rustc-link-search={}", lib_path.display());

// Tell cargo to tell rustc to link the shared library.
println!("cargo:rustc-link-lib=lnsocket");
println!("cargo:rustc-link-lib=secp256k1");
println!("cargo:rustc-link-lib=sodium");
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());

Expand All @@ -36,9 +59,8 @@ fn main() {
// bindings for.
.header("lnsocket.h")
.header("lnsocket_internal.h")
.clang_arg("-Ideps/secp256k1/include")
.clang_arg("-Ideps/libsodium/src/libsodium/include")
.header("deps/secp256k1/include/secp256k1.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.
Expand Down

0 comments on commit 93307d1

Please sign in to comment.