Makefile, waku.nimble: allow the creation of dynamic library, libwaku.so (#1730)

This commit is contained in:
Ivan Folgueira Bande 2023-05-19 08:20:12 +02:00 committed by GitHub
parent ceb54b1821
commit d0aa388b39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 18 deletions

View File

@ -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 \

View File

@ -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..<paramCount():
extra_params &= " " & paramStr(i)
if isStatic:
exec "nim " & lang & " --out:build/" & name & ".a --app:staticlib --opt:size --noMain --header " & extra_params & " " & srcDir & name & ".nim"
if `type` == "static":
exec "nim c" & " --out:build/" & name & ".a --app:staticlib --opt:size --noMain --header " & extra_params & " " & srcDir & name & ".nim"
else:
exec "nim " & lang & " --out:build/" & name & ".a --app:lib --opt:size --noMain --header " & extra_params & " " & srcDir & name & ".nim"
exec "nim c" & " --out:build/" & name & ".so --app:lib --opt:size --noMain --header " & extra_params & " " & srcDir & name & ".nim"
proc test(name: string, params = "-d:chronicles_log_level=DEBUG", lang = "c") =
# XXX: When running `> 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":