https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/134196

>From 528be44ebae8ea5cd7f23c51ad11c314a73f152b Mon Sep 17 00:00:00 2001
From: Reid Kleckner <r...@google.com>
Date: Fri, 28 Mar 2025 22:11:05 -0700
Subject: [PATCH 1/8] [clang] Merge gtest binaries into AllClangUnitTests

This reduces the size of the clang/unittests build directory by 64% and
my overall build dir size by 5%. Static linking is the real driving
factor here, but even if the default build configuration used shared
libraries, I don't see why we should be building so many unit test
binaries.

To make the project more approachable for new contributors, I'm
attempting to make the build a bit less resource-intensive. Build
directory size is a common complaint, and this is low-hanging fruit.
---
 clang/unittests/CMakeLists.txt                | 53 ++++++++++++++++++-
 clang/unittests/Driver/ModuleCacheTest.cpp    |  2 +-
 clang/unittests/Interpreter/CMakeLists.txt    |  2 +-
 .../Interpreter/ExceptionTests/CMakeLists.txt |  2 +-
 4 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index f3823ba309420..8d4476761e03e 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -15,11 +15,11 @@ if(CLANG_BUILT_STANDALONE)
   endif()
 endif()
 
-# add_clang_unittest(test_name file1.cpp file2.cpp)
+# add_distinct_clang_unittest(test_name file1.cpp file2.cpp)
 #
 # Will compile the list of files together and link against the clang
 # Produces a binary named 'basename(test_name)'.
-function(add_clang_unittest test_name)
+function(add_distinct_clang_unittest test_name)
   cmake_parse_arguments(ARG
     ""
     ""
@@ -47,6 +47,33 @@ function(add_clang_unittest test_name)
   target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
 endfunction()
 
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
+
+# add_clang_unittest(test_name file1.cpp file2.cpp)
+#
+# Adds unittests to the combined AllClangUnitTests binary. The unittest binary
+# is defined after adding all unittest subdirectories.
+function(add_clang_unittest test_name)
+  cmake_parse_arguments(ARG
+    ""
+    ""
+    "CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS"
+    ${ARGN})
+
+  file(RELATIVE_PATH src_prefix "${CMAKE_CURRENT_FUNCTION_LIST_DIR}" 
"${CMAKE_CURRENT_SOURCE_DIR}")
+  set(srcs_prefixed)
+  foreach(src ${ARG_UNPARSED_ARGUMENTS})
+    set(srcs_prefixed ${srcs_prefixed} "${src_prefix}/${src}")
+  endforeach()
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_SRCS ${srcs_prefixed})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_CLANG_LIBS 
${ARG_CLANG_LIBS})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LINK_LIBS 
${ARG_LINK_LIBS})
+  set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS 
${ARG_LLVM_COMPONENTS})
+endfunction()
+
 add_subdirectory(Basic)
 add_subdirectory(Lex)
 add_subdirectory(Parse)
@@ -77,3 +104,25 @@ add_subdirectory(Index)
 add_subdirectory(InstallAPI)
 add_subdirectory(Serialization)
 add_subdirectory(Support)
+
+
+# If we're doing a single merged clang unit test binary, add that target after
+# all the previous subdirectories have been processed.
+get_property(SRCS GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
+get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
+get_property(LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
+get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
+add_distinct_clang_unittest(AllClangUnitTests
+  ${SRCS}
+  CLANG_LIBS
+  ${CLANG_LIBS}
+  LINK_LIBS
+  ${LINK_LIBS}
+  LLVM_COMPONENTS
+  ${LLVM_COMPONENTS}
+)
+
+# The Tooling library has some internal headers. Make those work. If we like
+# the merged clang unit test binary, we can udpate the include paths and make
+# this the default.
+include_directories(Tooling)
diff --git a/clang/unittests/Driver/ModuleCacheTest.cpp 
b/clang/unittests/Driver/ModuleCacheTest.cpp
index 48744415647e6..7aa5047c59bd3 100644
--- a/clang/unittests/Driver/ModuleCacheTest.cpp
+++ b/clang/unittests/Driver/ModuleCacheTest.cpp
@@ -17,7 +17,7 @@ using namespace clang::driver;
 
 namespace {
 
-TEST(ModuleCacheTest, GetTargetAndMode) {
+TEST(DriverModuleCacheTest, GetTargetAndMode) {
   SmallString<128> Buf;
   Driver::getDefaultModuleCachePath(Buf);
   StringRef Path = Buf;
diff --git a/clang/unittests/Interpreter/CMakeLists.txt 
b/clang/unittests/Interpreter/CMakeLists.txt
index 9df1a4b03da47..1dda9024075a1 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_clang_unittest(ClangReplInterpreterTests
+add_distinct_clang_unittest(ClangReplInterpreterTests
   IncrementalCompilerBuilderTest.cpp
   IncrementalProcessingTest.cpp
   InterpreterTest.cpp
diff --git a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt 
b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
index eb366a860661c..dfd94d8e6442c 100644
--- a/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
+++ b/clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
@@ -3,7 +3,7 @@
 set(LLVM_REQUIRES_EH ON)
 set(LLVM_REQUIRES_RTTI ON)
 
-add_clang_unittest(ClangReplInterpreterExceptionTests
+add_distinct_clang_unittest(ClangReplInterpreterExceptionTests
   InterpreterExceptionTest.cpp
   EXPORT_SYMBOLS
 

>From 4ca1b47d81f5147aa739b5d12bd41130b2df132c Mon Sep 17 00:00:00 2001
From: Reid Kleckner <r...@google.com>
Date: Thu, 3 Apr 2025 04:43:29 +0000
Subject: [PATCH 2/8] Migrate new ParseTests unittest binary to new style

---
 clang/unittests/Parse/CMakeLists.txt | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/clang/unittests/Parse/CMakeLists.txt 
b/clang/unittests/Parse/CMakeLists.txt
index 2a31be625042e..6859efed294c8 100644
--- a/clang/unittests/Parse/CMakeLists.txt
+++ b/clang/unittests/Parse/CMakeLists.txt
@@ -1,20 +1,15 @@
-set(LLVM_LINK_COMPONENTS
-  Support
-  )
 add_clang_unittest(ParseTests
   ParseHLSLRootSignatureTest.cpp
-  )
-clang_target_link_libraries(ParseTests
-  PRIVATE
+  CLANG_LIBS
   clangAST
   clangBasic
   clangLex
   clangParse
   clangSema
-  )
-target_link_libraries(ParseTests
-  PRIVATE
+  LINK_LIBS
   LLVMTestingAnnotations
   LLVMTestingSupport
   clangTesting
+  LLVM_COMPONENTS
+  Support
   )

>From 30a54f3afbc7c90c9d00585889b8f2d832612ebb Mon Sep 17 00:00:00 2001
From: Reid Kleckner <r...@google.com>
Date: Thu, 10 Apr 2025 16:32:02 +0200
Subject: [PATCH 3/8] Interpret an empty code model as no code model, or the
 default code model

---
 clang/lib/CodeGen/BackendUtil.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7557cb8408921..b3daf81cad805 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -304,7 +304,7 @@ getCodeModel(const CodeGenOptions &CodeGenOpts) {
                            .Case("kernel", llvm::CodeModel::Kernel)
                            .Case("medium", llvm::CodeModel::Medium)
                            .Case("large", llvm::CodeModel::Large)
-                           .Case("default", ~1u)
+                           .Cases("default", "", ~1u)
                            .Default(~0u);
   assert(CodeModel != ~0u && "invalid code model!");
   if (CodeModel == ~1u)

>From 3059cfa4e5fe8edb48170adff2bafd3c5ee06101 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <r...@google.com>
Date: Thu, 10 Apr 2025 07:33:14 -0700
Subject: [PATCH 4/8] Update clang/unittests/CMakeLists.txt

Co-authored-by: Petr Hosek <pho...@google.com>
---
 clang/unittests/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index 8d4476761e03e..be4a8f9f88df8 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -123,6 +123,6 @@ add_distinct_clang_unittest(AllClangUnitTests
 )
 
 # The Tooling library has some internal headers. Make those work. If we like
-# the merged clang unit test binary, we can udpate the include paths and make
+# the merged clang unit test binary, we can update the include paths and make
 # this the default.
 include_directories(Tooling)

>From 12069f83dbf9cd853d65b4a7c319f6fcdbcff936 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <r...@google.com>
Date: Thu, 10 Apr 2025 16:39:55 +0200
Subject: [PATCH 5/8] Initialize MCs so target machine construction works when
 targets are present

---
 clang/unittests/Frontend/OutputStreamTest.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/unittests/Frontend/OutputStreamTest.cpp 
b/clang/unittests/Frontend/OutputStreamTest.cpp
index fa5d726d25290..29e6ee9740895 100644
--- a/clang/unittests/Frontend/OutputStreamTest.cpp
+++ b/clang/unittests/Frontend/OutputStreamTest.cpp
@@ -14,6 +14,7 @@
 #include "clang/FrontendTool/Utils.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/TargetSelect.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -23,6 +24,7 @@ using namespace clang::frontend;
 namespace {
 
 TEST(FrontendOutputTests, TestOutputStream) {
+  llvm::InitializeAllTargetMCs();
   auto Invocation = std::make_shared<CompilerInvocation>();
   Invocation->getPreprocessorOpts().addRemappedFile(
       "test.cc", MemoryBuffer::getMemBuffer("").release());
@@ -47,6 +49,7 @@ TEST(FrontendOutputTests, TestOutputStream) {
 }
 
 TEST(FrontendOutputTests, TestVerboseOutputStreamShared) {
+  llvm::InitializeAllTargetMCs();
   auto Invocation = std::make_shared<CompilerInvocation>();
   Invocation->getPreprocessorOpts().addRemappedFile(
       "test.cc", MemoryBuffer::getMemBuffer("invalid").release());
@@ -77,6 +80,7 @@ TEST(FrontendOutputTests, TestVerboseOutputStreamOwned) {
   std::string VerboseBuffer;
   bool Success;
   {
+    llvm::InitializeAllTargetMCs();
     auto Invocation = std::make_shared<CompilerInvocation>();
     Invocation->getPreprocessorOpts().addRemappedFile(
         "test.cc", MemoryBuffer::getMemBuffer("invalid").release());

>From 7c3e7a22310f2b9fdef9c982437ffc9005a2a6c4 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <r...@google.com>
Date: Thu, 10 Apr 2025 16:43:41 +0200
Subject: [PATCH 6/8] Fix include lint

---
 clang/unittests/Frontend/OutputStreamTest.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/unittests/Frontend/OutputStreamTest.cpp 
b/clang/unittests/Frontend/OutputStreamTest.cpp
index 29e6ee9740895..27d2d7f451d36 100644
--- a/clang/unittests/Frontend/OutputStreamTest.cpp
+++ b/clang/unittests/Frontend/OutputStreamTest.cpp
@@ -8,13 +8,12 @@
 
 #include "clang/Basic/LangStandard.h"
 #include "clang/CodeGen/BackendUtil.h"
-#include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/FrontendTool/Utils.h"
 #include "clang/Lex/PreprocessorOptions.h"
-#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;

>From db2fb7830c648d3bb2792acfd58a15241ddf378b Mon Sep 17 00:00:00 2001
From: Reid Kleckner <r...@google.com>
Date: Thu, 10 Apr 2025 19:16:24 +0200
Subject: [PATCH 7/8] Satisfy non-optional brief doc requirement for premerge

---
 clang/unittests/CMakeLists.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index be4a8f9f88df8..35f96d4a96453 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -47,10 +47,10 @@ function(add_distinct_clang_unittest test_name)
   target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
 endfunction()
 
-define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS)
-define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
-define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS)
-define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS)
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS BRIEF_DOCS "<internal 
setting>")
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS BRIEF_DOCS 
"<internal setting>")
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS BRIEF_DOCS 
"<internal setting>")
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS BRIEF_DOCS "<internal 
setting>")
 
 # add_clang_unittest(test_name file1.cpp file2.cpp)
 #

>From eba6bcea57ccb81a7ca4d44bee9895da5652c010 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <r...@google.com>
Date: Thu, 10 Apr 2025 20:47:40 +0200
Subject: [PATCH 8/8] Also set FULL_DOCS =S

---
 clang/unittests/CMakeLists.txt | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index 35f96d4a96453..b4114d419b75c 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -47,10 +47,11 @@ function(add_distinct_clang_unittest test_name)
   target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
 endfunction()
 
-define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS BRIEF_DOCS "<internal 
setting>")
-define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS BRIEF_DOCS 
"<internal setting>")
-define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS BRIEF_DOCS 
"<internal setting>")
-define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS BRIEF_DOCS "<internal 
setting>")
+set(doc_opts BRIEF_DOCS "<internal setting>" FULL_DOCS "<internal settings>")
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS ${doc_opts})
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${doc_opts})
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS ${doc_opts})
+define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS ${doc_opts})
 
 # add_clang_unittest(test_name file1.cpp file2.cpp)
 #

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to