Libwaku spike start (#510)

* libwaku init e2e

* basic cstring check

* wip
This commit is contained in:
Oskar Thorén 2021-04-28 19:13:34 +08:00 committed by GitHub
parent e2678d55ff
commit 0d5e14f83c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 0 deletions

2
.gitignore vendored
View File

@ -34,3 +34,5 @@ rln
package-lock.json
node_modules/
/.update.timestamp
libwaku

View File

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

4
waku/v2/node/libwaku/build.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
nim c --skipParentCfg libwaku.nim
gcc libwaku.c ./libwaku.a -lm -g -o libwaku

View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include <stddef.h>
#include "libwaku.h"
int main(int argc, char* argv[]) {
char* string;
NimMain();
//echo();
string = info("hello there");
printf("Info: %s", string);
}

View File

@ -0,0 +1,9 @@
#include <stdint.h>
#include <stddef.h>
// Initialize Nim
void NimMain();
char* info(const char* wakuNode);
void echo();

View File

@ -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()

View File

@ -0,0 +1,5 @@
-app:staticlib
o:"libwaku.a"
noMain
header
-d:"chronicles_sinks=textlines"