-
Notifications
You must be signed in to change notification settings - Fork 4.4k
C++ dependency pruning is broken for Windows/MSVC #14947
Description
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?
- Clone https://github.com/lummax/bazel-header-recompilation-reproducer
- run
bazel build :main -s - modify
dead.hwhich may be used bymainbut is never included frommain.cpp - rerun
bazel build :main -s
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
bazel/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
Line 350 in 6c955a5
| if (!shouldScanIncludes && dotdFile == null) { |
.../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);
}