| 1 | # Clangd remote index |
| 2 | |
| 3 | Clangd uses a global index for project-wide code completion, navigation and |
| 4 | other features. For large projects, building this can take many hours and |
| 5 | keeping it loaded uses a lot of memory. |
| 6 | |
| 7 | To relieve that burden, we're building remote index — a global index |
| 8 | served on a different machine and shared between developers. This directory |
| 9 | contains code that is used as Proof of Concept for the upcoming remote index |
| 10 | feature. |
| 11 | |
| 12 | ## Building |
| 13 | |
| 14 | This feature uses gRPC and Protobuf libraries, so you will need to install them. |
| 15 | There are two ways of doing that. |
| 16 | |
| 17 | However you install dependencies, to enable this feature and build remote index |
| 18 | tools you will need to set this CMake flag — `-DCLANGD_ENABLE_REMOTE=On`. |
| 19 | |
| 20 | ### System-installed libraries |
| 21 | |
| 22 | On Debian-like systems gRPC and Protobuf can be installed from apt: |
| 23 | |
| 24 | ```bash |
| 25 | apt install libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc |
| 26 | ``` |
| 27 | |
| 28 | ### Building from sources |
| 29 | |
| 30 | Another way of installing gRPC and Protobuf is building from sources using |
| 31 | CMake (we need CMake config files to find necessary libraries in LLVM). The |
| 32 | easiest way of doing that would be to choose a directory where you want to |
| 33 | install so that the installation files are not copied to system root and you |
| 34 | can easily uninstall gRPC or use different versions. |
| 35 | |
| 36 | ```bash |
| 37 | # Get source code. |
| 38 | $ git clone -b v1.36.3 https://github.com/grpc/grpc |
| 39 | $ cd grpc |
| 40 | $ git submodule update --init |
| 41 | # Choose directory where you want gRPC installation to live. |
| 42 | $ export GRPC_INSTALL_PATH=/where/you/want/grpc/to/be/installed |
| 43 | # Build and install gRPC to ${GRPC_INSTALL_PATH} |
| 44 | $ mkdir build; cd build |
| 45 | $ cmake -DgRPC_INSTALL=ON -DCMAKE_INSTALL_PREFIX=${GRPC_INSTALL_PATH} -DCMAKE_BUILD_TYPE=Release .. |
| 46 | $ make install |
| 47 | ``` |
| 48 | |
| 49 | This [guide](https://github.com/grpc/grpc/blob/master/BUILDING.md) goes into |
| 50 | more detail on how to build gRPC from sources. |
| 51 | |
| 52 | By default, CMake will look for system-installed libraries when building remote |
| 53 | index tools so you will have to adjust LLVM's CMake invocation. The following |
| 54 | flag will inform build system that you chose this option — |
| 55 | `-DGRPC_INSTALL_PATH=${GRPC_INSTALL_PATH}`. |
| 56 | |
| 57 | ## Running |
| 58 | |
| 59 | You can run `clangd-index-server` and connect `clangd` instance to it using |
| 60 | `--remote-index-address` and `--project-root` flags. |