# Build your own Clangd/Clangd-indexer/Clangd-index-server > It's so hard to build the clangd with grpc from the source... > Therefore, hope this blog can help you to build clangd. ### How to build clangd Follow the step in https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm ``` sh $ git clone --depth 1 https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cmake -S llvm -B build -G Ninja \ -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra' \ -DCMAKE_BUILD_TYPE=Release $ cmake --build build --target 'clang;clang-tidy;clang-format;clangd' $ ./build/bin/clangd --version clangd version 17.0.1 (https://github.com/llvm/llvm-project.git e19b7dc36bc047b9eb72078d034596be766da350) Features: linux Platform: x86_64-unknown-linux-gnu ``` ### How to build clangd with grpc * If you want to use remote index server, must build the grpc build * Target build is clangd, clangd-index-server #### Build gRpc We need to add grpc into clangd. Therefore, we need to install grpc first. The step to build grpc you can follow the https://github.com/grpc/grpc/blob/master/BUILDING.md ``` sh $ git clone --recurse-submodules -b v1.58.1 --depth 1 --shallow-submodules https://github.com/grpc/grpc grpc-v1.58.1 $ cd grpc-v1.58.1 $ mkdir -p cmake/build $ cd cmake/build $ export MY_INSTALL_DIR=$HOME/.local # official suggest we build in our local folder $ export CC=$(which gcc); export CXX=$(which g++) $ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR ../../ $ cmake --build . $ cmake --build . --target install # install the library to $MY_INSTALL_DIR ``` If you don't have ninja, use make is also fine. ``` sh $ cmake -DCMAKE_BUILD_TYPE=Release -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR ../../ $ make -j $ make install # install the library to $MY_INSTALL_DIR ``` #### Build clangd with gRpc To build the clangd with grpc. We follow the guide from https://github.com/llvm/llvm-project/tree/main/clang-tools-extra/clangd/index/remote 1. Add -DCLANGD_ENABLE_REMOTE=On 2. Add -DGRPC_INSTALL_PATH=${GRPC_INSTALL_PATH} * GPRC_INSTALL_PATH is where the gRpc install. * it's $HOME/.local in the previous grpc build. Step to build clangd with grpc: ``` sh $ git clone --depth 1 https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra' -DCMAKE_BUILD_TYPE=Release -DCLANGD_ENABLE_REMOTE=On -DGRPC_INSTALL_PATH=$HOME/.local $ cmake --build build --target 'clang;clang-tidy;clang-format;clangd;clangd-indexer;clangd-index-server;llvm-symbolizer;llvm-config' ``` ![](https://hackmd.io/_uploads/SkjAKQJxp.png)