[clang-tools-extra] 9bcf0ef - [clangd] Optionally add reflection for clangd-index-server
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 15 13:07:42 PDT 2021
Author: Kirill Bobyrev
Date: 2021-03-15T21:07:25+01:00
New Revision: 9bcf0eff99a01094c685ff375a42e3f5a9166094
URL: https://github.com/llvm/llvm-project/commit/9bcf0eff99a01094c685ff375a42e3f5a9166094
DIFF: https://github.com/llvm/llvm-project/commit/9bcf0eff99a01094c685ff375a42e3f5a9166094.diff
LOG: [clangd] Optionally add reflection for clangd-index-server
This was originally landed without the optional part and reverted later:
https://github.com/llvm/llvm-project/commit/8080ea4c4b8c456c72c617587cc32f174b3105c1
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D98404
Added:
Modified:
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/Features.inc.in
clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
clang-tools-extra/clangd/index/remote/server/Server.cpp
llvm/cmake/modules/FindGRPC.cmake
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt
index a6229a229002..11b8c7eadd1d 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -19,6 +19,7 @@ option(CLANGD_MALLOC_TRIM "Call malloc_trim(3) periodically in Clangd. (only tak
llvm_canonicalize_cmake_booleans(
CLANGD_BUILD_XPC
CLANGD_ENABLE_REMOTE
+ ENABLE_GRPC_REFLECTION
CLANGD_MALLOC_TRIM
LLVM_ENABLE_ZLIB
)
diff --git a/clang-tools-extra/clangd/Features.inc.in b/clang-tools-extra/clangd/Features.inc.in
index c21d2b145571..5dfde58890b7 100644
--- a/clang-tools-extra/clangd/Features.inc.in
+++ b/clang-tools-extra/clangd/Features.inc.in
@@ -1,3 +1,4 @@
#define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@
+#define ENABLE_GRPC_REFLECTION @ENABLE_GRPC_REFLECTION@
#define CLANGD_MALLOC_TRIM @CLANGD_MALLOC_TRIM@
diff --git a/clang-tools-extra/clangd/index/remote/server/CMakeLists.txt b/clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
index e6959db6bbd8..90b62caf524c 100644
--- a/clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
+++ b/clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
@@ -17,4 +17,6 @@ target_link_libraries(clangd-index-server
RemoteIndexProto
RemoteIndexServiceProto
clangdRemoteMarshalling
+
+ ${REFLECTION_LIBRARY}
)
diff --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 3de2c38f7c08..be0e844a1f80 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "Features.inc"
#include "Index.pb.h"
#include "Service.grpc.pb.h"
#include "index/Index.h"
@@ -35,6 +36,10 @@
#include <memory>
#include <thread>
+#if ENABLE_GRPC_REFLECTION
+#include <grpc++/ext/proto_server_reflection_plugin.h>
+#endif
+
namespace clang {
namespace clangd {
namespace remote {
@@ -313,6 +318,9 @@ void runServerAndWait(clangd::SymbolIndex &Index, llvm::StringRef ServerAddress,
RemoteIndexServer Service(Index, IndexRoot);
grpc::EnableDefaultHealthCheckService(true);
+#if ENABLE_GRPC_REFLECTION
+ grpc::reflection::InitProtoReflectionServerBuilderPlugin();
+#endif
grpc::ServerBuilder Builder;
Builder.AddListeningPort(ServerAddress.str(),
grpc::InsecureServerCredentials());
diff --git a/llvm/cmake/modules/FindGRPC.cmake b/llvm/cmake/modules/FindGRPC.cmake
index 8fdb3506dff1..66e9d832ae94 100644
--- a/llvm/cmake/modules/FindGRPC.cmake
+++ b/llvm/cmake/modules/FindGRPC.cmake
@@ -1,3 +1,5 @@
+option(ENABLE_GRPC_REFLECTION "Link clangd-index-server to gRPC Reflection library" OFF)
+
# FIXME(kirillbobyrev): Check if gRPC and Protobuf headers can be included at
# configure time.
find_package(Threads REQUIRED)
@@ -22,6 +24,10 @@ if (GRPC_INSTALL_PATH)
add_library(protobuf ALIAS protobuf::libprotobuf)
set_target_properties(gRPC::grpc++ PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(grpc++ ALIAS gRPC::grpc++)
+ if (ENABLE_GRPC_REFLECTION)
+ set_target_properties(gRPC::grpc++_reflection PROPERTIES IMPORTED_GLOBAL TRUE)
+ add_library(grpc++_reflection ALIAS gRPC::grpc++_reflection)
+ endif()
set(GRPC_CPP_PLUGIN $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
set(PROTOC ${Protobuf_PROTOC_EXECUTABLE})
@@ -71,12 +77,21 @@ else()
add_library(grpc++ UNKNOWN IMPORTED GLOBAL)
message(STATUS "Using grpc++: " ${GRPC_LIBRARY})
set_target_properties(grpc++ PROPERTIES IMPORTED_LOCATION ${GRPC_LIBRARY})
+ if (ENABLE_GRPC_REFLECTION)
+ find_library(GRPC_REFLECTION_LIBRARY grpc++_reflection $GRPC_OPTS REQUIRED)
+ add_library(grpc++_reflection UNKNOWN IMPORTED GLOBAL)
+ set_target_properties(grpc++_reflection PROPERTIES IMPORTED_LOCATION ${GRPC_REFLECTION_LIBRARY})
+ endif()
find_library(PROTOBUF_LIBRARY protobuf $PROTOBUF_OPTS REQUIRED)
message(STATUS "Using protobuf: " ${PROTOBUF_LIBRARY})
add_library(protobuf UNKNOWN IMPORTED GLOBAL)
set_target_properties(protobuf PROPERTIES IMPORTED_LOCATION ${PROTOBUF_LIBRARY})
endif()
+if (ENABLE_GRPC_REFLECTION)
+ set(REFLECTION_LIBRARY grpc++_reflection)
+endif()
+
# Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
# Libraries that use these headers should adjust the include path.
# If the "GRPC" argument is given, services are also generated.
More information about the cfe-commits
mailing list