Skip to content

C++ dependency pruning is broken for Windows/MSVC #14947

@lukasoyen

Description

@lukasoyen

Description of the problem:

With gcc style compiler bazel performs "dotD" dependency pruning of unused headers to limit recompilations if these unused headers were touched. As a feature this is somewhat documented in CODEBASE.md and several issues here/mails on bazel-discuss.

It is less clear if bazel does/is supposed to do the same with MSVC toolchains. It is clear that bazel uses /showIncludes to perform header inclusion checking, but unclear if it goes further. #11765 hints at header pruning on Windows being a feature.

Bugs: what's the simplest, easiest way to reproduce this bug?

On Linux/gcc the second build does nothing, on Windows/MSVC the compilation unit is rebuild.

What operating system are you running Bazel on?

Ubuntu 21.10 / Windows 10

What's the output of bazel info release?

release 5.0.0

Any other information, logs, or outputs that you want to share?

The following change in

fixes the problem, but I am not sure if that modification is safe.

 .../devtools/build/lib/rules/cpp/CppCompileActionBuilder.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
index 36c81dc5..4472d771 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
@@ -347,7 +347,7 @@ public class CppCompileActionBuilder {
     if (grepIncludes != null) {
       realMandatoryInputsBuilder.add(grepIncludes);
     }
-    if (!shouldScanIncludes && dotdFile == null) {
+    if (!shouldScanIncludes && dotdFile == null && !featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES)) {
       realMandatoryInputsBuilder.addTransitive(ccCompilationContext.getDeclaredIncludeSrcs());
       realMandatoryInputsBuilder.addTransitive(additionalPrunableHeaders);
     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1I'll work on this now. (Assignee required)area-WindowsWindows-specific issues and feature requeststeam-Rules-CPPIssues for C++ rulestype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions