[Bazel][GN] Reuse the GN LLVM config file generation code
authorReid Kleckner <rnk@google.com>
Fri, 27 May 2022 19:21:33 +0000 (12:21 -0700)
committerReid Kleckner <rnk@google.com>
Wed, 1 Jun 2022 02:40:05 +0000 (19:40 -0700)
commite2ee8bf9818189b900e65d6ea8f1ae6fc75455ce
tree10b4b416c924f545cfdce6de4885a24ba62877a5
parent3c31c68c90b9252a9607196df856f2d42f225aa0
[Bazel][GN] Reuse the GN LLVM config file generation code

Currently, the Bazel build uses static, checked in [llvm-]config.h files
in combination with global macro definitions to mimic CMake's generated
headers. This change reuses the write_cmake_config.py script from the GN
build to generate the headers from source in the same way. The purpose
is to ensure that the Bazel build stays up to date with any changes to
the CMake config files. The write_cmake_config.py script has good error
checking to ensure that unneeded, stale variables are not passed, and
that any missing variables are reported as errors.

I tried to closely follow the logic in the GN build here:
  llvm/utils/gn/secondary/llvm/include/Config/BUILD.gn
The duplication between this file and config.bzl is significant, and we
could consider going further, but I'd like to hold off on it for now.

The GN build changes are to move the write_cmake_config.py script up to
//llvm/utils/write_cmake_config.py, and update the paths accordingly.

The next logical change is to generate Clang's config.h header.

Differential Revision: https://reviews.llvm.org/D126581
llvm/utils/gn/build/write_cmake_config.gni
llvm/utils/write_cmake_config.py [moved from llvm/utils/gn/build/write_cmake_config.py with 91% similarity]
utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
utils/bazel/llvm-project-overlay/llvm/config.bzl
utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h [deleted file]
utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h [deleted file]
utils/bazel/llvm-project-overlay/llvm/write_cmake_config.bzl [new file with mode: 0644]