Skip to content

Commit

Permalink
feat(cbindings): first commit - waku relay (#1632) (#1714)
Browse files Browse the repository at this point in the history
* feat(cbindings): first commit - waku relay (#1632)

* test_app.nim: fix compilation issue. App.init(..) -> App.new(..)

* Simplifying library name (libwaku) and standardizing function names (waku_*)

* Proper wrapper of the waku_node API and creation of the libwaku.a

* Rolling back changes that are not needed

* Rolling back changes that are out of the scope of this task

* wakunode.nim: Removing unnecessary import

* Aplying PR suggestions

* Renaming 'waku.h' -> 'libwaku.h'

* Use of 'isNil' instead of '== nil'

* libwaku.nim: explicitly setting waku_poll() as gcsafe
  • Loading branch information
Ivansete-status committed May 12, 2023
1 parent 2ec9809 commit 2defbd2
Show file tree
Hide file tree
Showing 16 changed files with 1,425 additions and 132 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ nimbus-build-system.paths
*.sqlite3
*.sqlite3-shm
*.sqlite3-wal

# Ignore autogenerated C-bingings compilation files
/examples/cbindings/libwaku.h
39 changes: 23 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,31 @@ docker-push:
docker push $(DOCKER_IMAGE_NAME)


##############
## Wrappers ##
##############
# TODO: Remove unused target
libwaku.so: | build deps deps2
################
## C Bindings ##
################
.PHONY: cbindings cwaku_example libwaku.a

libwaku.a: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim libwaku $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims

libwaku.so: | build deps
# TODO: pending to enhance this part. Kindly use the static approach.
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim c --app:lib --noMain --nimcache:nimcache/libwaku $(NIM_PARAMS) -o:build/$@.0 wrappers/libwaku.nim && \
rm -f build/$@ && \
ln -s $@.0 build/$@
$(ENV_SCRIPT) nim c --app:lib --opt:size --noMain --header -o:build/$@ library/cwakunode.nim

# libraries for dynamic linking of non-Nim objects
EXTRA_LIBS_DYNAMIC := -L"$(CURDIR)/build" -lwaku -lm
cbindings: | build libwaku.a

# TODO: Remove unused target
wrappers: | build deps librln libwaku.so
echo -e $(BUILD_MSG) "build/C_wrapper_example" && \
$(CC) wrappers/wrapper_example.c -Wl,-rpath,'$$ORIGIN' $(EXTRA_LIBS_DYNAMIC) -g -o build/C_wrapper_example
echo -e $(BUILD_MSG) "build/go_wrapper_example" && \
go build -ldflags "-linkmode external -extldflags '$(EXTRA_LIBS_DYNAMIC)'" -o build/go_wrapper_example wrappers/wrapper_example.go #wrappers/cfuncs.go
cwaku_example: | build cbindings
echo -e $(BUILD_MSG) "build/$@" && \
cp nimcache/release/libwaku/libwaku.h ./examples/cbindings/ && \
cc -o "build/$@" \
./examples/cbindings/waku_example.c \
-lwaku -Lbuild/ -pthread -ldl -lm \
-lminiupnpc -Lvendor/nim-nat-traversal/vendor/miniupnp/miniupnpc/build/ \
-lnatpmp -Lvendor/nim-nat-traversal/vendor/libnatpmp-upstream/ \
vendor/nim-libbacktrace/libbacktrace_wrapper.o \
vendor/nim-libbacktrace/install/usr/lib/libbacktrace.a

endif # "variables.mk" was not included
Loading

0 comments on commit 2defbd2

Please sign in to comment.