mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-01-02 14:03:10 +00:00
chore: use externally provided nwaku (#95)
* chore: use externally provided nwaku The fundamental idea is that the nwaku repository should be provided beforehand before building waku-go-bindings * fix: include libwaku with brackets --------- Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
This commit is contained in:
parent
6887455b91
commit
aa64c47d2b
3
.gitignore
vendored
3
.gitignore
vendored
@ -32,3 +32,6 @@ waku/store.sqlite3-wal
|
|||||||
waku/test_repeated_start_stop.log
|
waku/test_repeated_start_stop.log
|
||||||
|
|
||||||
third_party/
|
third_party/
|
||||||
|
|
||||||
|
# JetBrains IDEs
|
||||||
|
.idea/
|
||||||
75
README.md
75
README.md
@ -1,51 +1,52 @@
|
|||||||
# Waku Go Bindings
|
# Waku Go Bindings
|
||||||
|
|
||||||
This repository provides Go bindings for the Waku library, enabling seamless integration with Go projects.
|
Go bindings for the Waku library.
|
||||||
|
|
||||||
## Installation
|
## Install
|
||||||
|
|
||||||
To build the required dependencies for this module, the `make` command needs to be executed. If you are integrating this module into another project via `go get`, ensure that you navigate to the `waku-go-bindings` module directory and run `make`.
|
|
||||||
|
|
||||||
### Steps to Install
|
|
||||||
|
|
||||||
Follow these steps to install and set up the module:
|
|
||||||
|
|
||||||
1. Make sure your system has the [prerequisites](https://docs.waku.org/guides/nwaku/build-source#prerequisites) to run a local nwaku node
|
|
||||||
|
|
||||||
2. Retrieve the module using `go get`:
|
|
||||||
```
|
```
|
||||||
go get -u github.com/waku-org/waku-go-bindings
|
go get -u github.com/waku-org/waku-go-bindings
|
||||||
```
|
```
|
||||||
3. Navigate to the module's directory:
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
This repository doesn't download or build `nwaku`. You must provide `libwaku` and its headers.
|
||||||
|
|
||||||
|
To do so, you can:
|
||||||
|
- Build `libwaku` from https://github.com/waku-org/nwaku.
|
||||||
|
- Point `cgo` to the headers and compiled library when building your project.
|
||||||
|
|
||||||
|
Example environment setup (adjust paths to your nwaku checkout):
|
||||||
```
|
```
|
||||||
cd $(go list -m -f '{{.Dir}}' github.com/waku-org/waku-go-bindings)
|
export NWAKU_DIR=/path/to/nwaku
|
||||||
```
|
export CGO_CFLAGS="-I${NWAKU_DIR}/library"
|
||||||
4. Prepare third_party directory and clone nwaku
|
export CGO_LDFLAGS="-L${NWAKU_DIR}/build -lwaku -Wl,-rpath,${NWAKU_DIR}/build"
|
||||||
```
|
|
||||||
sudo mkdir third_party
|
|
||||||
sudo chown $USER third_party
|
|
||||||
```
|
|
||||||
5. Build the dependencies:
|
|
||||||
```
|
|
||||||
make -C waku
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Now the module is ready for use in your project.
|
Such setup would look like this in a `Makefile`:
|
||||||
|
```Makefile
|
||||||
|
NWAKU_DIR ?= /path/to/nwaku
|
||||||
|
CGO_CFLAGS = -I$(NWAKU_DIR)/library
|
||||||
|
CGO_LDFLAGS = -L$(NWAKU_DIR)/build -lwaku -Wl,-rpath,$(NWAKU_DIR)/build
|
||||||
|
|
||||||
### Note
|
build: ## Your project build command
|
||||||
|
go build ./...
|
||||||
In order to easily build the libwaku library on demand, it is recommended to add the following target in your project's Makefile:
|
|
||||||
|
|
||||||
```
|
|
||||||
LIBWAKU_DEP_PATH=$(shell go list -m -f '{{.Dir}}' github.com/waku-org/waku-go-bindings)
|
|
||||||
|
|
||||||
buildlib:
|
|
||||||
cd $(LIBWAKU_DEP_PATH) &&\
|
|
||||||
sudo mkdir -p third_party &&\
|
|
||||||
sudo chown $(USER) third_party &&\
|
|
||||||
make -C waku
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example Usage
|
For a reference integration, see how `status-go` wires `CGO_CFLAGS` and `CGO_LDFLAGS` in its build setup.
|
||||||
|
|
||||||
For an example on how to use this package, please take a look at our [example-go-bindings](https://github.com/gabrielmer/example-waku-go-bindings) repo
|
NOTE: If your project is itself used as a Go dependency, all its clients will have to follow the same nwaku setup.
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
When working on this repository itself, `nwaku` is included as a git submodule for convenience.
|
||||||
|
|
||||||
|
- Initialize and update the submodule, then build `libwaku`
|
||||||
|
```sh
|
||||||
|
git submodule update --init --recursive
|
||||||
|
make -C waku build-libwaku
|
||||||
|
```
|
||||||
|
- Build the project. Submodule paths are used by default to find `libwaku`.
|
||||||
|
```shell
|
||||||
|
make -C waku build
|
||||||
|
```
|
||||||
|
|||||||
@ -1,37 +1,25 @@
|
|||||||
# Makefile for Waku Go Bindings
|
# Makefile for Waku Go Bindings
|
||||||
|
|
||||||
# Directories
|
# Directories
|
||||||
THIRD_PARTY_DIR := ../third_party
|
THIRD_PARTY_DIR := $(shell pwd)/../third_party
|
||||||
NWAKU_REPO := https://github.com/waku-org/nwaku
|
NWAKU_REPO := https://github.com/waku-org/nwaku
|
||||||
NWAKU_DIR := $(THIRD_PARTY_DIR)/nwaku
|
NWAKU_DIR := $(THIRD_PARTY_DIR)/nwaku
|
||||||
|
|
||||||
.PHONY: all clean prepare build-libwaku build
|
.PHONY: all clean build-libwaku build
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
# Prepare third_party directory and clone nwaku
|
|
||||||
prepare:
|
|
||||||
@echo "Creating third_party directory..."
|
|
||||||
@mkdir -p $(THIRD_PARTY_DIR)
|
|
||||||
|
|
||||||
@echo "Cloning nwaku repository..."
|
|
||||||
@if [ ! -d "$(NWAKU_DIR)" ]; then \
|
|
||||||
cd $(THIRD_PARTY_DIR) && \
|
|
||||||
git clone $(NWAKU_REPO) && \
|
|
||||||
cd $(NWAKU_DIR) && \
|
|
||||||
make update; \
|
|
||||||
else \
|
|
||||||
echo "nwaku repository already exists."; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build libwaku
|
# Build libwaku
|
||||||
build-libwaku: prepare
|
build-libwaku:
|
||||||
@echo "Building libwaku..."
|
@echo "Building libwaku..."
|
||||||
@cd $(NWAKU_DIR) && make libwaku
|
@cd $(NWAKU_DIR) && make libwaku
|
||||||
|
|
||||||
# Build Waku Go Bindings
|
# Build Waku Go Bindings
|
||||||
build: build-libwaku
|
|
||||||
|
build: export CGO_CFLAGS = "-I${NWAKU_DIR}/library/"
|
||||||
|
build: export CGO_LDFLAGS = "-L${NWAKU_DIR}/build/ -lwaku -L${NWAKU_DIR} -Wl,-rpath,${NWAKU_DIR}/build/"
|
||||||
|
build:
|
||||||
@echo "Building Waku Go Bindings..."
|
@echo "Building Waku Go Bindings..."
|
||||||
go build ./...
|
go build ./...
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
package waku
|
package waku
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo LDFLAGS: -L../third_party/nwaku/build/ -lwaku
|
#include <libwaku.h>
|
||||||
#cgo LDFLAGS: -L../third_party/nwaku -Wl,-rpath,../third_party/nwaku/build/
|
|
||||||
|
|
||||||
#include "../third_party/nwaku/library/libwaku.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -348,6 +345,7 @@ import (
|
|||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
||||||
"github.com/waku-org/go-waku/waku/v2/utils"
|
"github.com/waku-org/go-waku/waku/v2/utils"
|
||||||
|
|
||||||
"github.com/waku-org/waku-go-bindings/waku/common"
|
"github.com/waku-org/waku-go-bindings/waku/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user