mirror of
https://github.com/logos-blockchain/logos-blockchain-module.git
synced 2026-05-24 10:09:30 +00:00
Merge 2ba35fc8e11b16133d3db97acc90f55eb709eed8 into 20ae40b9463092e1ffe0805b3dd70f5829a489aa
This commit is contained in:
commit
d3a9455fe5
210
CMakeLists.txt
210
CMakeLists.txt
@ -1,203 +1,23 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.14)
|
||||||
project(logos-blockchain-module LANGUAGES CXX)
|
project(LogosBlockchainModulePlugin LANGUAGES CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
# ---- Options ----
|
if(DEFINED ENV{LOGOS_MODULE_BUILDER_ROOT})
|
||||||
set(LOGOS_CORE_ROOT "" CACHE PATH "Path to logos-core root directory.")
|
include($ENV{LOGOS_MODULE_BUILDER_ROOT}/cmake/LogosModule.cmake)
|
||||||
set(LOGOS_BLOCKCHAIN_ROOT "" CACHE PATH "Path to logos-blockchain source root.")
|
|
||||||
set(LOGOS_BLOCKCHAIN_LIB "" CACHE PATH "Path to prebuilt logos-blockchain lib.")
|
|
||||||
set(LOGOS_BLOCKCHAIN_INCLUDE "" CACHE PATH "Path to prebuilt logos-blockchain include.")
|
|
||||||
|
|
||||||
set(HAS_LOGOS_CORE_ROOT FALSE)
|
|
||||||
set(HAS_LOGOS_BLOCKCHAIN_ROOT FALSE)
|
|
||||||
set(HAS_LOGOS_BLOCKCHAIN_LIB FALSE)
|
|
||||||
set(HAS_LOGOS_BLOCKCHAIN_INCLUDE FALSE)
|
|
||||||
|
|
||||||
if (DEFINED LOGOS_CORE_ROOT AND NOT "${LOGOS_CORE_ROOT}" STREQUAL "")
|
|
||||||
set(HAS_LOGOS_CORE_ROOT TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (DEFINED LOGOS_BLOCKCHAIN_ROOT AND NOT "${LOGOS_BLOCKCHAIN_ROOT}" STREQUAL "")
|
|
||||||
set(HAS_LOGOS_BLOCKCHAIN_ROOT TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DEFINED LOGOS_BLOCKCHAIN_LIB AND NOT "${LOGOS_BLOCKCHAIN_LIB}" STREQUAL "")
|
|
||||||
set(HAS_LOGOS_BLOCKCHAIN_LIB TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DEFINED LOGOS_BLOCKCHAIN_INCLUDE AND NOT "${LOGOS_BLOCKCHAIN_INCLUDE}" STREQUAL "")
|
|
||||||
set(HAS_LOGOS_BLOCKCHAIN_INCLUDE TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT HAS_LOGOS_CORE_ROOT)
|
|
||||||
message(FATAL_ERROR "LOGOS_CORE_ROOT must be set to the logos-core root directory.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAS_LOGOS_BLOCKCHAIN_LIB AND HAS_LOGOS_BLOCKCHAIN_INCLUDE AND NOT HAS_LOGOS_BLOCKCHAIN_ROOT)
|
|
||||||
message(STATUS "Using prebuilt logos-blockchain.")
|
|
||||||
set(LOGOS_BLOCKCHAIN_PREBUILT TRUE)
|
|
||||||
elseif(NOT HAS_LOGOS_BLOCKCHAIN_LIB AND NOT HAS_LOGOS_BLOCKCHAIN_INCLUDE AND HAS_LOGOS_BLOCKCHAIN_ROOT)
|
|
||||||
message(STATUS "Building logos-blockchain from source.")
|
|
||||||
set(LOGOS_BLOCKCHAIN_PREBUILT FALSE)
|
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Either both LOGOS_BLOCKCHAIN_LIB and LOGOS_BLOCKCHAIN_INCLUDE must be set for prebuilt logos-blockchain, or only LOGOS_BLOCKCHAIN_ROOT must be set for building from source.")
|
message(FATAL_ERROR "LogosModule.cmake not found. Set LOGOS_MODULE_BUILDER_ROOT.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ---- Qt ----
|
# logos_module() handles: Qt/AUTOMOC setup, SDK/module include paths, linking
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Core RemoteObjects)
|
# libs from EXTERNAL_LIBS into lib/, plugin output naming, RPATH, install rules.
|
||||||
set(CMAKE_AUTOMOC ON)
|
logos_module(
|
||||||
set(CMAKE_AUTOUIC ON)
|
NAME liblogos_blockchain_module
|
||||||
set(CMAKE_AUTORCC ON)
|
SOURCES
|
||||||
|
src/i_logos_blockchain_module.h
|
||||||
# ---- Directories ----
|
src/logos_blockchain_module.h
|
||||||
set(WORKSPACE_ROOT "${CMAKE_BINARY_DIR}/workspace")
|
src/logos_blockchain_module.cpp
|
||||||
file(MAKE_DIRECTORY "${WORKSPACE_ROOT}")
|
EXTERNAL_LIBS
|
||||||
|
logos_blockchain
|
||||||
# ---- Logos Core SDK ----
|
|
||||||
set(SDK_LIB "${LOGOS_CORE_ROOT}/lib/liblogos_sdk.a")
|
|
||||||
set(SDK_INC "${LOGOS_CORE_ROOT}/include")
|
|
||||||
|
|
||||||
# ---- OS Specifics ----
|
|
||||||
if(APPLE)
|
|
||||||
set(DYLIB_EXT ".dylib")
|
|
||||||
elseif(WIN32)
|
|
||||||
set(DYLIB_EXT ".dll")
|
|
||||||
set(IMPLIB_EXT ".lib")
|
|
||||||
else()
|
|
||||||
set(DYLIB_EXT ".so")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# NOTE (Windows):
|
|
||||||
# Rust cdylib typically produces:
|
|
||||||
# - logos_blockchain.dll (runtime)
|
|
||||||
# - logos_blockchain.lib (import lib)
|
|
||||||
# The Windows build hasn't been yet, so adjust accordingly if the DLL is named without the 'lib' prefix.
|
|
||||||
|
|
||||||
# ---- Logos Blockchain (build OR consume) ----
|
|
||||||
if(LOGOS_BLOCKCHAIN_PREBUILT)
|
|
||||||
set(LOGOS_BLOCKCHAIN_DYLIB "${LOGOS_BLOCKCHAIN_LIB}/liblogos_blockchain${DYLIB_EXT}")
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
set(LOGOS_BLOCKCHAIN_IMPLIB "${LOGOS_BLOCKCHAIN_LIB}/logos_blockchain${IMPLIB_EXT}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_custom_target(logos_blockchain_libs)
|
|
||||||
|
|
||||||
else()
|
|
||||||
find_program(CARGO_EXECUTABLE cargo REQUIRED)
|
|
||||||
|
|
||||||
set(CARGO_TARGET_DIR "${WORKSPACE_ROOT}/logos-blockchain/target")
|
|
||||||
set(INTERNAL_STAGE "${WORKSPACE_ROOT}/stage")
|
|
||||||
set(INTERNAL_STAGE_LIB "${INTERNAL_STAGE}/lib")
|
|
||||||
set(INTERNAL_STAGE_INCLUDE "${INTERNAL_STAGE}/include")
|
|
||||||
file(MAKE_DIRECTORY "${CARGO_TARGET_DIR}" "${INTERNAL_STAGE_LIB}" "${INTERNAL_STAGE_INCLUDE}")
|
|
||||||
|
|
||||||
set(LOGOS_BLOCKCHAIN_LIB "${INTERNAL_STAGE_LIB}")
|
|
||||||
set(LOGOS_BLOCKCHAIN_INCLUDE "${INTERNAL_STAGE_INCLUDE}")
|
|
||||||
|
|
||||||
set(LOGOS_BLOCKCHAIN_DYLIB "${INTERNAL_STAGE_LIB}/liblogos_blockchain${DYLIB_EXT}")
|
|
||||||
set(LOGOS_BLOCKCHAIN_HEADER "${INTERNAL_STAGE_INCLUDE}/logos_blockchain.h")
|
|
||||||
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${LOGOS_BLOCKCHAIN_DYLIB}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E env
|
|
||||||
CARGO_TARGET_DIR=${CARGO_TARGET_DIR}
|
|
||||||
${CARGO_EXECUTABLE} build --release
|
|
||||||
--package logos-blockchain-c
|
|
||||||
--manifest-path "${LOGOS_BLOCKCHAIN_ROOT}/Cargo.toml"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy
|
|
||||||
"${CARGO_TARGET_DIR}/release/liblogos_blockchain${DYLIB_EXT}"
|
|
||||||
"${LOGOS_BLOCKCHAIN_DYLIB}"
|
|
||||||
DEPENDS "${LOGOS_BLOCKCHAIN_ROOT}/Cargo.toml"
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${LOGOS_BLOCKCHAIN_HEADER}"
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
||||||
"${LOGOS_BLOCKCHAIN_ROOT}/c-bindings/logos_blockchain.h"
|
|
||||||
"${LOGOS_BLOCKCHAIN_HEADER}"
|
|
||||||
DEPENDS "${LOGOS_BLOCKCHAIN_DYLIB}"
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_target(logos_blockchain_libs DEPENDS "${LOGOS_BLOCKCHAIN_DYLIB}" "${LOGOS_BLOCKCHAIN_HEADER}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ---- Imported targets ----
|
|
||||||
add_library(logos_blockchain_interface SHARED IMPORTED GLOBAL)
|
|
||||||
set_target_properties(logos_blockchain_interface PROPERTIES
|
|
||||||
IMPORTED_LOCATION "${LOGOS_BLOCKCHAIN_DYLIB}"
|
|
||||||
INTERFACE_INCLUDE_DIRECTORIES "${LOGOS_BLOCKCHAIN_INCLUDE}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT LOGOS_BLOCKCHAIN_PREBUILT)
|
|
||||||
add_dependencies(logos_blockchain_interface logos_blockchain_libs)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
set_target_properties(logos_blockchain_interface PROPERTIES IMPORTED_IMPLIB "${LOGOS_BLOCKCHAIN_IMPLIB}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_library(logos_core STATIC IMPORTED)
|
|
||||||
set_target_properties(logos_core PROPERTIES
|
|
||||||
IMPORTED_LOCATION "${SDK_LIB}"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(logos_cpp_sdk INTERFACE)
|
|
||||||
target_include_directories(logos_cpp_sdk INTERFACE "${SDK_INC}" "${SDK_INC}/cpp")
|
|
||||||
|
|
||||||
# ---- Plugin ----
|
|
||||||
set(PLUGIN_TARGET logos_blockchain_module)
|
|
||||||
|
|
||||||
qt_add_plugin(${PLUGIN_TARGET} CLASS_NAME LogosBlockchainModule)
|
|
||||||
|
|
||||||
target_sources(${PLUGIN_TARGET} PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/logos_blockchain_module.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set_property(TARGET ${PLUGIN_TARGET} PROPERTY PUBLIC_HEADER
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/i_logos_blockchain_module.h
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(${PLUGIN_TARGET} PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(${PLUGIN_TARGET} PRIVATE
|
|
||||||
Qt6::Core
|
|
||||||
Qt6::RemoteObjects
|
|
||||||
logos_blockchain_interface
|
|
||||||
logos_cpp_sdk
|
|
||||||
logos_core
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_definitions(${PLUGIN_TARGET} PRIVATE
|
|
||||||
LOGOS_BLOCKCHAIN_MODULE_METADATA_FILE="${CMAKE_CURRENT_SOURCE_DIR}/metadata.json"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_dependencies(${PLUGIN_TARGET} logos_blockchain_libs)
|
|
||||||
|
|
||||||
if(APPLE)
|
|
||||||
set_target_properties(${PLUGIN_TARGET} PROPERTIES
|
|
||||||
BUILD_RPATH "@loader_path"
|
|
||||||
INSTALL_RPATH "@loader_path"
|
|
||||||
)
|
|
||||||
elseif(UNIX)
|
|
||||||
set_target_properties(${PLUGIN_TARGET} PROPERTIES
|
|
||||||
BUILD_RPATH "$ORIGIN"
|
|
||||||
INSTALL_RPATH "$ORIGIN"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ---- Install ----
|
|
||||||
install(TARGETS ${PLUGIN_TARGET}
|
|
||||||
LIBRARY DESTINATION lib
|
|
||||||
ARCHIVE DESTINATION lib
|
|
||||||
RUNTIME DESTINATION bin
|
|
||||||
PUBLIC_HEADER DESTINATION include
|
|
||||||
)
|
|
||||||
install(DIRECTORY "${LOGOS_BLOCKCHAIN_INCLUDE}/" DESTINATION include)
|
|
||||||
install(FILES "${LOGOS_BLOCKCHAIN_DYLIB}" DESTINATION lib)
|
|
||||||
|
|||||||
45
README.md
45
README.md
@ -1,38 +1,41 @@
|
|||||||
# Logos Blockchain Module
|
# Logos Blockchain Module
|
||||||
|
|
||||||
### Setup
|
A Logos core module that wraps the [logos-blockchain](https://github.com/logos-blockchain/logos-blockchain) C bindings and ships the zk circuit binaries needed at runtime.
|
||||||
|
|
||||||
#### IDE
|
Built with [logos-module-builder](https://github.com/logos-co/logos-module-builder): `flake.nix`, `CMakeLists.txt`, and `metadata.json` are the only build-system files. The module-builder's `mkLogosModule` pulls the prebuilt `logos-blockchain-c` derivation (lib + header) in via `externalLibInputs`; the circuits directory is staged separately in `preConfigure` / `postInstall` because it's runtime data rather than a library.
|
||||||
|
|
||||||
If you're using an IDE with CMake integration make sure it points to the same cmake directory as the `justfile`, which defaults to `build`.
|
### Build and inspect
|
||||||
|
|
||||||
This will reduce friction when working on the project.
|
```bash
|
||||||
|
# In the workspace (preferred):
|
||||||
|
ws build logos-blockchain-module
|
||||||
|
ws build logos-blockchain-module --auto-local # pick up local dep overrides
|
||||||
|
|
||||||
#### Nix
|
# Inspect the built plugin
|
||||||
|
lm ./result/lib/liblogos_blockchain_module_plugin.so
|
||||||
|
|
||||||
* Use `nix flake update` to bring all nix context and packages
|
# Standalone
|
||||||
* Use `nix build` to build the package
|
nix build # -> result/lib/<plugin>.so + result/lib/circuits/
|
||||||
* Use `nix run` to launch the module-viewer and check your module loads properly
|
nix develop # cmake/ninja iteration
|
||||||
* Use `nix develop` to setup your IDE
|
```
|
||||||
|
|
||||||
|
### Files
|
||||||
|
|
||||||
|
- `flake.nix` — `mkLogosModule` call + circuits staging
|
||||||
|
- `CMakeLists.txt` — single `logos_module()` macro + C++20 bump
|
||||||
|
- `metadata.json` — module identity, deps, and `nix.external_libraries`
|
||||||
|
- `src/` — plugin sources (Q_OBJECT + Q_INVOKABLE API)
|
||||||
|
|
||||||
### Troubleshooting
|
### Troubleshooting
|
||||||
|
|
||||||
#### Nix + IDE Integration
|
#### Nix + IDE Integration
|
||||||
If your IDE reports that a file doesn't belong to the project or that files cannot be found, the CMake cache
|
If your IDE reports that a file doesn't belong to the project or that files cannot be found, the CMake cache is likely missing the Nix-provided paths. This happens when the IDE runs CMake on its own, outside the Nix environment, leaving `LOGOS_CPP_SDK_ROOT` / `LOGOS_MODULE_BUILDER_ROOT` unset.
|
||||||
is likely missing the Nix-provided paths. This happens when the IDE runs CMake on its own, outside the Nix
|
|
||||||
environment, leaving the required paths empty.
|
|
||||||
|
|
||||||
To fix it:
|
To fix it:
|
||||||
|
|
||||||
1. **Regenerate the cache from within the Nix shell**
|
1. **Regenerate the cache from within the Nix shell** — this provides the required Nix paths and writes them into `build/CMakeCache.txt`:
|
||||||
|
|
||||||
This provides the required Nix paths and writes them into `build/CMakeCache.txt`:
|
|
||||||
```bash
|
```bash
|
||||||
nix develop -c just configure
|
nix develop -c cmake -B build -GNinja
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Reload the CMake project without resetting the cache**
|
2. **Reload the CMake project without resetting the cache.** On RustRover: open the CMake tool window (**View → Tool Windows → CMake**) and click **Reload** (↺). Resetting the cache would wipe the paths you just wrote.
|
||||||
|
|
||||||
If on RustRover: Open the CMake tool window (**View → Tool Windows → CMake**) and click the **Reload** button (↺) in the toolbar.
|
|
||||||
|
|
||||||
> Resetting the cache would wipe the paths you just wrote, so make sure to reload only.
|
|
||||||
|
|||||||
6884
flake.lock
generated
6884
flake.lock
generated
File diff suppressed because it is too large
Load Diff
181
flake.nix
181
flake.nix
@ -2,163 +2,40 @@
|
|||||||
description = "Logos Blockchain Module - Qt6 Plugin";
|
description = "Logos Blockchain Module - Qt6 Plugin";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.follows = "logos-liblogos/nixpkgs";
|
logos-module-builder.url = "github:logos-co/logos-module-builder";
|
||||||
|
|
||||||
logos-liblogos.url = "github:logos-co/logos-liblogos";
|
|
||||||
logos-core.url = "github:logos-co/logos-cpp-sdk";
|
|
||||||
|
|
||||||
#logos-blockchain.url = "github:logos-blockchain/logos-blockchain?rev=d7ff5984fa3371a89e944b163b358465a5e307ad"; # pre-0.1.3 + genesis fixes
|
|
||||||
logos-blockchain.url = "github:logos-blockchain/logos-blockchain?ref=feat/nix/disable-testing"; # pre-0.1.3 + genesis fixes
|
logos-blockchain.url = "github:logos-blockchain/logos-blockchain?ref=feat/nix/disable-testing"; # pre-0.1.3 + genesis fixes
|
||||||
|
|
||||||
logos-module-viewer.url = "github:logos-co/logos-module-viewer";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs = inputs@{ logos-module-builder, ... }:
|
||||||
{
|
logos-module-builder.lib.mkLogosModule {
|
||||||
self,
|
src = ./.;
|
||||||
nixpkgs,
|
configFile = ./metadata.json;
|
||||||
logos-core,
|
flakeInputs = inputs;
|
||||||
logos-blockchain,
|
|
||||||
logos-module-viewer,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
lib = nixpkgs.lib;
|
|
||||||
|
|
||||||
systems = [
|
externalLibInputs = {
|
||||||
"x86_64-linux"
|
logos_blockchain = inputs.logos-blockchain;
|
||||||
"aarch64-linux"
|
};
|
||||||
"x86_64-darwin"
|
|
||||||
"aarch64-darwin"
|
|
||||||
];
|
|
||||||
|
|
||||||
forAll = lib.genAttrs systems;
|
preConfigure = { externalLibs }: ''
|
||||||
|
if [ -d "${externalLibs.logos_blockchain}/circuits" ]; then
|
||||||
|
echo "Staging zk circuits from logos-blockchain..."
|
||||||
|
cp -r "${externalLibs.logos_blockchain}/circuits" ./circuits
|
||||||
|
chmod -R u+w ./circuits
|
||||||
|
else
|
||||||
|
echo "WARNING: no circuits/ found in logos-blockchain derivation"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
|
||||||
mkPkgs = system: import nixpkgs { inherit system; };
|
# Logos Core Edge-case
|
||||||
in
|
# The current version of Logos Core expects circuits' binaries under `lib/circuits/`.
|
||||||
{
|
# Until we address this in Logos Core, we use this hook to include to ensure the circuits' binaries
|
||||||
packages = forAll (
|
# are included in the binary bundle and avoid the circuits being mangled by Nix (which did that when
|
||||||
system:
|
# copying them in a previous phase).
|
||||||
let
|
postInstall = ''
|
||||||
pkgs = mkPkgs system;
|
if [ -d "$LOGOS_MODULE_SOURCE_DIR/circuits" ]; then
|
||||||
llvmPkgs = pkgs.llvmPackages;
|
cp -r "$LOGOS_MODULE_SOURCE_DIR/circuits" "$out/lib/circuits"
|
||||||
|
chmod -R u+w "$out/lib/circuits"
|
||||||
logosCore = logos-core.packages.${system}.default;
|
fi
|
||||||
logosBlockchainC = logos-blockchain.packages.${system}.logos-blockchain-c;
|
'';
|
||||||
|
|
||||||
logosBlockchainModule = pkgs.stdenv.mkDerivation {
|
|
||||||
pname = "logos-blockchain-module";
|
|
||||||
version = "dev";
|
|
||||||
src = ./.;
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
|
||||||
pkgs.cmake
|
|
||||||
pkgs.ninja
|
|
||||||
pkgs.pkg-config
|
|
||||||
pkgs.qt6.wrapQtAppsHook
|
|
||||||
];
|
|
||||||
|
|
||||||
buildInputs = [
|
|
||||||
pkgs.qt6.qtbase
|
|
||||||
pkgs.qt6.qtremoteobjects
|
|
||||||
pkgs.qt6.qttools
|
|
||||||
llvmPkgs.clang
|
|
||||||
llvmPkgs.libclang
|
|
||||||
logosBlockchainC
|
|
||||||
]
|
|
||||||
++ lib.optionals pkgs.stdenv.isDarwin [
|
|
||||||
pkgs.libiconv
|
|
||||||
pkgs.cacert
|
|
||||||
];
|
|
||||||
|
|
||||||
LIBCLANG_PATH = "${llvmPkgs.libclang.lib}/lib";
|
|
||||||
CLANG_PATH = "${llvmPkgs.clang}/bin/clang";
|
|
||||||
SSL_CERT_FILE = lib.optionalString pkgs.stdenv.isDarwin "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
|
||||||
|
|
||||||
cmakeFlags = [
|
|
||||||
"-DLOGOS_CORE_ROOT=${logosCore}"
|
|
||||||
"-DLOGOS_BLOCKCHAIN_LIB=${logosBlockchainC}/lib"
|
|
||||||
"-DLOGOS_BLOCKCHAIN_INCLUDE=${logosBlockchainC}/include"
|
|
||||||
];
|
|
||||||
|
|
||||||
postInstall = ''
|
|
||||||
mkdir $out/share
|
|
||||||
cp -r ${logosBlockchainC}/circuits $out/share
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Logos Core Edge-case
|
|
||||||
# The current version of Logos Core expects circuits' binaries under `lib/circuits/`.
|
|
||||||
# Until we address this in Logos Core, we use this hook to include to ensure the circuits' binaries
|
|
||||||
# are included in the binary bundle and avoid the circuits being mangled by Nix (which did that when
|
|
||||||
# copying them in a previous phase).
|
|
||||||
postFixup = ''
|
|
||||||
cp -r ${logosBlockchainC}/circuits $out/lib/circuits
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
lib = logosBlockchainModule;
|
|
||||||
default = logosBlockchainModule;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
apps = forAll (
|
|
||||||
system:
|
|
||||||
let
|
|
||||||
pkgs = mkPkgs system;
|
|
||||||
logosBlockchainModuleLib = self.packages.${system}.lib;
|
|
||||||
logosModuleViewer = logos-module-viewer.packages.${system}.default;
|
|
||||||
extension = if pkgs.stdenv.isDarwin then "dylib"
|
|
||||||
else if pkgs.stdenv.hostPlatform.isWindows then "dll"
|
|
||||||
else "so";
|
|
||||||
inspectModule = {
|
|
||||||
type = "app";
|
|
||||||
program =
|
|
||||||
"${pkgs.writeShellScriptBin "inspect-module" ''
|
|
||||||
exec ${logosModuleViewer}/bin/logos-module-viewer \
|
|
||||||
--module ${logosBlockchainModuleLib}/lib/liblogos_blockchain_module.${extension}
|
|
||||||
''}/bin/inspect-module";
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inspect-module = inspectModule;
|
|
||||||
default = inspectModule;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
devShells = forAll (
|
|
||||||
system:
|
|
||||||
let
|
|
||||||
pkgs = mkPkgs system;
|
|
||||||
pkg = self.packages.${system}.default;
|
|
||||||
logosCore = logos-core.packages.${system}.default;
|
|
||||||
logosBlockchainC = logos-blockchain.packages.${system}.logos-blockchain-c;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
default = pkgs.mkShell {
|
|
||||||
inputsFrom = [ pkg ];
|
|
||||||
|
|
||||||
inherit (pkg)
|
|
||||||
LIBCLANG_PATH
|
|
||||||
CLANG_PATH;
|
|
||||||
|
|
||||||
LOGOS_CORE_ROOT = "${logosCore}";
|
|
||||||
LOGOS_BLOCKCHAIN_LIB = "${logosBlockchainC}/lib";
|
|
||||||
LOGOS_BLOCKCHAIN_INCLUDE = "${logosBlockchainC}/include";
|
|
||||||
|
|
||||||
shellHook = ''
|
|
||||||
BLUE='\e[1;34m'
|
|
||||||
GREEN='\e[1;32m'
|
|
||||||
RESET='\e[0m'
|
|
||||||
|
|
||||||
echo -e "\n''${BLUE}=== Logos Blockchain Module Development Environment ===''${RESET}"
|
|
||||||
echo -e "''${GREEN}LOGOS_CORE_ROOT:''${RESET} $LOGOS_CORE_ROOT"
|
|
||||||
echo -e "''${GREEN}LOGOS_BLOCKCHAIN_LIB:''${RESET} $LOGOS_BLOCKCHAIN_LIB"
|
|
||||||
echo -e "''${GREEN}LOGOS_BLOCKCHAIN_INCLUDE:''${RESET} $LOGOS_BLOCKCHAIN_INCLUDE"
|
|
||||||
echo -e "''${BLUE}---------------------------------------------------------''${RESET}"
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
10
justfile
10
justfile
@ -1,13 +1,13 @@
|
|||||||
default: build
|
default: build
|
||||||
|
|
||||||
|
# Inside `nix develop` / `ws develop logos-blockchain-module` the module-builder
|
||||||
|
# provides LOGOS_CPP_SDK_ROOT and LOGOS_MODULE_BUILDER_ROOT — CMake picks them
|
||||||
|
# up automatically via the logos_module() macro, no explicit -D flags needed.
|
||||||
configure:
|
configure:
|
||||||
cmake -S . -B build -G Ninja \
|
cmake -S . -B build -G Ninja
|
||||||
${LOGOS_CORE_ROOT:+-DLOGOS_CORE_ROOT="$LOGOS_CORE_ROOT"} \
|
|
||||||
${LOGOS_BLOCKCHAIN_LIB:+-DLOGOS_BLOCKCHAIN_LIB="$LOGOS_BLOCKCHAIN_LIB"} \
|
|
||||||
${LOGOS_BLOCKCHAIN_INCLUDE:+-DLOGOS_BLOCKCHAIN_INCLUDE="$LOGOS_BLOCKCHAIN_INCLUDE"}
|
|
||||||
|
|
||||||
build: configure
|
build: configure
|
||||||
cmake --build build --parallel --target logos_blockchain_module
|
cmake --build build --parallel --target liblogos_blockchain_module_module_plugin
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build result
|
rm -rf build result
|
||||||
|
|||||||
@ -5,16 +5,29 @@
|
|||||||
"author": "Logos Blockchain Team",
|
"author": "Logos Blockchain Team",
|
||||||
"type": "core",
|
"type": "core",
|
||||||
"category": "blockchain",
|
"category": "blockchain",
|
||||||
"main": "liblogos_blockchain_module",
|
"main": "liblogos_blockchain_module_plugin",
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"capabilities": [],
|
"capabilities": [],
|
||||||
"include": [
|
"include": [
|
||||||
"liblogos_blockchain.dylib",
|
"liblogos_blockchain.dylib",
|
||||||
"liblogos_blockchain.so",
|
"liblogos_blockchain.so",
|
||||||
"liblogos_blockchain.dll",
|
"liblogos_blockchain.dll",
|
||||||
"liblogos_blockchain_module.dylib",
|
"liblogos_blockchain_module_plugin.dylib",
|
||||||
"liblogos_blockchain_module.so",
|
"liblogos_blockchain_module_plugin.so",
|
||||||
"liblogos_blockchain_module.dll",
|
"liblogos_blockchain_module_plugin.dll",
|
||||||
"circuits"
|
"circuits"
|
||||||
]
|
],
|
||||||
|
|
||||||
|
"nix": {
|
||||||
|
"packages": {
|
||||||
|
"build": [],
|
||||||
|
"runtime": []
|
||||||
|
},
|
||||||
|
"external_libraries": [
|
||||||
|
{ "name": "logos_blockchain" }
|
||||||
|
],
|
||||||
|
"cmake": {
|
||||||
|
"extra_include_dirs": ["lib"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
#define I_LOGOS_BLOCKCHAIN_MODULE_API_H
|
#define I_LOGOS_BLOCKCHAIN_MODULE_API_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <core/interface.h>
|
#include "interface.h"
|
||||||
|
|
||||||
class ILogosBlockchainModule {
|
class ILogosBlockchainModule {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -4,12 +4,31 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QMetaType>
|
||||||
|
#include <QUrl>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QVariantList>
|
||||||
|
|
||||||
// Define static member
|
// Define static member
|
||||||
LogosBlockchainModule* LogosBlockchainModule::s_instance = nullptr;
|
LogosBlockchainModule* LogosBlockchainModule::s_instance = nullptr;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
// Rust `File::open` / `deserialize_config_at_path` only accept real filesystem paths. QML often
|
||||||
|
// passes `file:///...` URLs; strip to a local path when applicable.
|
||||||
|
QString localPathFromFileUrl(const QString& s) {
|
||||||
|
if (s.isEmpty()) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
if (s.startsWith(QStringLiteral("file:"), Qt::CaseInsensitive)) {
|
||||||
|
const QUrl u(s);
|
||||||
|
if (u.isLocalFile()) {
|
||||||
|
return QDir::toNativeSeparators(u.toLocalFile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
// Use the C API type Hash (from logos_blockchain.h) to define address/hash byte size.
|
// Use the C API type Hash (from logos_blockchain.h) to define address/hash byte size.
|
||||||
constexpr int ADDRESS_BYTES = sizeof(Hash);
|
constexpr int ADDRESS_BYTES = sizeof(Hash);
|
||||||
constexpr int ADDRESS_HEX_LEN = ADDRESS_BYTES * 2;
|
constexpr int ADDRESS_HEX_LEN = ADDRESS_BYTES * 2;
|
||||||
@ -263,14 +282,14 @@ int LogosBlockchainModule::start(const QString& config_path, const QString& depl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qInfo() << "Starting the node with the configuration file:" << effective_config_path;
|
effective_config_path = localPathFromFileUrl(effective_config_path);
|
||||||
qInfo() << "Using deployment:" << (deployment.isEmpty() ? "<default>" : deployment);
|
const QString deployment_path = localPathFromFileUrl(deployment);
|
||||||
|
|
||||||
const QByteArray config_path_buffer = effective_config_path.toUtf8();
|
const QByteArray config_path_buffer = effective_config_path.toUtf8();
|
||||||
const char* config_path_ptr = effective_config_path.isEmpty() ? nullptr : config_path_buffer.constData();
|
const char* config_path_ptr = effective_config_path.isEmpty() ? nullptr : config_path_buffer.constData();
|
||||||
|
|
||||||
const QByteArray deployment_buffer = deployment.toUtf8();
|
const QByteArray deployment_buffer = deployment_path.toUtf8();
|
||||||
const char* deployment_ptr = deployment.isEmpty() ? nullptr : deployment_buffer.constData();
|
const char* deployment_ptr = deployment_path.isEmpty() ? nullptr : deployment_buffer.constData();
|
||||||
|
|
||||||
auto [value, error] = start_lb_node(config_path_ptr, deployment_ptr);
|
auto [value, error] = start_lb_node(config_path_ptr, deployment_ptr);
|
||||||
qInfo() << "Start node returned with value and error.";
|
qInfo() << "Start node returned with value and error.";
|
||||||
|
|||||||
@ -13,7 +13,7 @@ extern "C" {
|
|||||||
|
|
||||||
class LogosBlockchainModule final : public QObject, public PluginInterface, public ILogosBlockchainModule {
|
class LogosBlockchainModule final : public QObject, public PluginInterface, public ILogosBlockchainModule {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID ILogosBlockchainModule_iid FILE LOGOS_BLOCKCHAIN_MODULE_METADATA_FILE)
|
Q_PLUGIN_METADATA(IID ILogosBlockchainModule_iid FILE "metadata.json")
|
||||||
Q_INTERFACES(PluginInterface)
|
Q_INTERFACES(PluginInterface)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user