[libcxx-commits] [libcxx] [libcxx] adds way for clang-tidy to be built with non-default stdlib (PR #154573)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 20 09:49:50 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Christopher Di Bella (cjdb)

<details>
<summary>Changes</summary>

The default standard library for Clang on Linux is libstdc++. As such, testing libc++ with a clang-tidy that's been built with libc++ results in a host of linker errors, because the libc++ clang-tidy plugin is built with the compiler default.

This commit alleviates the problem by allowing the developer to choose which implementation the plugin should be built with.

---
Full diff: https://github.com/llvm/llvm-project/pull/154573.diff


2 Files Affected:

- (modified) libcxx/CMakeLists.txt (+3) 
- (modified) libcxx/test/tools/clang_tidy_checks/CMakeLists.txt (+7) 


``````````diff
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 85514cc7547a9..8c3b9c289f91a 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -186,6 +186,9 @@ cmake_dependent_option(LIBCXX_INSTALL_STATIC_LIBRARY
 cmake_dependent_option(LIBCXX_INSTALL_SHARED_LIBRARY
   "Install the shared libc++ library." ON
   "LIBCXX_ENABLE_SHARED;LIBCXX_INSTALL_LIBRARY" OFF)
+set(LIBCXX_BUILD_CLANG_TIDY_PLUGIN_WITH_STDLIB "" CACHE STRING
+  "Builds the clang-tidy plugin with the specified standard library implementation. Must either be blank (use compiler default), 'libc++', or 'libstdc++'.
+   This should only be set when the clang-tidy binary is built with a different standard library implementation to the compiler's default choice.")
 
 option(LIBCXX_ABI_UNSTABLE "Use the unstable ABI of libc++. This is equivalent to specifying LIBCXX_ABI_VERSION=n, where n is the not-yet-stable version." OFF)
 if (LIBCXX_ABI_UNSTABLE)
diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 521a60c0fc498..1f796fb4005b0 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -103,6 +103,13 @@ set(SOURCES
    )
 
 add_library(cxx-tidy MODULE ${SOURCES})
+if(LIBCXX_BUILD_CLANG_TIDY_PLUGIN_WITH_STDLIB)
+  if(LIBCXX_BUILD_CLANG_TIDY_PLUGIN_WITH_STDLIB STREQUAL "libc++" OR LIBCXX_BUILD_CLANG_TIDY_PLUGIN_WITH_STDLIB STREQUAL "libstdc++")
+    target_compile_options(cxx-tidy PUBLIC -stdlib=${LIBCXX_BUILD_CLANG_TIDY_PLUGIN_WITH_STDLIB})
+  else()
+    message(ERROR "${LIBCXX_BUILD_CLANG_TIDY_PLUGIN_WITH_STDLIB} must either be empty, 'libc++', or 'libstdc++'.")
+  endif()
+endif()
 target_link_libraries(cxx-tidy clangTidy)
 
 set_target_properties(cxx-tidy PROPERTIES

``````````

</details>


https://github.com/llvm/llvm-project/pull/154573


More information about the libcxx-commits mailing list