Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lummax opened this issue Mar 3, 2022 · 7 comments
Closed

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

lummax opened this issue Mar 3, 2022 · 7 comments
Labels
area-Windows Windows-specific issues and feature requests P1 I'll work on this now. (Assignee required) team-Rules-CPP Issues for C++ rules type: bug

Comments

@lummax
Copy link

lummax commented Mar 3, 2022

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);
     }
@gregestren gregestren added team-Rules-CPP Issues for C++ rules untriaged area-Windows Windows-specific issues and feature requests type: bug labels Mar 7, 2022
@oquenchil oquenchil added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed untriaged labels Apr 6, 2022
@konste
Copy link
Contributor

konste commented Mar 30, 2023

@meteorcloudy
Hi Yun, it happened so that this pretty simple bug is a show stopper right at the time when we supposed to switch to Bazel build at Salesforce. Will you accept a one liner PR for it? It should be pretty safe as it only affects Windows.

@meteorcloudy
Copy link
Member

@konste Sure, I'm happy to review a PR, this sounds like a nice improvement for Windows.

@meteorcloudy
Copy link
Member

@konste Sorry, I meant the one line fix looks good to me, maybe extract the conditions to a function called shouldParseShowIncludes?

@meteorcloudy meteorcloudy added P1 I'll work on this now. (Assignee required) and removed P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) labels Mar 30, 2023
@meteorcloudy
Copy link
Member

@bazel-io fork 6.2.0

@konste
Copy link
Contributor

konste commented Mar 30, 2023

@meteorcloudy please review #17928
I also have tested it on our huge three platforms project and it does the right thing.

@konste
Copy link
Contributor

konste commented Apr 3, 2023

@meteorcloudy - PR approved! Please merge it and mark for cherry pick to 6.2.0 AND to 7.0.0-pre.20230322.4 if possible.

@meteorcloudy
Copy link
Member

/cc @kshyanashree Please cherry pick 788801a into 6.2 branch

ShreeM01 pushed a commit to ShreeM01/bazel that referenced this issue Apr 3, 2023
This fixes bazelbuild#14947.

Closes bazelbuild#17928.

PiperOrigin-RevId: 521446074
Change-Id: I4bc155f0245bc1933e86cd0b37762263437ed1fe
meteorcloudy pushed a commit that referenced this issue Apr 4, 2023
…le. (#17957)

This fixes #14947.

Closes #17928.

PiperOrigin-RevId: 521446074
Change-Id: I4bc155f0245bc1933e86cd0b37762263437ed1fe

Co-authored-by: Konstantin Erman <kerman@tableau.com>
fweikert pushed a commit to fweikert/bazel that referenced this issue May 25, 2023
This fixes bazelbuild#14947.

Closes bazelbuild#17928.

PiperOrigin-RevId: 521446074
Change-Id: I4bc155f0245bc1933e86cd0b37762263437ed1fe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Windows Windows-specific issues and feature requests P1 I'll work on this now. (Assignee required) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants