Parity as a library (#8412)
* Parity as a library * Fix concerns * Allow using a null on_client_restart_cb * Fix more concerns * Test the C library in test.sh * Reduce CMake version to 3.5 * Move the clib test before cargo test * Add println in test
This commit is contained in:
committed by
Afri Schoedon
parent
28c731881f
commit
ac3de4c5fc
19
parity-clib-example/CMakeLists.txt
Normal file
19
parity-clib-example/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
include(ExternalProject)
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/../parity-clib")
|
||||
|
||||
add_executable(parity-example main.cpp)
|
||||
|
||||
ExternalProject_Add(
|
||||
libparity
|
||||
DOWNLOAD_COMMAND ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
COMMAND cargo build -p parity-clib # Note: use --release in a real project
|
||||
BINARY_DIR "${CMAKE_SOURCE_DIR}/../target"
|
||||
INSTALL_COMMAND ""
|
||||
LOG_BUILD ON)
|
||||
|
||||
add_dependencies(parity-example libparity)
|
||||
target_link_libraries(parity-example "${CMAKE_SOURCE_DIR}/../target/debug/libparity.so")
|
||||
28
parity-clib-example/main.cpp
Normal file
28
parity-clib-example/main.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <cstddef>
|
||||
#include <unistd.h>
|
||||
#include <parity.h>
|
||||
|
||||
void on_restart(void*, const char*, size_t) {}
|
||||
|
||||
int main() {
|
||||
ParityParams cfg = { 0 };
|
||||
cfg.on_client_restart_cb = on_restart;
|
||||
|
||||
const char* args[] = {"--light"};
|
||||
size_t str_lens[] = {7};
|
||||
if (parity_config_from_cli(args, str_lens, 1, &cfg.configuration) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void* parity;
|
||||
if (parity_start(&cfg, &parity) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
sleep(5);
|
||||
if (parity != NULL) {
|
||||
parity_destroy(parity);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user