Context: https://github.com/llvm/llvm-project/issues/63890
These builtin headers are required to exist alongside clang-tidy for it to work. Specifically, the tool looks for headers relatively in ../lib/clang/{major version}/include.
Differential D158942
[bazel] Include builtin headers with clang-tidy jathu on Aug 26 2023, 12:09 PM. Authored by
Details Context: https://github.com/llvm/llvm-project/issues/63890 These builtin headers are required to exist alongside clang-tidy for it to work. Specifically, the tool looks for headers relatively in ../lib/clang/{major version}/include.
Diff Detail
Event TimelineComment Actions I've only touched the bazel config for LLVM libc, I don't feel qualified to review this patch. Comment Actions Sure, I can take a look, although I'm out at least the rest of the week. @alexfh, do you have any ideas here? The root cause of the bug seems to be that clang-based tooling looks for headers relative to where it is, assuming it doesn't find it in isystem or similar flags. There are some brief docs that mention cmake-related things: https://clang.llvm.org/docs/LibTooling.html#builtin-includes. clang works because it's defined in the same build file as the clang builtin headers, and it has some transitive dep onto it, but that might actually be accidental. I'm not sure the approach here makes sense, since it only fixes the case of using this tool directly from the blaze tree since now the directory will be placed in the right spot adjacent to clang-tidy. As soon as you copy the clang-tidy binary to install it somewhere, it will fail to find the headers if you don't also know that you have to copy that too. But, I'm also not aware of any kind of well lit path for this kind of problem. The build file tree defines lots of targets to build and produce a bunch of build artifacts, but there isn't really an equivalent to running install targets that place all those build artifacts together and in the right configuration (e.g. clang needs to go next to clang headers). That's usually done by external means.
Comment Actions @rnk @rupprecht thanks for the review!
It is true that if we copy just the binary outside of the bazel sandbox, the tool will not work. However, this is the case with installing clang-tidy from any package manager. For example, try moving your installed clang-tidy anywhere in your system — it will fail to run if the adjacent headers are not found. So, if someone does copy the binary out, I guess they will have to follow the standard of bundling the runtime headers too. Note that we are making the headers a runtime data file, so I'm assuming if you use Bazel to package the binary, it will include the headers?
I assumed the existence of a runtime data attribute in cc_binary meant this is an accepted pattern. I've configured clang-tidy to run using Bazel and the data files are successfully included in the runfiles when it runs
Comment Actions FYI, I was working for introducing clang-resources in D141755. Could we unify clang-resources in the clang? Comment Actions @chapuni this will not work since it needs to be located in the parent folder of where the binary is built — so it must exist in utils/bazel/llvm-project-overlay/clang-tools-extra/lib/clang/{major version}/include. FWIW also tried it by rebasing on your diff and get a runtime error (headers not found) Comment Actions bump @rupprecht — hoping to get a decision on this before phabricator shuts down, otherwise I'll have to recreate the PR on GitHub Comment Actions Moving this diff to GitHub since Phabricator will be shutdown Oct 1: https://github.com/llvm/llvm-project/pull/67626 cc @rupprecht |
Why does the symlink destination need the version in it?