diff --git a/.gitignore b/.gitignore index 451814e44..ed070c9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ rln package-lock.json node_modules/ /.update.timestamp + +libwaku diff --git a/waku/v2/node/libwaku/README.md b/waku/v2/node/libwaku/README.md new file mode 100644 index 000000000..47a4ca50d --- /dev/null +++ b/waku/v2/node/libwaku/README.md @@ -0,0 +1,12 @@ +# libwaku + +Exposes a C API that can be used by other environments other than C. + +## Running + +Make sure you run `$PROJECTDIR/env.sh bash` first. Then: + +``` +./build.sh +./libwaku +``` diff --git a/waku/v2/node/libwaku/libwaku.c b/waku/v2/node/libwaku/libwaku.c new file mode 100644 index 000000000..cc126e183 --- /dev/null +++ b/waku/v2/node/libwaku/libwaku.c @@ -0,0 +1,12 @@ +#include +#include + +#include "libwaku.h" + +int main(int argc, char* argv[]) { + char* string; + NimMain(); + //echo(); + string = info("hello there"); + printf("Info: %s", string); +} diff --git a/waku/v2/node/libwaku/libwaku.h b/waku/v2/node/libwaku/libwaku.h new file mode 100644 index 000000000..f8c722481 --- /dev/null +++ b/waku/v2/node/libwaku/libwaku.h @@ -0,0 +1,9 @@ +#include +#include + +// Initialize Nim +void NimMain(); + +char* info(const char* wakuNode); + +void echo(); diff --git a/waku/v2/node/libwaku/libwaku.nim b/waku/v2/node/libwaku/libwaku.nim new file mode 100644 index 000000000..fc2d967f2 --- /dev/null +++ b/waku/v2/node/libwaku/libwaku.nim @@ -0,0 +1,36 @@ +# libwaku +# +# Exposes a C API that can be used by other environment than C. + +# TODO Start a node +# TODO Mock info call +# TODO Write header file +# TODO Write example C code file +# TODO Wrap info call +# TODO Init a node + +# proc info*(node: WakuNode): WakuInfo = +proc info(foo: cstring): cstring {.exportc.} = + echo "info about node" + echo foo + return foo + +proc echo() {.exportc.} = + echo "echo" + +# TODO Here at the moment, start the node +# Then do info call +# WIP +#proc main() {.async.} = +# let +# rng = crypto.newRng() +# conf = WakuNodeConf.load() +# (extIp, extTcpPort, extUdpPort) = setupNat(conf.nat, clientId, +# Port(uint16(conf.tcpPort) + conf.portsShift), +# Port(uint16(conf.udpPort) + conf.portsShift)) +# node = WakuNode.init(conf.nodeKey, conf.listenAddress, +# Port(uint16(conf.tcpPort) + conf.portsShift), extIp, extTcpPort) +# +# await node.start() +# +#main() diff --git a/waku/v2/node/libwaku/nim.cfg b/waku/v2/node/libwaku/nim.cfg new file mode 100644 index 000000000..29a2312bc --- /dev/null +++ b/waku/v2/node/libwaku/nim.cfg @@ -0,0 +1,5 @@ +-app:staticlib +o:"libwaku.a" +noMain +header +-d:"chronicles_sinks=textlines"