[libcxx-commits] [libcxx] [libcxx] adds way for clang-tidy to be built with non-default stdlib (PR #154573)
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 20 09:49:04 PDT 2025
https://github.com/cjdb created https://github.com/llvm/llvm-project/pull/154573
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.
>From 921acdb79cd0401f91261eea4a04a0819e98505a Mon Sep 17 00:00:00 2001
From: Christopher Di Bella <cjdb at google.com>
Date: Wed, 20 Aug 2025 16:43:22 +0000
Subject: [PATCH] [libcxx] adds way for clang-tidy to be built with non-default
stdlib
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.
---
libcxx/CMakeLists.txt | 3 +++
libcxx/test/tools/clang_tidy_checks/CMakeLists.txt | 7 +++++++
2 files changed, 10 insertions(+)
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
More information about the libcxx-commits
mailing list