[clang-tools-extra] [llvm] [bazel] Add clangd as a library support (PR #81556)

via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 14 14:27:52 PDT 2024


https://github.com/josh11b updated https://github.com/llvm/llvm-project/pull/81556

>From e2b83f086e51d7144d8e6ac1d1850300de55f01f Mon Sep 17 00:00:00 2001
From: Josh L <github-llvm at technomagi.com>
Date: Mon, 12 Feb 2024 22:59:21 +0000
Subject: [PATCH 1/4] Add bazel support for clangd as a library.

---
 clang-tools-extra/clangd/Transport.h          |  1 -
 .../clang-tools-extra/clangd/BUILD.bazel      | 45 +++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel

diff --git a/clang-tools-extra/clangd/Transport.h b/clang-tools-extra/clangd/Transport.h
index 4e80ea95b8537d..f17441cfc1ef22 100644
--- a/clang-tools-extra/clangd/Transport.h
+++ b/clang-tools-extra/clangd/Transport.h
@@ -18,7 +18,6 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H
 
-#include "Feature.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/raw_ostream.h"
diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
new file mode 100644
index 00000000000000..0e25dd1c166560
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
@@ -0,0 +1,45 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])
+
+cc_library(
+    name = "clangd_library",
+    srcs = [
+        "JSONTransport.cpp",
+        "Protocol.cpp",
+        "URI.cpp",
+        "index/SymbolID.cpp",
+        "support/Logger.cpp",
+        "support/Trace.cpp",
+        "support/MemoryTree.cpp",
+        "support/Context.cpp",
+        "support/Cancellation.cpp",
+        "support/ThreadCrashReporter.cpp",
+        "support/Shutdown.cpp",
+    ],
+    hdrs = [
+        "Transport.h",
+        "Protocol.h",
+        "URI.h",
+        "LSPBinder.h",
+        "index/SymbolID.h",
+        "support/Function.h",
+        "support/Cancellation.h",
+        "support/ThreadCrashReporter.h",
+        "support/Logger.h",
+        "support/Trace.h",
+        "support/MemoryTree.h",
+        "support/Context.h",
+        "support/Shutdown.h",
+    ],
+    includes = ["."],
+    deps = [
+        "//llvm:Support",
+        "//clang:basic",
+        "//clang:index",
+    ],
+)

>From 9dc8c8e9196fa51a9f687fd6542dc8ca0de70173 Mon Sep 17 00:00:00 2001
From: Josh L <github-llvm at technomagi.com>
Date: Thu, 14 Mar 2024 21:02:52 +0000
Subject: [PATCH 2/4] Implement suggestions from review

---
 .../clang-tools-extra/clangd/BUILD.bazel                     | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
index 0e25dd1c166560..c1d24058e21a1d 100644
--- a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
@@ -2,12 +2,13 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-package(default_visibility = ["//visibility:public"])
+package(features = ["layering_check"],
+        default_visibility = ["//visibility:public"])
 
 licenses(["notice"])
 
 cc_library(
-    name = "clangd_library",
+    name = "clangDaemon",
     srcs = [
         "JSONTransport.cpp",
         "Protocol.cpp",

>From ca0ab60e98b51a80718b56fb92b8e51cb60112f7 Mon Sep 17 00:00:00 2001
From: Josh L <github-llvm at technomagi.com>
Date: Thu, 14 Mar 2024 21:17:57 +0000
Subject: [PATCH 3/4] Checkpoint progress.

---
 clang-tools-extra/clangd/Transport.h                          | 1 +
 .../llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/Transport.h b/clang-tools-extra/clangd/Transport.h
index f17441cfc1ef22..4e80ea95b8537d 100644
--- a/clang-tools-extra/clangd/Transport.h
+++ b/clang-tools-extra/clangd/Transport.h
@@ -18,6 +18,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H
 
+#include "Feature.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/raw_ostream.h"
diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
index c1d24058e21a1d..490135823e072e 100644
--- a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
@@ -2,8 +2,8 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-package(features = ["layering_check"],
-        default_visibility = ["//visibility:public"])
+package(default_visibility = ["//visibility:public"],
+        features = ["layering_check"])
 
 licenses(["notice"])
 

>From 86b82c8b919bac1d4969a1f3121302678c1e2a8b Mon Sep 17 00:00:00 2001
From: Josh L <github-llvm at technomagi.com>
Date: Thu, 14 Mar 2024 21:26:24 +0000
Subject: [PATCH 4/4] Incorporate more feedback

---
 .../clang-tools-extra/clangd/BUILD.bazel                     | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
index 490135823e072e..cd9759b4adb661 100644
--- a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
@@ -7,8 +7,11 @@ package(default_visibility = ["//visibility:public"],
 
 licenses(["notice"])
 
+# TODO: Pick up other files for more complete functionality, to match
+# clangd/CMakeLists.txt. This might look something like
+# glob(["*.cpp", "dir/**/*.cpp", ...]).
 cc_library(
-    name = "clangDaemon",
+    name = "ClangDaemon",
     srcs = [
         "JSONTransport.cpp",
         "Protocol.cpp",



More information about the cfe-commits mailing list