mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-07 16:33:08 +00:00
feat: use nwaku instead of go-waku
This commit is contained in:
parent
1ea96f80b2
commit
9750a329ab
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -1,3 +1,3 @@
|
|||||||
[submodule "waku-sys/vendor"]
|
[submodule "waku-sys/vendor"]
|
||||||
path = waku-sys/vendor
|
path = waku-sys/vendor
|
||||||
url = https://github.com/status-im/go-waku.git
|
url = https://github.com/waku-org/nwaku
|
||||||
|
|||||||
@ -1,86 +1,36 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::env::set_current_dir;
|
use std::env::set_current_dir;
|
||||||
use std::fs;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
fn get_go_bin() -> String {
|
fn build_nwaku_lib(project_dir: &Path) {
|
||||||
if cfg!(target_family = "unix") {
|
|
||||||
let output = String::from_utf8(
|
|
||||||
Command::new("/usr/bin/which")
|
|
||||||
.arg("go")
|
|
||||||
.output()
|
|
||||||
.map_err(|e| println!("cargo:warning=Couldn't find `which` command: {e}"))
|
|
||||||
.expect("`which` command not found")
|
|
||||||
.stdout,
|
|
||||||
)
|
|
||||||
.expect("which output couldnt be parsed");
|
|
||||||
|
|
||||||
if output.is_empty() {
|
|
||||||
println!("cargo:warning=Couldn't find go binary installed, please ensure that it is installed and/or withing the system paths");
|
|
||||||
panic!("Couldn't find `go` binary installed");
|
|
||||||
}
|
|
||||||
output.trim().to_string()
|
|
||||||
} else if cfg!(target_family = "windows") {
|
|
||||||
"go".into()
|
|
||||||
} else {
|
|
||||||
panic!("OS not supported!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_go_waku_lib(go_bin: &str, project_dir: &Path) {
|
|
||||||
// Build go-waku static lib
|
|
||||||
// build command taken from waku make file:
|
|
||||||
// https://github.com/status-im/go-waku/blob/eafbc4c01f94f3096c3201fb1e44f17f907b3068/Makefile#L115
|
|
||||||
let out_dir: PathBuf = env::var_os("OUT_DIR").unwrap().into();
|
|
||||||
let vendor_path = project_dir.join("vendor");
|
let vendor_path = project_dir.join("vendor");
|
||||||
|
|
||||||
set_current_dir(vendor_path).expect("Moving to vendor dir");
|
set_current_dir(vendor_path).expect("Moving to vendor dir");
|
||||||
|
|
||||||
let mut cmd = Command::new(go_bin);
|
let mut cmd = Command::new("make");
|
||||||
cmd.env("CGO_ENABLED", "1")
|
cmd.arg("libwaku").arg("STATIC=true");
|
||||||
.arg("build")
|
|
||||||
.arg("-buildmode=c-archive")
|
|
||||||
.arg("-tags=gowaku_no_rln")
|
|
||||||
.arg("-o")
|
|
||||||
.arg(out_dir.join("libgowaku.a"))
|
|
||||||
.arg("./library/c");
|
|
||||||
|
|
||||||
// Setting `GOCACHE=/tmp/` for crates.io job that builds documentation
|
|
||||||
// when a crate is being published or updated.
|
|
||||||
if std::env::var("DOCS_RS").is_ok() {
|
|
||||||
cmd.env("GOCACHE", "/tmp/");
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.status()
|
cmd.status()
|
||||||
.map_err(|e| println!("cargo:warning=go build failed due to: {e}"))
|
.map_err(|e| println!("cargo:warning=make build failed due to: {e}"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
set_current_dir(project_dir).expect("Going back to project dir");
|
set_current_dir(project_dir).expect("Going back to project dir");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn patch_gowaku_lib() {
|
fn generate_bindgen_code(project_dir: &Path) {
|
||||||
// Replacing cgo_utils.h as it is only needed when compiling go-waku bindings
|
let vendor_path = project_dir.join("vendor");
|
||||||
let lib_dir: PathBuf = env::var_os("OUT_DIR").unwrap().into();
|
let build_dir = vendor_path.join("build");
|
||||||
let file_path = lib_dir.join("libgowaku.h");
|
let header_path = vendor_path.join("library/libwaku.h");
|
||||||
let data = fs::read_to_string(&file_path).expect("Unable to read file");
|
|
||||||
let new_data = data.replace("#include <cgo_utils.h>", "");
|
|
||||||
fs::write(&file_path, new_data).expect("Unable to write file");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_bindgen_code() {
|
println!("cargo:rustc-link-search={}", build_dir.display());
|
||||||
let lib_dir: PathBuf = env::var_os("OUT_DIR").unwrap().into();
|
println!("cargo:rustc-link-lib=static=waku");
|
||||||
|
println!("cargo:rerun-if-changed={}", header_path.display());
|
||||||
println!("cargo:rustc-link-search={}", lib_dir.display());
|
|
||||||
println!("cargo:rustc-link-lib=static=gowaku");
|
|
||||||
println!("cargo:rerun-if-changed=libgowaku.h");
|
|
||||||
|
|
||||||
patch_gowaku_lib();
|
|
||||||
|
|
||||||
// Generate waku bindings with bindgen
|
// Generate waku bindings with bindgen
|
||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
// The input header we would like to generate
|
// The input header we would like to generate
|
||||||
// bindings for.
|
// bindings for.
|
||||||
.header(format!("{}/{}", lib_dir.display(), "libgowaku.h"))
|
.header(format!("{}", header_path.display()))
|
||||||
// Tell cargo to invalidate the built crate whenever any of the
|
// Tell cargo to invalidate the built crate whenever any of the
|
||||||
// included header files changed.
|
// included header files changed.
|
||||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||||
@ -98,10 +48,8 @@ fn generate_bindgen_code() {
|
|||||||
|
|
||||||
#[cfg(not(doc))]
|
#[cfg(not(doc))]
|
||||||
fn main() {
|
fn main() {
|
||||||
let go_bin = get_go_bin();
|
|
||||||
|
|
||||||
let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||||
|
|
||||||
build_go_waku_lib(&go_bin, &project_dir);
|
build_nwaku_lib(&project_dir);
|
||||||
generate_bindgen_code();
|
generate_bindgen_code(&project_dir);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit e340337d64622d22cb94a969255efe4e36637df0
|
Subproject commit b64b017060337dfc427c74c4688e55ca8165caef
|
||||||
Loading…
x
Reference in New Issue
Block a user