refactor the C and Go wrapper build system
- moved "nimbus/api" to "wrappers" - renamed files - replaced the build scripts with Makefile targets - set the rpath relative to the test binary's location so it can look for libnimbus.so there at runtime - libnimbus.so.0 required on Linux, apparently - compiled all the Nimbus code with `--app:lib`, not just one file (this required skipping a proc in "nimbus/config.nim" because it uses an API that's unavailable in libraries) - removed static linking from the Go wrapper. It doesn't make sense at a global level, when using a shared Nimbus library. To selectively link static libraries, we should probably be specifying them as *.a. I did build a static libnimbus.a, as a test, but it insisted on dlopen-ing a shared version of itself which looked too ugly to continue.
This commit is contained in:
parent
ea06407e19
commit
1d7e14dc1b
|
@ -1,4 +1,4 @@
|
||||||
nimcache
|
/nimcache
|
||||||
|
|
||||||
# Executables shall be put in an ignored build/ directory
|
# Executables shall be put in an ignored build/ directory
|
||||||
/build
|
/build
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -49,7 +49,7 @@ TOOLS_DIRS := premix tests
|
||||||
# comma-separated values for the "clean" target
|
# comma-separated values for the "clean" target
|
||||||
TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
|
TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
|
||||||
|
|
||||||
.PHONY: all $(TOOLS) deps sanity-checks github-ssh build-nim update status ntags ctags nimbus testsuite test clean mrproper fetch-dlls test-libp2p-daemon nat-libs libminiupnpc.a libnatpmp.a go-checks
|
.PHONY: all $(TOOLS) deps sanity-checks github-ssh build-nim update status ntags ctags nimbus testsuite test clean mrproper fetch-dlls test-libp2p-daemon nat-libs libminiupnpc.a libnatpmp.a go-checks libnimbus.so wrappers
|
||||||
|
|
||||||
# default target, because it's the first one that doesn't start with '.'
|
# default target, because it's the first one that doesn't start with '.'
|
||||||
all: $(TOOLS) nimbus
|
all: $(TOOLS) nimbus
|
||||||
|
@ -128,7 +128,7 @@ test-reproducibility:
|
||||||
|
|
||||||
# usual cleaning
|
# usual cleaning
|
||||||
clean:
|
clean:
|
||||||
rm -rf build/{nimbus,$(TOOLS_CSV),all_tests,test_rpc,*.exe} vendor/go/bin \
|
rm -rf build/{nimbus,$(TOOLS_CSV),all_tests,test_rpc,*.exe,*.so,*.so.0,*_wrapper_test} vendor/go/bin \
|
||||||
$(NIMBLE_DIR) $(NIM_BINARY) $(NIM_DIR)/nimcache nimcache
|
$(NIMBLE_DIR) $(NIM_BINARY) $(NIM_DIR)/nimcache nimcache
|
||||||
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc clean $(HANDLE_OUTPUT)
|
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc clean $(HANDLE_OUTPUT)
|
||||||
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/libnatpmp clean $(HANDLE_OUTPUT)
|
+ $(MAKE) -C vendor/nim-nat-traversal/vendor/libnatpmp clean $(HANDLE_OUTPUT)
|
||||||
|
@ -197,6 +197,18 @@ test-libp2p-daemon: | vendor/go/bin/p2pd deps
|
||||||
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) tests/testdaemon.nim && \
|
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) tests/testdaemon.nim && \
|
||||||
rm -f tests/testdaemon
|
rm -f tests/testdaemon
|
||||||
|
|
||||||
|
libnimbus.so: | build deps nat-libs
|
||||||
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
|
$(ENV_SCRIPT) nim c --app:lib --noMain -d:"chronicles_sinks=textlines" --debuginfo --opt:speed --lineTrace:off $(NIM_PARAMS) -o:build/$@.0 wrappers/wrapper.nim && \
|
||||||
|
rm -f build/$@ && \
|
||||||
|
ln -s $@.0 build/$@
|
||||||
|
|
||||||
|
wrappers: | build deps nat-libs libnimbus.so go-checks
|
||||||
|
echo -e $(BUILD_MSG) "build/C_wrapper_test" && \
|
||||||
|
$(CC) wrappers/wrapper.c -Wl,-rpath,'$$ORIGIN' -Lbuild -lnimbus -lm -g -o build/C_wrapper_test
|
||||||
|
echo -e $(BUILD_MSG) "build/go_wrapper_test" && \
|
||||||
|
go build -o build/go_wrapper_test wrappers/wrapper.go
|
||||||
|
|
||||||
# https://bitbucket.org/nimcontrib/ntags/ - currently fails with "out of memory"
|
# https://bitbucket.org/nimcontrib/ntags/ - currently fails with "out of memory"
|
||||||
ntags:
|
ntags:
|
||||||
ntags -R .
|
ntags -R .
|
||||||
|
|
4
nim.cfg
4
nim.cfg
|
@ -17,3 +17,7 @@
|
||||||
--excessiveStackTrace:on
|
--excessiveStackTrace:on
|
||||||
-d:metrics # enable metric collection
|
-d:metrics # enable metric collection
|
||||||
|
|
||||||
|
# Required to make up for the compiler's inability to invalidate the C file
|
||||||
|
# (and object) cache on different command line arguments.
|
||||||
|
--forceBuild
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
status_api_test
|
|
||||||
libnimbus_api.so
|
|
|
@ -1,7 +0,0 @@
|
||||||
This folder contains an experimental C API for using parts of the nimbus
|
|
||||||
code from C/go in the status console client:
|
|
||||||
|
|
||||||
https://github.com/status-im/status-console-client/
|
|
||||||
|
|
||||||
It serves mainly as a proof-of-concept for now - there are several unresolved
|
|
||||||
issues surrounding threading, inter-language communication, callbacks etc.
|
|
|
@ -1,2 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
go build --ldflags '-extldflags "-static"' -o test main.go
|
|
|
@ -1,12 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
echo "[Cleaning up caches...]"
|
|
||||||
rm -rf nimcache/
|
|
||||||
rm -f libnimbus_api.so
|
|
||||||
|
|
||||||
# ../env.sh nim c --opt:speed --lineTrace:off --verbosity:2 status_api
|
|
||||||
# gcc status_api.c ./libnimbus_api.so -lm -o xx
|
|
||||||
|
|
||||||
# debug info
|
|
||||||
../../env.sh nim c --debuginfo --opt:speed --lineTrace:off --verbosity:2 status_api
|
|
||||||
gcc status_api.c ./libnimbus_api.so -lm -g -o status_api_test
|
|
|
@ -1,4 +0,0 @@
|
||||||
-app:lib
|
|
||||||
o:"libnimbus_api.so"
|
|
||||||
noMain
|
|
||||||
-d:"chronicles_sinks=textlines"
|
|
|
@ -752,7 +752,8 @@ LOGGING AND DEBUGGING OPTIONS:
|
||||||
$ord(defaultNetwork)
|
$ord(defaultNetwork)
|
||||||
]
|
]
|
||||||
|
|
||||||
proc processArguments*(msg: var string): ConfigStatus =
|
when declared(os.paramCount): # not available with `--app:lib`
|
||||||
|
proc processArguments*(msg: var string): ConfigStatus =
|
||||||
## Process command line argument and update `NimbusConfiguration`.
|
## Process command line argument and update `NimbusConfiguration`.
|
||||||
let config = getConfiguration()
|
let config = getConfiguration()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
This folder contains an experimental C wrapper for using parts of the Nimbus
|
||||||
|
code from C/Go in the Status console client:
|
||||||
|
|
||||||
|
https://github.com/status-im/status-console-client/
|
||||||
|
|
||||||
|
It serves mainly as a proof-of-concept for now - there are several unresolved
|
||||||
|
issues surrounding threading, inter-language communication, callbacks etc.
|
||||||
|
|
||||||
|
To build the wrappers and the test programs, run from the top level directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make wrappers
|
||||||
|
```
|
||||||
|
|
||||||
|
Now you can run the test programs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
build/C_wrapper_test
|
||||||
|
build/go_wrapper_test
|
||||||
|
```
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "status_api.h"
|
#include "wrapper.h"
|
||||||
|
|
||||||
void NimMain();
|
void NimMain();
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #cgo LDFLAGS: /home/oskarth/git/nimbus/nimbus/libnimbus_api.so -lm
|
// #cgo LDFLAGS: -Wl,-rpath,'$ORIGIN' -L${SRCDIR}/../build -lnimbus -lm
|
||||||
// #include "libnim.h"
|
// #include "wrapper.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// Arrange that main.main runs on main thread.
|
// Arrange that main.main runs on main thread.
|
|
@ -12,7 +12,7 @@ import
|
||||||
nimcrypto/[bcmode, hmac, rijndael, pbkdf2, sha2, sysrand, utils, keccak, hash],
|
nimcrypto/[bcmode, hmac, rijndael, pbkdf2, sha2, sysrand, utils, keccak, hash],
|
||||||
eth/[keys, rlp, p2p], eth/p2p/rlpx_protocols/[whisper_protocol],
|
eth/[keys, rlp, p2p], eth/p2p/rlpx_protocols/[whisper_protocol],
|
||||||
eth/p2p/[discovery, enode, peer_pool], chronicles,
|
eth/p2p/[discovery, enode, peer_pool], chronicles,
|
||||||
../config
|
../nimbus/config
|
||||||
|
|
||||||
type
|
type
|
||||||
CReceivedMessage* = object
|
CReceivedMessage* = object
|
Loading…
Reference in New Issue