forked from OSchip/llvm-project
[clangd] Optionally add reflection for clangd-index-server
This was originally landed without the optional part and reverted later:
8080ea4c4b
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D98404
This commit is contained in:
parent
68e4084bf6
commit
9bcf0eff99
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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@
|
||||
|
|
|
@ -17,4 +17,6 @@ target_link_libraries(clangd-index-server
|
|||
RemoteIndexProto
|
||||
RemoteIndexServiceProto
|
||||
clangdRemoteMarshalling
|
||||
|
||||
${REFLECTION_LIBRARY}
|
||||
)
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue