From e444b0aace8028b21b07707c28921e9fb9758b35 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Wed, 10 Apr 2024 02:29:25 +0530 Subject: [PATCH] Toolchain+Docs: Improve the way to enable clangd Allowing an environment variable to enable/disable the build for clangd and other toolchains will improve the developer-experience than reconfiguring and building the toolchain manually. Now you will have to call the command as following $ CLANG_ENABLE_CLANGD=ON Toolchain/BuildClang.sh --- Documentation/AdvancedBuildInstructions.md | 5 +---- Toolchain/CMake/LLVMConfig.cmake | 8 +++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Documentation/AdvancedBuildInstructions.md b/Documentation/AdvancedBuildInstructions.md index 6fa0d42b698..1bd576161f2 100644 --- a/Documentation/AdvancedBuildInstructions.md +++ b/Documentation/AdvancedBuildInstructions.md @@ -224,10 +224,7 @@ clangd that are aware of SerenityOS as a valid target. These tools will be insta the script. Pointing your editor's plugins to the custom-built clang tools and a ``compile_commands.json`` from a clang build of Serenity can enable richer error reporting than the tools that are installed for the build host. -To enable building clangd as part of the clang toolchain, set ``CLANG_ENABLE_CLANGD`` to ON in -``Toolchain/CMake/LLVMConfig.cmake`` before running BuildClang.sh. If you already built the clang toolchain and would like to -enable the custom clangd build, change the CMake cache variable ``CLANG_ENABLE_CLANGD`` to ON in ``Toolchain/Build/clang/llvm`` -and re-install with ``cd Toolchain/Build/clang/llvm && cmake ../../../Tarballs/llvm-project-$LLVM_VERSION.src/llvm -DCLANG_ENABLE_CLANGD=ON && ninja install/strip``, where $LLVM_VERSION should be tab-completable in your shell. +To enable building clangd as part of the clang toolchain, set ``CLANG_ENABLE_CLANGD`` environment variable to ``ON``, then run ``Toolchain/BuildClang.sh``. ## Clang-format updates diff --git a/Toolchain/CMake/LLVMConfig.cmake b/Toolchain/CMake/LLVMConfig.cmake index 1c5316f2806..cb6f550f8dc 100644 --- a/Toolchain/CMake/LLVMConfig.cmake +++ b/Toolchain/CMake/LLVMConfig.cmake @@ -27,7 +27,13 @@ set(LLVM_INSTALL_UTILS ON CACHE BOOL "") set(LLVM_INSTALL_TOOLCHAIN_ONLY OFF CACHE BOOL "Don't install headers, utils, and tools") set(LLVM_INSTALL_BINUTILS_SYMLINKS OFF CACHE BOOL "") -set(CLANG_ENABLE_CLANGD OFF CACHE BOOL "") +if(DEFINED ENV{CLANG_ENABLE_CLANGD} AND "$ENV{CLANG_ENABLE_CLANGD}" STREQUAL "ON") + message(STATUS "Enabling clangd as a part of toolchain build") + set(CLANG_ENABLE_CLANGD ON CACHE BOOL "" FORCE) +else() + message(STATUS "Disabling clangd as a part of toolchain build") + set(CLANG_ENABLE_CLANGD OFF CACHE BOOL "" FORCE) +endif() foreach(target x86_64-pc-serenity;aarch64-pc-serenity;riscv64-pc-serenity) list(APPEND targets "${target}")