Page MenuHomePhabricator

D3867.id14230.diff
No OneTemporary

D3867.id14230.diff

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,101 @@
+project(grpc-comm)
+cmake_minimum_required(VERSION 3.4)
+
+include(GNUInstallDirs)
+find_package(protobuf REQUIRED)
+find_package(gRPC REQUIRED)
+
+set(_components backup blob tunnelbroker)
+# Iterate through each protobuf file
+# and create headers, sources, and export as component library
+foreach(_component ${_components})
+ 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(${_component}
+ ${PROTO_HDRS} ${PROTO_SRCS}
+ )
+
+ target_link_libraries(${_component}
+ gRPC::grpc++
+ protobuf::libprotobuf
+ )
+
+ # reference local directory when building, use installation path when installing
+ target_include_directories(${_component}
+ PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/_generated>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ )
+
+ install(TARGETS ${_component} EXPORT comm-export
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_component}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_component}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_component}
+ )
+
+ # 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
+ tunnelbroker
+)
+
+# reference local directory when building, use installation path when installing
+target_include_directories(comm-client
+ PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ # 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 ${_components} 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 <grpcpp/grpcpp.h>
#include "ClientGetReadReactor.h"
-#include "_generated/tunnelbroker.grpc.pb.h"
-#include "_generated/tunnelbroker.pb.h"
+#include <tunnelbroker.grpc.pb.h>
+#include <tunnelbroker.pb.h>
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 <Tools/Logger.h>
+#include <grpc/Client.h>
#include <sstream>
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 <Internal/SocketStatus.h>
#include <grpcpp/grpcpp.h>
-#include "_generated/tunnelbroker.grpc.pb.h"
-#include "_generated/tunnelbroker.pb.h"
+#include <tunnelbroker.grpc.pb.h>
+#include <tunnelbroker.pb.h>
class ClientGetReadReactor
: public grpc::ClientReadReactor<tunnelbroker::GetResponse> {
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 <grpc/ClientGetReadReactor.h>
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 <Internal/GlobalNetworkSingleton.h>
+#include <Internal/SocketStatus.h>
+#include <grpc/GRPCStreamHostObject.h>
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
@@ -15,6 +15,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 { };

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 29, 6:29 PM (13 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2597789
Default Alt Text
D3867.id14230.diff (6 KB)

Event Timeline