================ @@ -1,6 +1,14 @@ -add_clang_library(clangTidyPlugin STATIC +if(NOT CLANG_PLUGIN_SUPPORT OR NOT CLANG_LINK_CLANG_DYLIB OR ---------------- zeyi2 wrote:
AFAIK there are two ways to provide the Clang/LLVM symbols needed by the plugin: 1. Resolve them from the host executable, which may link Clang/LLVM statically. 2. Link both the host and the plugin against the same libclang-cpp and libLLVM shared libraries. These approaches are discussed in [the SSAF plugin review](https://github.com/llvm/llvm-project/pull/191401#issuecomment-4223837337). The [follow-up comment](https://github.com/llvm/llvm-project/pull/191401#issuecomment-4226613421) recommends normal library linking for the shared-library configuration. The first approach is harder for clang-tidy: its checks require tooling and dataflow implementations that the host does not necessarily contain. Linking their static dependencies into the plugin can introduce duplicate global state. Hiding those symbols is not sufficient either: a private frontend plugin registry prevents the host from finding the registered action. Avoiding both problems would require additional dependency handling. This patch therefore uses the second approach and only builds the plugin when the required shared-library configuration is enabled. ----- Historically, the plugin was linked into libclang. The [original test](https://github.com/llvm/llvm-project/commit/8f5eb56df37566187e9132fb905d7fcbd9fd4732#diff-7d0b899718292e8138360f65e49e4c80bd46c86916e35e54745ba18907b21ea73) used: ``` c-index-test -test-load-source-reparse 2 all test.cpp \ -Xclang -add-plugin -Xclang clang-tidy \ -Xclang -plugin-arg-clang-tidy \ -Xclang '-checks=-*,llvm-namespace-comment' ``` That libclang integration was [removed in 2018](https://github.com/llvm/llvm-project/commit/da113f3202bafb6ecb0a5e51c741e49b7681a91f). With this patch, users can load the plugin during normal compilation: ``` clang++ -Xclang -load -Xclang /path/to/clangTidyPlugin.so \ -Xclang -add-plugin -Xclang clang-tidy \ -Xclang -plugin-arg-clang-tidy \ -Xclang '-checks=-*,modernize-use-nullptr' \ -c test.cpp ``` The new usage explicitly loads a separate plugin into Clang while the registration name and `-checks= argument` remain the same. (To be clear: this repairs the existing clang-tidy frontend plugin and makes it dynamically loadable. It *does not restore* the libclang integration that was already removed.) https://github.com/llvm/llvm-project/pull/221961 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
