mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-15 00:16:48 +00:00
deploy: be717ce5f3a72ff270e9ffe87add9356c8ec5a1e
This commit is contained in:
parent
3a703c7b47
commit
9db51e53cf
2
.gitignore
vendored
2
.gitignore
vendored
@ -34,5 +34,3 @@ rln
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
node_modules/
|
node_modules/
|
||||||
/.update.timestamp
|
/.update.timestamp
|
||||||
|
|
||||||
libwaku
|
|
||||||
|
16
Makefile
16
Makefile
@ -29,6 +29,8 @@ DOCKER_IMAGE_NIM_PARAMS ?= -d:chronicles_colors:none -d:insecure
|
|||||||
bridge \
|
bridge \
|
||||||
test \
|
test \
|
||||||
clean \
|
clean \
|
||||||
|
libwaku.so \
|
||||||
|
wrappers \
|
||||||
libbacktrace
|
libbacktrace
|
||||||
|
|
||||||
ifeq ($(NIM_PARAMS),)
|
ifeq ($(NIM_PARAMS),)
|
||||||
@ -185,3 +187,17 @@ ifneq ($(USE_LIBBACKTRACE), 0)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
endif # "variables.mk" was not included
|
endif # "variables.mk" was not included
|
||||||
|
|
||||||
|
libwaku.so: | build deps
|
||||||
|
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/$@
|
||||||
|
|
||||||
|
# libraries for dynamic linking of non-Nim objects
|
||||||
|
EXTRA_LIBS_DYNAMIC := -L"$(CURDIR)/build" -lwaku -lm
|
||||||
|
wrappers: | build deps 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
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# libtool - Provide generalized library-building support services.
|
# libtool - Provide generalized library-building support services.
|
||||||
# Generated automatically by config.status (libbacktrace) version-unused
|
# Generated automatically by config.status (libbacktrace) version-unused
|
||||||
# Libtool was configured on host fv-az190-125:
|
# Libtool was configured on host fv-az129-187:
|
||||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||||
#
|
#
|
||||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||||
|
9
wrappers/README.md
Normal file
9
wrappers/README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# libwaku
|
||||||
|
|
||||||
|
Exposes a C API that can be used by other environments other than C.
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
```
|
||||||
|
make wrappers
|
||||||
|
```
|
14
wrappers/libwaku.h
Normal file
14
wrappers/libwaku.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef __LIBWAKU_H__
|
||||||
|
#define __LIBWAKU_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
// Initialize Nim
|
||||||
|
void NimMain();
|
||||||
|
|
||||||
|
char* info(const char* wakuNode);
|
||||||
|
|
||||||
|
void echo();
|
||||||
|
|
||||||
|
#endif //__LIBWAKU_H__
|
38
wrappers/libwaku.nim
Normal file
38
wrappers/libwaku.nim
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# 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, dynlib.} =
|
||||||
|
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()
|
||||||
|
|
||||||
|
# When main done stuff
|
14
wrappers/wrapper_example.c
Normal file
14
wrappers/wrapper_example.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "libwaku.h"
|
||||||
|
|
||||||
|
void NimMain();
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
char* string;
|
||||||
|
NimMain();
|
||||||
|
//echo();
|
||||||
|
string = info("hello there");
|
||||||
|
printf("Info: %s", string);
|
||||||
|
}
|
35
wrappers/wrapper_example.go
Normal file
35
wrappers/wrapper_example.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// Passing "-lwaku" to the Go linker through "-extldflags" is not enough. We need it in here, for some reason.
|
||||||
|
#cgo LDFLAGS: -Wl,-rpath,'$ORIGIN' -L${SRCDIR}/../build -lwaku
|
||||||
|
#include "libwaku.h"
|
||||||
|
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// Arrange that main.main runs on main thread.
|
||||||
|
func init() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
}
|
||||||
|
|
||||||
|
func Start() {
|
||||||
|
C.NimMain()
|
||||||
|
|
||||||
|
messageC := C.CString("Calling info")
|
||||||
|
fmt.Println("Start nim-waku")
|
||||||
|
var str = C.info(messageC)
|
||||||
|
fmt.Println("Info", str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Hi main")
|
||||||
|
Start()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user