Support for plugins for clang-tidy on Windows

We are trying to create a plugin for clang-tidy on Windows and ran into a problem that the plugin cannot use AST matchers. The linker complains that some symbols used in the plugin are undefined:

lld-link: error: undefined symbol: struct clang::ast_matchers::internal::VariadicOperatorMatcherFunc<1, 1> const clang::ast_matchers::unless
...
lld-link: error: undefined symbol: struct clang::ast_matchers::internal::VariadicOperatorMatcherFunc<2, 4294967295> const clang::ast_matchers::allOf
...

The problem seems to be that the symbols for these global variables are not exported, so plugins cannot access them.

One of the possible solutions I am trying to investigate is to extend the extract_symbols.py script so that it adds the symbols for the AST matchers to the list it generates. This approach requires that the symbols be tagged with DATA in the .def file so that they are exported correctly, which means that the output format for the script needs to be changed; the declarations of the matchers in the header file clang/include/clang/ASTMatchers/ASTMatchers.h also need to be updated so that a plugin can get the declarations as __declspec(dllimport), something like this:

#if defined(_WIN32) && defined(AST_MATCHERS_DLLIMPORT)
  #define AST_MATCHERS_LINKAGE __declspec(dllimport)
#else
  #define AST_MATCHERS_LINKAGE
#endif
...
AST_MATCHERS_LINKAGE
extern const internal::VariadicOperatorMatcherFunc<
    2, std::numeric_limits<unsigned>::max()>
    eachOf;

So, before I go too far with a patch for this approach, I would like to ask the community:

  • Is this approach suitable for the upstream?
  • Are there flaws in it that I have overlooked?
  • Are there any better ideas to solve the problem?

Thanks for any feedback!