bazel: Include checking fails on windows for generated C header files (undeclared inclusion(s))

Description of the problem / feature request:

Include checking fails on windows for generated C/CPP header files. (the compilation is OK, but when Bazel checks the files afterwards, the header file is not recognized.)

Feature requests: what underlying problem are you trying to solve with this feature?

The include checking fails in CppCompileAction.java, in validateInclusions.

The line which is supposed to say the header file is ok is (around line 807):

if (allowedIncludes.contains(input)) {
  continue;
}

The problem is that the artifact execroot differs on Windows and Linux for all generated files: Edit: There seem to be a more intricate problem then just “all generated files”. It might have something to do with circular dependencies? I am trying to get a minimal example rolling.

Linux:

  • my/generated/header/path/myheader.h

Windows:

  • bazel-out/x64_windows-fastbuild/bin/my/generated/header/path/myheader.h

which causes the include check to fail.

A quick fix would be to add yet another check:

// Problem on windows with generated headers.
for (Artifact artifact : allowedIncludes) {
  if (artifact.getRootRelativePath().toString().equals(input.getExecPath().toString()))
  {
     continue checking;
  }
}

But it is not the clean way forward.

Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  • Create a header-file with a Skylark rule (if gen-rule, set output_to_bindir =True).
  • Include the file in a C file.
  • Try to compile on windows.

Edit: The problem is more intricate than this, i am trying to create a minimal example.

What operating system are you running Bazel on?

Windows

What’s the output of bazel info release?

release 0.21.0

Have you found anything relevant by searching the web?

Might be the same cause as to #3828 and #6337

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

No

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (12 by maintainers)

Commits related to this issue

Most upvoted comments

No lets close it. I open i new if the problem remains in bazel build-farm.

I debugged on this a bit, it indeed is a similar issue with #6847.

The MSVC compiler always output the absolute path of the header files it detected, but of course a file under the remote worker’s execution directory is not declared as dependency, so it failed at header check.

https://github.com/bazelbuild/bazel/commit/a1aa5c14782b38d8edf86953230f76ba2662378d provided a work around for this problem. When Bazel sees an absolute header file path, it first tries to find execroot in the file path, then converts it to a relative path by ignoring everything before execroot. This relative path would be the correct path for the file actually declared in dependency.

But the execroot used for actions in buildfarm worker doesn’t contain execroot https://github.com/bazelbuild/bazel-buildfarm/blob/master/src/main/java/build/buildfarm/instance/AbstractServerInstance.java#L274

To solve this problem, we have to append execroot to the execution directory. Also it seems we don’t have workspace name in path, that is also necessary. Basically,

D:/gh-7030/worker/default_memory_instance/operations/af056149-3fd3-4c74-9c8e-3f8880e89041/foo.h

should become

D:/gh-7030/worker/default_memory_instance/operations/af056149-3fd3-4c74-9c8e-3f8880e89041/execroot/__main__/foo.h

The idea is the buildfarm worker’s execution directory should mimic the actual Bazel execution root.