summaryrefslogtreecommitdiff
path: root/runtimes
diff options
context:
space:
mode:
authorMichael Kruse <llvm-project@meinersbur.de>2025-11-12 11:50:33 +0100
committerGitHub <noreply@github.com>2025-11-12 11:50:33 +0100
commit0957656a4077b6a70f3e3dbb3a011b40d53e1a97 (patch)
tree1077c36eb7a5349ae1f17a2e07b042d4f97a2e8f /runtimes
parenta276624b2e34bfea36dd472ffc71bb4f78bbd39a (diff)
[runtimes][GTest] LLVM-independent unittests (#164794)
The LLVM-customized GTest has a dependency on LLVM to support `llvm::raw_ostream` and hence has to link to LLVMSupport. The runtimes use the LLVMSupport from the bootstrapping LLVM build. The problem is that the boostrapping compiler and the runtimes target can diverge in their ABI, even in the runtimes default build. For instance, Clang is built using gcc which uses libstdc++, but the runtimes is built by Clang which can be configured to use libcxx by default. Altough it does not use gcc, this issue has caused [flang-aarch64-libcxx](https://lab.llvm.org/buildbot/#/builders/89)) to break, and is still (again?) broken. This patch makes the runtimes' GTest independent from LLVMSupport so we do not link any runtimes component with LLVM components. Runtime projects that use GTest unittests: * flang-rt * libc * compiler-rt: Adds `gtest-all.cpp` with [GTEST_NO_LLVM_SUPPORT=1](https://github.com/llvm/llvm-project/blob/f801b6f67ea896d6e4d2de38bce9a79689ceb254/compiler-rt/CMakeLists.txt#L723) to each unittest without using `llvm_gtest`. Not touched by this PR. * openmp: Handled by #159416. Not touched for now by this PR to avoid conflict. The current state of this PR tries to reuse https://github.com/llvm/llvm-project/blob/main/third-party/unittest/CMakeLists.txt as much as possible, altough personally I would prefer to make it use "modern CMake" style. third-party/unittest/CMakeLists.txt will detect whether it is used in runtimes build and adjaust accordingly. It creates a different target for LLVM (`llvm_gtest`, NFCI) and another one for the runtimes (`runtimes_gtest`). It is not possible to reuse `llvm_gtest` for both since `llvm_gtest` is imported using `find_package(LLVM)` if configured using LLVM_INSTALL_GTEST. An alias `default_gtest` is used to select between the two. `default_gtest` could also be used for openmp which also supports standalone and [LLVM_ENABLE_PROJECTS](https://github.com/llvm/llvm-project/pull/152189) build mode.
Diffstat (limited to 'runtimes')
-rw-r--r--runtimes/CMakeLists.txt14
1 files changed, 14 insertions, 0 deletions
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index cc756da426e6..b17bd8f66536 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -256,6 +256,20 @@ endif()
# This can be used to detect whether we're in the runtimes build.
set(LLVM_RUNTIMES_BUILD ON)
+# Make GTest available to all runtimes
+# The runtime must call make_gtest_target() for it to become available. This is
+# to avoid build failures when gtest is not actually needed. In particular,
+# mingw-incomplete-sysroot is missing C++ header files that GTest needs to
+# compile.
+function(build_gtest)
+ if(TARGET default_gtest)
+ # Already available
+ return()
+ endif()
+
+ add_subdirectory("${LLVM_THIRD_PARTY_DIR}/unittest" "${CMAKE_BINARY_DIR}/third-party/runtimes_gtest")
+endfunction()
+
foreach(entry ${runtimes})
get_filename_component(projName ${entry} NAME)