diff --git a/native/cpp/CommonCpp/grpc/CMakeLists.txt b/native/cpp/CommonCpp/grpc/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/grpc/CMakeLists.txt @@ -0,0 +1,105 @@ +project(grpc-comm) +cmake_minimum_required(VERSION 3.4) + +include(GNUInstallDirs) +find_package(protobuf REQUIRED) +find_package(gRPC REQUIRED) + +set(_components backup blob tunnelbroker) +set(TARGETS) +# Iterate through each protobuf file +# and create headers, sources, and export as component library +foreach(_component ${_components}) + set(LIB_NAME comm-${_component}-grpc) + set(TARGETS ${TARGETS} ${LIB_NAME}) + + set(PROTO_HDRS + ${CMAKE_CURRENT_SOURCE_DIR}/_generated/${_component}.pb.h + ${CMAKE_CURRENT_SOURCE_DIR}/_generated/${_component}.grpc.pb.h + ) + + set(PROTO_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/_generated/${_component}.pb.cc + ${CMAKE_CURRENT_SOURCE_DIR}/_generated/${_component}.grpc.pb.cc + ) + + add_library(${LIB_NAME} + ${PROTO_HDRS} ${PROTO_SRCS} + ) + + target_link_libraries(${LIB_NAME} + gRPC::grpc++ + protobuf::libprotobuf + ) + + # reference local directory when building, use installation path when installing + target_include_directories(${LIB_NAME} + PUBLIC + $ + $ + ) + + install(TARGETS ${LIB_NAME} EXPORT comm-export + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${LIB_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${LIB_NAME} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${LIB_NAME} + ) + + # ensure headers are also installed + install(FILES ${PROTO_HDRS} DESTINATION include/comm/grpc) +endforeach() + +set(CLIENT_HDRS + "Client.h" + "ClientGetReadReactor.h" + "GRPCStreamHostObject.h" +) + +set(CLIENT_SRCS + "Client.cpp" + "ClientGetReadReactor.cpp" + "GRPCStreamHostObject.cpp" +) + +add_library(comm-client + ${CLIENT_HDRS} + ${CLIENT_SRCS} +) + +target_link_libraries(comm-client + gRPC::grpc++ + protobuf::libprotobuf + comm-tunnelbroker-grpc +) + +# reference local directory when building, use installation path when installing +target_include_directories(comm-client + PUBLIC + $ + $ + # HACK: add complete cmake support to react-native? + PRIVATE + "../../../node_modules/react-native/ReactCommon/callinvoker" + "../../../node_modules/react-native/ReactCommon/jsi" +) + +install(TARGETS comm-client EXPORT comm-export + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT comm-client + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-client + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT comm-client +) + +install(FILES ${CLIENT_HDRS} DESTINATION include/grpc) + +# For development purposes, able to reference build directory +export(TARGETS ${TARGETS} comm-client + NAMESPACE comm-grpc:: + FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/comm-grpc/comm-grpc-targets.cmake +) + +# For installation +install(EXPORT comm-export + FILE comm-grpc-targets.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/comm-grpc + NAMESPACE comm-grpc:: +) diff --git a/native/cpp/CommonCpp/grpc/Client.h b/native/cpp/CommonCpp/grpc/Client.h --- a/native/cpp/CommonCpp/grpc/Client.h +++ b/native/cpp/CommonCpp/grpc/Client.h @@ -6,8 +6,8 @@ #include #include "ClientGetReadReactor.h" -#include "_generated/tunnelbroker.grpc.pb.h" -#include "_generated/tunnelbroker.pb.h" +#include +#include namespace comm { namespace network { diff --git a/native/cpp/CommonCpp/grpc/Client.cpp b/native/cpp/CommonCpp/grpc/Client.cpp --- a/native/cpp/CommonCpp/grpc/Client.cpp +++ b/native/cpp/CommonCpp/grpc/Client.cpp @@ -1,5 +1,5 @@ -#include "Client.h" -#include "Logger.h" +#include +#include #include namespace comm { diff --git a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h --- a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h +++ b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h @@ -1,10 +1,10 @@ #pragma once -#include "../NativeModules/InternalModules/SocketStatus.h" +#include #include -#include "_generated/tunnelbroker.grpc.pb.h" -#include "_generated/tunnelbroker.pb.h" +#include +#include class ClientGetReadReactor : public grpc::ClientReadReactor { diff --git a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp --- a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp +++ b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp @@ -1,4 +1,4 @@ -#include "ClientGetReadReactor.h" +#include ClientGetReadReactor::ClientGetReadReactor( tunnelbroker::TunnelbrokerService::Stub *stub, diff --git a/native/cpp/CommonCpp/grpc/GRPCStreamHostObject.cpp b/native/cpp/CommonCpp/grpc/GRPCStreamHostObject.cpp --- a/native/cpp/CommonCpp/grpc/GRPCStreamHostObject.cpp +++ b/native/cpp/CommonCpp/grpc/GRPCStreamHostObject.cpp @@ -1,6 +1,6 @@ -#include "GRPCStreamHostObject.h" -#include "../NativeModules/InternalModules/GlobalNetworkSingleton.h" -#include "../NativeModules/InternalModules/SocketStatus.h" +#include +#include +#include using namespace facebook; diff --git a/nix/comm-grpc.nix b/nix/comm-grpc.nix new file mode 100644 --- /dev/null +++ b/nix/comm-grpc.nix @@ -0,0 +1,27 @@ +{ lib +, stdenv +, cmake +, openssl +, pkg-config +, grpc +, ninja +, protobuf_3_15_cmake +}: + +stdenv.mkDerivation rec { + name = "comm-grpc"; + + src = ../native/cpp/CommonCpp/grpc; + + nativeBuildInputs = [ + cmake + ninja + pkg-config + ]; + + buildInputs = [ + openssl + grpc + protobuf_3_15_cmake + ]; +} diff --git a/nix/overlay.nix b/nix/overlay.nix --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -29,6 +29,8 @@ protobuf_3_15_cmake = prev.callPackage ./protobuf_3_15.nix { }; + comm-grpc = final.callPackage ./comm-grpc.nix { }; + devShell = final.callPackage ./dev-shell.nix { }; mysql-down = prev.callPackage ./mysql-down-linux.nix { };