code review pt-1
This commit is contained in:
parent
bcf3f6bf29
commit
589dba2d27
|
@ -4,3 +4,5 @@ vendor/.nimble
|
|||
/bottles/
|
||||
/test_nim/build
|
||||
tmp
|
||||
src/libstatuslib-stamp
|
||||
settings.json
|
||||
|
|
8
Makefile
8
Makefile
|
@ -117,20 +117,20 @@ $(STATUSGO): | deps
|
|||
+ cd vendor/status-go && \
|
||||
$(MAKE) statusgo-shared-library $(HANDLE_OUTPUT)
|
||||
|
||||
LIBSTATUSLIB := build/$@.$(LIBSTATUS_EXT).0
|
||||
libstatuslib: | $(STATUSGO)
|
||||
LIBSTATUSLIB := build/libstatuslib.$(LIBSTATUS_EXT).0
|
||||
libstatuslib: | $(STATUSGO)
|
||||
echo -e $(BUILD_MSG) "$@" && \
|
||||
$(ENV_SCRIPT) nim c $(NIM_PARAMS) $(NIM_EXTRA_PARAMS) --passL:"-L$(STATUSGO_LIBDIR)" --passL:"-lstatus" -o:build/$@.$(LIBSTATUS_EXT).0 -d:ssl --app:lib --noMain --header --nimcache:nimcache/libstatuslib statuslib.nim && \
|
||||
rm -f build/$@.$(LIBSTATUS_EXT) && \
|
||||
ln -s $@.$(LIBSTATUS_EXT).0 build/$@.$(LIBSTATUS_EXT) && \
|
||||
cp nimcache/libstatuslib/*.h build/. && \
|
||||
cp nimcache/libstatuslib/statuslib.h build/statuslib.h.for-reference-only && \
|
||||
[[ $$? = 0 ]]
|
||||
|
||||
# libraries for dynamic linking of non-Nim objects
|
||||
EXTRA_LIBS_DYNAMIC := -L"$(CURDIR)/build" -lstatuslib -lm -L"$(STATUSGO_LIBDIR)" -lstatus
|
||||
build_ctest: | $(LIBSTATUSLIB) build deps
|
||||
echo -e $(BUILD_MSG) "build/ctest" && \
|
||||
$(CC) test/main.c -Wl,-rpath,'$$ORIGIN' -I./vendor/nimbus-build-system/vendor/Nim/lib $(EXTRA_LIBS_DYNAMIC) -g -o build/ctest
|
||||
$(CC) test/main.c -Wl,-rpath,'$$ORIGIN' -Iinclude/ $(EXTRA_LIBS_DYNAMIC) -g -o build/ctest
|
||||
|
||||
LD_LIBRARY_PATH_NIMBLE := $${LD_LIBRARY_PATH}
|
||||
ifneq ($(detected_OS),Windows)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef __statuslib__
|
||||
#define __statuslib__
|
||||
|
||||
void NimMain(void);
|
||||
|
||||
void helloWorld(void);
|
||||
|
||||
typedef struct Status Status;
|
||||
|
||||
Status* newStatusInstance(char* fleetConfig);
|
||||
|
||||
void freeStatusInstance(Status* instance);
|
||||
|
||||
void ensureDirectories(char* dataDir, char* tmpDir, char* logDir);
|
||||
|
||||
void initNode(Status* self, char* statusGoDir, char* keystoreDir);
|
||||
|
||||
#endif /* __statuslib__ */
|
|
@ -100,8 +100,13 @@ proc getBloomFilterBitsSet*(self: Status): int {.exportc, dynlib.} =
|
|||
# exported correctly
|
||||
|
||||
|
||||
proc newStatusInstance*(fleetConfig: cstring): Status {.exportc, dynlib.} =
|
||||
newStatusInstance($fleetConfig)
|
||||
proc newStatusInstance*(fleetConfig: cstring): Status {.exportc, cdecl, dynlib.} =
|
||||
result = newStatusInstance($fleetConfig)
|
||||
GC_ref(result)
|
||||
|
||||
proc freeStatusInstance*(instance: var Status) {.exportc, cdecl, dynlib.} =
|
||||
GC_unref(instance)
|
||||
instance = nil
|
||||
|
||||
proc initNode*(self: Status, statusGoDir, keystoreDir: cstring) {.exportc, dynlib.} =
|
||||
self.initNode($statusGoDir, $keystoreDir)
|
||||
|
@ -109,5 +114,5 @@ proc initNode*(self: Status, statusGoDir, keystoreDir: cstring) {.exportc, dynli
|
|||
proc saveStringSetting*(self: Status, setting: Setting, value: cstring) {.exportc, dynlib.} =
|
||||
self.saveSetting(setting, $value)
|
||||
|
||||
proc saveBoolSetting*(self: Status, setting: Setting, value: bool) {.exportc, dynlib.} =
|
||||
self.saveSetting(setting, value)
|
||||
proc saveBoolSetting*(self: Status, setting: Setting, value: cint) {.exportc, dynlib.} =
|
||||
self.saveSetting(setting, value.bool)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "../build/statuslib.h"
|
||||
#include "statuslib.h"
|
||||
|
||||
void NimMain();
|
||||
|
||||
|
@ -18,4 +18,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
initNode(statusObj, "./build/A", "./build/B");
|
||||
|
||||
freeStatusInstance(statusObj);
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
# https://github.com/github/gitignore/blob/master/CMake.gitignore
|
||||
# ==============================================================================
|
||||
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
|
||||
|
||||
# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore
|
||||
# ==============================================================================
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
|
@ -8,7 +8,7 @@ set(CMAKE_AUTOUIC ON)
|
|||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
include(ExternalProject)
|
||||
|
@ -30,6 +30,7 @@ find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED)
|
|||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED)
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
nimstatus.cpp
|
||||
main.cpp
|
||||
qml.qrc
|
||||
)
|
||||
|
@ -74,11 +75,6 @@ include_directories(${STATUSGO_LIB_DIR})
|
|||
|
||||
|
||||
|
||||
# Include nim headers
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../vendor/nimbus-build-system/vendor/Nim/lib)
|
||||
|
||||
|
||||
|
||||
# Begin: status-lib
|
||||
set(STATUSLIB_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
|
||||
set(STATUSLIB_LIB_DIR ${STATUSLIB_ROOT}/build)
|
||||
|
@ -97,8 +93,8 @@ ExternalProject_Get_Property(libstatuslib SOURCE_DIR)
|
|||
add_library(statuslib SHARED IMPORTED)
|
||||
set_property(TARGET statuslib PROPERTY IMPORTED_LOCATION ${STATUSLIB_LIB_DIR}/libstatuslib.so)
|
||||
add_dependencies(statuslib libstatuslib)
|
||||
include_directories(${STATUSLIB_LIB_DIR})
|
||||
message(STATUS "foo include dir: ${STATUSLIB_LIB_DIR}")
|
||||
include_directories(${STATUSLIB_ROOT}/include)
|
||||
|
||||
|
||||
|
||||
target_compile_definitions(test-qtapp
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include "nimstatus.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "statuslib.h" // TODO: is it possible to export directly to C++?
|
||||
#include "statuslib.h"
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -12,20 +13,19 @@ int main(int argc, char *argv[])
|
|||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
#endif
|
||||
|
||||
NimMain();
|
||||
helloWorld();
|
||||
NimMain(); // Should be called always to initialize nim runtime
|
||||
|
||||
std::string someDirName{"./test"};
|
||||
char *cstr = &someDirName[0];
|
||||
|
||||
ensureDirectories(cstr, cstr, cstr);
|
||||
helloWorld(); // Example invocation of a nim function
|
||||
|
||||
std::string fleetStr{"{\"fleets\":{\"eth.prod\":{\"boot\":{\"boot-01.ac-cn-hongkong-c.eth.prod\":\"enode://6e6554fb3034b211398fcd0f0082cbb6bd13619e1a7e76ba66e1809aaa0c5f1ac53c9ae79cf2fd4a7bacb10d12010899b370c75fed19b991d9c0cdd02891abad@47.75.99.169:443\"},\"mail\":{\"mail-01.ac-cn-hongkong-c.eth.prod\":\"enode://606ae04a71e5db868a722c77a21c8244ae38f1bd6e81687cc6cfe88a3063fa1c245692232f64f45bd5408fed5133eab8ed78049332b04f9c110eac7f71c1b429@47.75.247.214:443\"},\"rendezvous\":{\"boot-01.ac-cn-hongkong-c.eth.prod\":\"/ip4/47.75.99.169/tcp/30703/ethv4/16Uiu2HAmV8Hq9e3zm9TMVP4zrVHo3BjqW5D6bDVV6VQntQd687e4\"},\"whisper\":{\"node-01.ac-cn-hongkong-c.eth.prod\":\"enode://b957e51f41e4abab8382e1ea7229e88c6e18f34672694c6eae389eac22dab8655622bbd4a08192c321416b9becffaab11c8e2b7a5d0813b922aa128b82990dab@47.75.222.178:443\"}}},\"meta\":{\"hostname\":\"node-01.do-ams3.proxy.misc\",\"timestamp\":\"2021-09-09T00:00:14.760436\"}}"};
|
||||
char *cfleetStr = &fleetStr[0];
|
||||
auto someDirName = QString{"./test"}.toLocal8Bit().data();
|
||||
ensureDirectories(someDirName, someDirName, someDirName);
|
||||
|
||||
// TODO: figure out how to unmangle this type
|
||||
tyObject_StatuscolonObjectType___PzMt9bO9aFlTtVlqs6Od8kZA *statusObj = newStatusInstance(cfleetStr);
|
||||
initNode(statusObj, cstr, cstr);
|
||||
QString fleetStr{"{\"fleets\":{\"eth.prod\":{\"boot\":{\"boot-01.ac-cn-hongkong-c.eth.prod\":\"enode://6e6554fb3034b211398fcd0f0082cbb6bd13619e1a7e76ba66e1809aaa0c5f1ac53c9ae79cf2fd4a7bacb10d12010899b370c75fed19b991d9c0cdd02891abad@47.75.99.169:443\"},\"mail\":{\"mail-01.ac-cn-hongkong-c.eth.prod\":\"enode://606ae04a71e5db868a722c77a21c8244ae38f1bd6e81687cc6cfe88a3063fa1c245692232f64f45bd5408fed5133eab8ed78049332b04f9c110eac7f71c1b429@47.75.247.214:443\"},\"rendezvous\":{\"boot-01.ac-cn-hongkong-c.eth.prod\":\"/ip4/47.75.99.169/tcp/30703/ethv4/16Uiu2HAmV8Hq9e3zm9TMVP4zrVHo3BjqW5D6bDVV6VQntQd687e4\"},\"whisper\":{\"node-01.ac-cn-hongkong-c.eth.prod\":\"enode://b957e51f41e4abab8382e1ea7229e88c6e18f34672694c6eae389eac22dab8655622bbd4a08192c321416b9becffaab11c8e2b7a5d0813b922aa128b82990dab@47.75.222.178:443\"}}},\"meta\":{\"hostname\":\"node-01.do-ams3.proxy.misc\",\"timestamp\":\"2021-09-09T00:00:14.760436\"}}"};
|
||||
|
||||
NimStatus statusObj(fleetStr);
|
||||
|
||||
statusObj.initializeNode("./test", "./test");
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include "nimstatus.hpp"
|
||||
|
||||
NimStatus::NimStatus(const QString& fleet){
|
||||
_ptr = newStatusInstance(fleet.toLocal8Bit().data());
|
||||
}
|
||||
|
||||
NimStatus::~NimStatus(){
|
||||
freeStatusInstance(_ptr);
|
||||
_ptr = nullptr;
|
||||
}
|
||||
|
||||
void NimStatus::initializeNode(const QString& statusGoDir, const QString& keystoreDir){
|
||||
initNode(_ptr, statusGoDir.toLocal8Bit().data(), keystoreDir.toLocal8Bit().data());
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "statuslib.h"
|
||||
}
|
||||
|
||||
|
||||
class NimStatus {
|
||||
public:
|
||||
NimStatus(const QString& fleet);
|
||||
virtual ~NimStatus();
|
||||
void initializeNode(const QString& statusGoDir, const QString& keystoreDir);
|
||||
private:
|
||||
Status* _ptr;
|
||||
};
|
Loading…
Reference in New Issue