diff --git a/clang-tools-extra/clangd/index/remote/README.md b/clang-tools-extra/clangd/index/remote/README.md --- a/clang-tools-extra/clangd/index/remote/README.md +++ b/clang-tools-extra/clangd/index/remote/README.md @@ -11,8 +11,9 @@ ## Building -This feature uses gRPC and Protobuf libraries, so you will need to install them. -There are two ways of doing that. +This feature uses gRPC (known to work with versions starting from 1.27.0) and +Protobuf libraries, so you will need to install them. There are two ways of +doing that. However you install dependencies, to enable this feature and build remote index tools you will need to set this CMake flag — `-DCLANGD_ENABLE_REMOTE=On`. 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 @@ -11,7 +11,7 @@ set(protobuf_MODULE_COMPATIBLE TRUE) find_package(Protobuf CONFIG REQUIRED HINTS ${GRPC_INSTALL_PATH}) message(STATUS "Using protobuf ${protobuf_VERSION}") - find_package(gRPC CONFIG REQUIRED HINTS ${GRPC_INSTALL_PATH}) + find_package(gRPC 1.27 CONFIG REQUIRED HINTS ${GRPC_INSTALL_PATH}) message(STATUS "Using gRPC ${gRPC_VERSION}") include_directories(${Protobuf_INCLUDE_DIRS}) @@ -41,6 +41,7 @@ # On macOS the libraries are typically installed via Homebrew and are not on # the system path. if (${APPLE}) + # FIXME(kirillbobyrev): Check gRPC version for macOS, too. find_program(HOMEBREW brew) # If Homebrew is not found, the user might have installed libraries # manually. Fall back to the system path. @@ -56,6 +57,18 @@ # If either library is not installed via Homebrew, fall back to the # system path. if (GRPC_HOMEBREW_RETURN_CODE EQUAL "0") + execute_process(COMMAND ${HOMEBREW} list --versions grpc + OUTPUT_VARIABLE HOMEBREW_GRPC_VERSION + RESULT_VARIABLE HOMEBREW_GRPC_VERSION_RETURN_CODE) + if (HOMEBREW_GRPC_VERSION_RETURN_CODE EQUAL "0") + # Parse MAJOR.MINOR gRPC version. + string(REGEX MATCH "grpc ([0-9]+\\.[0-9]+)" + gRPC_VERSION ${HOMEBREW_GRPC_VERSION}) + if (CMAKE_MATCH_1 VERSION_LESS "1.27") + message(FATAL_ERROR "gRPC version rerquied: >=1.27, found: ${CMAKE_MATCH_1}") + endif() + message(STATUS "Using gRPC ${CMAKE_MATCH_1}") + endif() include_directories(${GRPC_HOMEBREW_PATH}/include) find_library(GRPC_LIBRARY grpc++ @@ -78,6 +91,24 @@ IMPORTED_LOCATION ${PROTOBUF_LIBRARY}) endif() endif() + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + # Try to figure out gRPC version using APT for Debian-like Linux + # distributions. + find_program(APT apt) + if (NOT APT-NOTFOUND) + execute_process(COMMAND ${APT} policy libgrpc++-dev + OUTPUT_VARIABLE APT_GRPC_POLICY + RESULT_VARIABLE APT_GRPC_POLICY_RETURN_CODE) + if (APT_GRPC_POLICY_RETURN_CODE EQUAL "0") + # Parse MAJOR.MINOR gRPC version. + string(REGEX MATCH "Installed: ([0-9]+\\.[0-9]+)" + gRPC_VERSION ${APT_GRPC_POLICY}) + if (CMAKE_MATCH_1 VERSION_LESS "1.27") + message(FATAL_ERROR "gRPC version rerquied: >=1.27, found: ${CMAKE_MATCH_1}") + endif() + message(STATUS "Using gRPC ${CMAKE_MATCH_1}") + endif() + endif() endif() endif()