[clang-tdy] RFC: Support for plugin modules.

Dear List,

I've heard a few small discussions about this topic and they seem to be
positive so I thought I'd query it here to see what the consensus is.

The general idea is to add a `add-plugin` command line option to clang-
tidy, akin to the plugins clang supports. This will be used to load one
or more plugins that link additional ClangTidyModules to better enable
users to utilise their own custom clang-tidy checks.

Currently the only way to do that is to download the entire llvm
source, create the module and link it into clang-tidy the same way all
the built-in modules are linked.

Under this new proposal one could just get the required libraries. Then
build their module out of tree and tell clang-tidy to link at runtime
with `-add-plugin=<path-to-module>` command line option.

A typical modules source code could be as simple as this for just one

I recently had a use case at work where we wanted to write a
clang-tidy plugin but couldn't due to the lack of infrastructure and
so we wound up writing a clang static analyzer plugin instead.
Unfortunately, because LLVM-based plugin systems do not work on
Windows, this functionality still wouldn't have helped us out for our
needs. That said, I'm still 100% behind the proposal -- even with the
general plugin limitations this is a feature I have often wished for
and been surprised wasn't supported.


There is an alternative solution that is already working. With Clang tarball release you can build custom clang-tidy with additional checks outside of LLVM sources like you do with any other Clang tool after https://reviews.llvm.org/D73236 and https://reviews.llvm.org/D73300. Minimal boilerplate looks like this:

#include <clang/Config/config.h>
#include <llvm/Support/Compiler.h>
#include <clang-tidy/tool/ClangTidyMain.h>

namespace clang {
namespace tidy {

// This anchor is used to force the linker to link the CustomModule.
extern volatile int CustomModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED CustomModuleAnchorDestination =

} // tidy
} // clang

int main(int argc, const char **argv) {
return clang::tidy::clangTidyMain(argc, argv);

I think it is reasonable alternative to clang-tidy plugins that works everywhere. Anyway clang-tidy plugins are version dependent so they will work with almost the same version of Clang only.