[llvm] [bazel] Use `includes` for per-target lib/Target dirs to fix -Wmicrosoft-include (PR #228282)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 17:00:08 PDT 2026


https://github.com/UebelAndre created https://github.com/llvm/llvm-project/pull/228282

This is a cleaner implementation to https://github.com/llvm/llvm-project/pull/227867 which provides a more accurate-to-cmake include path instead of silencing the error.

>From 26d69ff853015e3f364921b03f23a271c8e92fe2 Mon Sep 17 00:00:00 2001
From: UebelAndre <github at uebelandre.com>
Date: Thu, 1 Oct 2026 16:58:23 -0700
Subject: [PATCH] [bazel] Use `includes` for per-target lib/Target dirs to fix
 -Wmicrosoft-include

---
 .../llvm-project-overlay/llvm/BUILD.bazel     | 25 +++++++++++--------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index 49f67afeb1057..ea081a4bdae57 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -3998,11 +3998,7 @@ gentbl_cc_library(
         srcs = ["lib/Target/" + target["name"] + "/TargetInfo/" + target["name"] + "TargetInfo.cpp"],
         hdrs = glob(["lib/Target/" + target["name"] + "/TargetInfo/*.h"]),
         copts = llvm_copts,
-        # Workaround for https://github.com/bazelbuild/bazel/issues/3828
-        # TODO(gcmn): Remove this when upgrading to a Bazel version containing
-        # https://github.com/bazelbuild/bazel/commit/e3b7e17b05f1
         includes = ["lib/Target/" + target["name"]],
-        strip_include_prefix = "lib/Target/" + target["name"],
         deps = [
             ":" + target["name"] + "CommonTableGen",
             ":MC",
@@ -4022,8 +4018,8 @@ gentbl_cc_library(
                 # 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 the target with the `strip_includes_prefix` of this
-                # library. This mixture is likely incompatible with header modules.
+                # relative to the target directory via `includes`. This mixture is
+                # likely incompatible with header modules.
                 "lib/Target/" + target["name"] + "/MCTargetDesc/*.h",
                 "lib/Target/" + target["name"] + "/Utils/*.h",
             ],
@@ -4043,9 +4039,9 @@ gentbl_cc_library(
                 "lib/Target/" + target["name"] + "/*.h",
 
                 # FIXME: The entries below should be `textual_hdrs` instead of
-                # `hdrs`, but unfortunately that doesn't work with
-                # `strip_include_prefix`:
-                # https://github.com/bazelbuild/bazel/issues/12424
+                # `hdrs`. That was blocked by `strip_include_prefix`
+                # (https://github.com/bazelbuild/bazel/issues/12424), which this
+                # rule no longer uses.
                 #
                 # Once that issue is fixed and released, we can switch this to
                 # `textual_hdrs` and remove the feature disabling the various Bazel
@@ -4063,7 +4059,13 @@ gentbl_cc_library(
             "-header_modules",
             "-layering_check",
         ],
-        strip_include_prefix = "lib/Target/" + target["name"],
+        # `includes` rather than `strip_include_prefix`: the prefix exposes the
+        # headers through a `_virtual_includes` copy, and when a header includes
+        # one from its parent directory (MCTargetDesc/RISCVTargetStreamer.h
+        # -> "RISCV.h") clang-cl's Microsoft include rule finds the real file,
+        # sees the ordinary lookup land on the copy, and rejects the mismatch
+        # under -Wmicrosoft-include. With `includes` both lookups agree.
+        includes = ["lib/Target/" + target["name"]],
         deps = [
             ":BinaryFormat",
             ":CodeGen",
@@ -4112,7 +4114,8 @@ gentbl_cc_library(
             "-layering_check",
             "-parse_headers",
         ],
-        strip_include_prefix = "lib/Target/" + target["name"],
+        # See the `includes` note on the `UtilsAndDesc` rule above.
+        includes = ["lib/Target/" + target["name"]],
         textual_hdrs = glob(
             [
                 "lib/Target/" + target["name"] + "/*.def",



More information about the llvm-commits mailing list