[clang-tools-extra] 56ac9d4 - [clangd] Add library for clangd main function
Ivan Murashko via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 11 13:50:13 PDT 2023
Author: Ivan Murashko
Date: 2023-07-11T21:48:50+01:00
New Revision: 56ac9d46a7c1468d587ccec02a781e52d0bb298a
URL: https://github.com/llvm/llvm-project/commit/56ac9d46a7c1468d587ccec02a781e52d0bb298a
DIFF: https://github.com/llvm/llvm-project/commit/56ac9d46a7c1468d587ccec02a781e52d0bb298a.diff
LOG: [clangd] Add library for clangd main function
The diff adds a library and header for clangd main function. That change allows to create custom builds for clangd outside the main LLVM repo. The diff also allows to use build system different from CMake to build clangd. The main reason for such change is an ability to use custom clang-tidy modules (created outside LLVM repo).
Test Plan:
```
ninja clangd
```
also check that necessary libs are installed aka
```
ninja install
...
ls <install folder>/lib/libclangdMain.a
```
Differential Revision: https://reviews.llvm.org/D145302
Added:
clang-tools-extra/clangd/tool/ClangdMain.h
clang-tools-extra/clangd/tool/ClangdToolMain.cpp
Modified:
clang-tools-extra/clangd/tool/CMakeLists.txt
clang-tools-extra/clangd/tool/ClangdMain.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/tool/CMakeLists.txt b/clang-tools-extra/clangd/tool/CMakeLists.txt
index 5a1556b813b595..223bd7c606f7d1 100644
--- a/clang-tools-extra/clangd/tool/CMakeLists.txt
+++ b/clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -1,6 +1,13 @@
-add_clang_tool(clangd
+# Needed by LLVM's CMake checks because this file defines multiple targets.
+set(LLVM_OPTIONAL_SOURCES ClangdToolMain.cpp)
+
+add_clang_library(clangdMain
ClangdMain.cpp
Check.cpp
+ )
+
+add_clang_tool(clangd
+ ClangdToolMain.cpp
$<TARGET_OBJECTS:obj.clangDaemonTweaks>
)
@@ -13,7 +20,7 @@ if(CLANGD_BUILD_XPC)
list(APPEND CLANGD_XPC_LIBS "clangdXpcJsonConversions" "clangdXpcTransport")
endif()
-clang_target_link_libraries(clangd
+clang_target_link_libraries(clangdMain
PRIVATE
clangAST
clangBasic
@@ -25,14 +32,14 @@ clang_target_link_libraries(clangd
clangToolingCore
clangToolingRefactoring
clangToolingSyntax
- )
-
-target_link_libraries(clangd
- PRIVATE
clangTidy
-
clangDaemon
clangdRemoteIndex
clangdSupport
${CLANGD_XPC_LIBS}
)
+
+clang_target_link_libraries(clangd
+ PRIVATE
+ clangdMain
+ )
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index ab5169171e3d87..27f70a527cd3cb 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "ClangdMain.h"
#include "ClangdLSPServer.h"
#include "CodeComplete.h"
#include "Compiler.h"
@@ -710,8 +711,6 @@ class FlagsConfigProvider : public config::Provider {
}
};
} // namespace
-} // namespace clangd
-} // namespace clang
enum class ErrorResultCode : int {
NoShutdownRequest = 1,
@@ -719,10 +718,7 @@ enum class ErrorResultCode : int {
CheckFailed = 3
};
-int main(int argc, char *argv[]) {
- using namespace clang;
- using namespace clang::clangd;
-
+int clangdMain(int argc, char *argv[]) {
llvm::InitializeAllTargetInfos();
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
llvm::sys::AddSignalHandler(
@@ -1041,3 +1037,6 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
return ExitCode;
}
+
+} // namespace clangd
+} // namespace clang
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.h b/clang-tools-extra/clangd/tool/ClangdMain.h
new file mode 100644
index 00000000000000..bd0f51aac83bb3
--- /dev/null
+++ b/clang-tools-extra/clangd/tool/ClangdMain.h
@@ -0,0 +1,19 @@
+//===--- ClangdMain.h - clangd main function ------------------------===//
+//
+// Part of the LLVM Project, 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+
+namespace clang {
+namespace clangd {
+// clangd main function (clangd server loop)
+int clangdMain(int argc, char *argv[]);
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
diff --git a/clang-tools-extra/clangd/tool/ClangdToolMain.cpp b/clang-tools-extra/clangd/tool/ClangdToolMain.cpp
new file mode 100644
index 00000000000000..b62ff362bd2a96
--- /dev/null
+++ b/clang-tools-extra/clangd/tool/ClangdToolMain.cpp
@@ -0,0 +1,13 @@
+//===--- ClangdToolMain.cpp - clangd main function ------------------------===//
+//
+// Part of the LLVM Project, 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "ClangdMain.h"
+
+int main(int argc, char **argv) {
+ return clang::clangd::clangdMain(argc, argv);
+}
More information about the cfe-commits
mailing list