From d0aa388b3902294d3b812b083cf75ff6c9b362a0 Mon Sep 17 00:00:00 2001 From: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com> Date: Fri, 19 May 2023 08:20:12 +0200 Subject: [PATCH] Makefile, waku.nimble: allow the creation of dynamic library, libwaku.so (#1730) --- Makefile | 26 ++++++++++++++------------ waku.nimble | 16 ++++++++++------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 735ef771d..4dd3e32c2 100644 --- a/Makefile +++ b/Makefile @@ -283,25 +283,27 @@ docker-push: ################ ## C Bindings ## ################ -.PHONY: cbindings cwaku_example libwaku.a +.PHONY: cbindings cwaku_example libwaku -libwaku.a: | build deps - echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim libwaku $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims +STATIC ?= false -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 --opt:size --noMain --header -o:build/$@ library/cwakunode.nim +libwaku: | build deps + rm -f build/libwaku* +ifeq ($(STATIC), true) + echo -e $(BUILD_MSG) "build/$@.a" && \ + $(ENV_SCRIPT) nim libwakuStatic $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims +else + echo -e $(BUILD_MSG) "build/$@.so" && \ + $(ENV_SCRIPT) nim libwakuDynamic $(NIM_PARAMS) $(EXPERIMENTAL_PARAMS) waku.nims +endif -cbindings: | build libwaku.a - -cwaku_example: | build cbindings +cwaku_example: | build libwaku 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 \ + -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 \ diff --git a/waku.nimble b/waku.nimble index 27add8d6a..be9e64a28 100644 --- a/waku.nimble +++ b/waku.nimble @@ -34,17 +34,17 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") = extra_params &= " " & paramStr(i) exec "nim " & lang & " --out:build/" & name & " " & extra_params & " " & srcDir & name & ".nim" -proc buildLibrary(name: string, srcDir = "./", params = "", lang = "c", isStatic = true) = +proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "static") = if not dirExists "build": mkDir "build" # allow something like "nim nimbus --verbosity:0 --hints:off nimbus.nims" var extra_params = params for i in 2.. NIM_PARAMS="-d:chronicles_log_level=INFO" make test2` @@ -100,9 +100,13 @@ task chat2bridge, "Build chat2bridge": buildBinary name, "apps/chat2bridge/", "-d:chronicles_log_level=TRACE" ### C Bindings -task libwaku, "Build the cbindings waku node library": +task libwakuStatic, "Build the cbindings waku node library": let name = "libwaku" - buildLibrary name, "library/", "-d:chronicles_log_level=ERROR" + buildLibrary name, "library/", "-d:chronicles_log_level=ERROR", "static" + +task libwakuDynamic, "Build the cbindings waku node library": + let name = "libwaku" + buildLibrary name, "library/", "-d:chronicles_log_level=ERROR", "dynamic" ### Legacy: Whisper & Waku v1 tasks task testwhisper, "Build & run Whisper tests":