Files
neuron-tai/packages/node/native/CMakeLists.txt
2026-07-13 16:00:49 +03:00

75 lines
2.9 KiB
CMake

# Native Shard protocol: C++ schema generation, build wiring and conformance test.
#
# The C++ stubs are generated into the build tree at configure time — they are
# never committed. A C++ consumer already needs a toolchain, so committing
# generated C++ would only create a second copy of the schema that can rot.
#
# gRPC C++ is optional here on purpose. The conformance test only needs message
# types, so the schema can be verified on a machine that has protobuf but not
# the gRPC C++ stack. When gRPC *is* found, the service stubs are generated too
# and exported as `shard_runtime_grpc` for the worker (DGR-008) to link.
#
# Build:
# cmake -S packages/node/native -B build/native -DCMAKE_PREFIX_PATH=<protobuf-install>
# cmake --build build/native -j
# ctest --test-dir build/native --output-on-failure
#
# `scripts/bootstrap_native_toolchain.sh` builds a protobuf install from source
# when the system has none.
cmake_minimum_required(VERSION 3.24)
project(meshnet_shard_protocol CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG QUIET)
set(SHARD_PROTO "${CMAKE_CURRENT_SOURCE_DIR}/proto/shard_runtime.proto")
# Message types: always available.
add_library(shard_runtime_proto STATIC "${SHARD_PROTO}")
target_link_libraries(shard_runtime_proto PUBLIC protobuf::libprotobuf)
target_include_directories(shard_runtime_proto PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
protobuf_generate(
TARGET shard_runtime_proto
LANGUAGE cpp
IMPORT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/proto"
PROTOC_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}"
)
# Service stubs: only when the gRPC C++ stack is present.
if(gRPC_FOUND)
add_library(shard_runtime_grpc STATIC "${SHARD_PROTO}")
target_link_libraries(shard_runtime_grpc PUBLIC shard_runtime_proto gRPC::grpc++)
target_include_directories(shard_runtime_grpc PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
protobuf_generate(
TARGET shard_runtime_grpc
LANGUAGE grpc
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
PLUGIN "protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
IMPORT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/proto"
PROTOC_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}"
)
message(STATUS "gRPC C++ found: building ShardRuntime service stubs")
else()
message(STATUS "gRPC C++ not found: building message types only "
"(sufficient for the conformance test)")
endif()
enable_testing()
add_executable(shard_protocol_conformance tests/test_shard_protocol_conformance.cpp)
target_link_libraries(shard_protocol_conformance PRIVATE shard_runtime_proto)
# The test asserts against the same committed vectors the Python test uses, and
# writes its own re-serialization back out so Python can prove the two languages
# agree byte-for-byte.
add_test(
NAME shard_protocol_conformance
COMMAND shard_protocol_conformance
"${CMAKE_CURRENT_SOURCE_DIR}/testdata"
"${CMAKE_CURRENT_BINARY_DIR}"
)