[llvm] [Bazel][Clang Tidy] Include builtin headers with clang-tidy (PR #67626)

Jordan Rupprecht via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 07:34:13 PST 2024


rupprecht wrote:

> Just checked our internal bazel build, and it's the same issue, a just-built clang without any setting up can't find system headers. We have to copy all built binaries/libraries into a certain directory structure as a separate build step to roughly match the CMake build. Either you can do that as a separate step outside of bazel, or have bazel setup the proper directory structure, but this PR is very specific to clang-tidy and I'd rather see a more complete and maintainable solution.
> 
> For example, the gn build has a [rule](https://github.com/llvm/llvm-project/blob/d39d5ccbc0c3ea6aca68e46ff9f4503b682d1ac2/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn#L87) to copy headers to a specific directory to mirror the CMake build, and by default it puts executables in `$build_dir/bin`, which also mirrors the CMake build. In contrast, this PR creates a symlink to headers that only works for clang-tidy, and sort of by happenstance as I've mentioned before, which is too hacky for my taste.
> 
> Perhaps @rupprecht has some thoughts, I believe he's been doing something similar recently.

It's definitely not at all ready (even internally), but the gist of what I have is to specify a toolchain configuration (i.e. what binaries you want to include in your toolchain, what platforms to support, etc.) and be able to use that as input to construct a runfiles tree that mirrors what an actual toolchain would look like -- so binaries would be in the same `bin` dir even if they're in different bazel packages, the headers would be in the right relative location to all the clang tools (like that GN link), etc.

I think it might be quite a while until I decouple my changes from all the internal stuff it uses. Maybe I could simplify it and put it somewhere in utils/bazel?

https://github.com/llvm/llvm-project/pull/67626


More information about the llvm-commits mailing list