diff --git a/clang-tools-extra/clangd/index/remote/server/CMakeLists.txt b/clang-tools-extra/clangd/index/remote/server/CMakeLists.txt --- a/clang-tools-extra/clangd/index/remote/server/CMakeLists.txt +++ b/clang-tools-extra/clangd/index/remote/server/CMakeLists.txt @@ -9,6 +9,11 @@ RemoteIndexServiceProto ) +if (ENABLE_GRPC_REFLECTION) + set(REFLECTION_LIBRARY grpc++_reflection) + add_definitions(-DENABLE_GRPC_REFLECTION) +endif() + target_link_libraries(clangd-index-server PRIVATE clangDaemon @@ -17,4 +22,6 @@ 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 --- a/clang-tools-extra/clangd/index/remote/server/Server.cpp +++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp @@ -35,6 +35,10 @@ #include #include +#ifdef ENABLE_GRPC_REFLECTION +#include +#endif + namespace clang { namespace clangd { namespace remote { @@ -313,6 +317,9 @@ RemoteIndexServer Service(Index, IndexRoot); grpc::EnableDefaultHealthCheckService(true); +#ifdef 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 --- a/llvm/cmake/modules/FindGRPC.cmake +++ b/llvm/cmake/modules/FindGRPC.cmake @@ -18,10 +18,14 @@ # gRPC CMake CONFIG gives the libraries slightly odd names, make them match # the conventional system-installed names. - set_target_properties(protobuf::libprotobuf PROPERTIES IMPORTED_GLOBAL TRUE) - 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_target_properties(protobuf::libprotobuf PROPERTIES IMPORTED_GLOBAL TRUE) + add_library(protobuf ALIAS protobuf::libprotobuf) set(GRPC_CPP_PLUGIN $) set(PROTOC ${Protobuf_PROTOC_EXECUTABLE}) @@ -71,6 +75,11 @@ 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)