[bazel] Respect llvm_target_list in llvm-exegesis
authorJordan Rupprecht <rupprecht@google.com>
Fri, 23 Sep 2022 02:20:04 +0000 (19:20 -0700)
committerJordan Rupprecht <rupprecht@google.com>
Fri, 23 Sep 2022 02:20:04 +0000 (19:20 -0700)
47afaf2eb02b1424a9aba241ccd02393a0cbc648 changed llvm-exegesis cmake rules
5b2f838db42ea190fdda147a33b5f0fcc8145689 ported them to bazel, but did so by adding all the `lib/{target}/*.cpp` sources in exegesis to the build rule
c7bf9d084d037aa6c8fd479be9ccdf963dc59e10 removed it, because it breaks users who don't build Mips and fail when building `lib/Mips/*.cpp`. But that in turn breaks those who *do* build the Mips target.

This should hopefully fix it for the final time by using selectively build subdirectories of exegesis target libs using llvm_target_exegesis, which is derived from llvm_targets, and is the list that can vary based on the downstream user.

I verified this builds with and without `Mips` in the `DEFAULT_TARGETS` configure list, and also double checked with `bazel query --output=build @llvm-project//llvm:Exegesis` that `lib/Mips/Target.cpp` is being included if and only if `Mips` is in the target list.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D134512

utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

index c6b7bf6..8994034 100644 (file)
@@ -2591,16 +2591,18 @@ cc_library(
     name = "Exegesis",
     srcs = glob([
         "tools/llvm-exegesis/lib/*.cpp",
-        "tools/llvm-exegesis/lib/AArch64/*.cpp",
-        "tools/llvm-exegesis/lib/PowerPC/*.cpp",
-        "tools/llvm-exegesis/lib/X86/*.cpp",
-        "tools/llvm-exegesis/lib/X86/*.h",
         # We have to include these headers here as well as in the `hdrs` below
         # to allow the `.cpp` files to use file-relative-inclusion to find
         # them, even though consumers of this library use inclusion relative to
         # `tools/llvm-exegesis/lib` with the `strip_includes_prefix` of this
         # library. This mixture appears to be incompatible with header modules.
         "tools/llvm-exegesis/lib/*.h",
+    ] + [
+        "tools/llvm-exegesis/lib/{}/*.cpp".format(t)
+        for t in llvm_target_exegesis
+    ] + [
+        "tools/llvm-exegesis/lib/{}/*.h".format(t)
+        for t in llvm_target_exegesis
     ]),
     hdrs = glob(["tools/llvm-exegesis/lib/*.h"]),
     copts = llvm_copts + ["-DHAVE_LIBPFM=1"],