bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.16k stars 4.05k forks source link

`external/bazel_tools` is a header search directory for all cc compile actions #8955

Closed meteorcloudy closed 5 years ago

meteorcloudy commented 5 years ago

By default, every cc_library and cc_binary depends on @bazel_tools//tools/cpp:malloc, this is causing every cc compilation to have external/bazel_tools as a header search directory. In non-sandboxed build, the compiler will always see headers from external/bazel_tools first. If you have the same header path (eg. src/main/cpp/util/file.h) in other directory, it will be ignored and the code will be compiled against the wrong header and fail with a header check error.

@oquenchil @hlopko

Related issue #8614 https://github.com/bazelbuild/bazel/pull/8954

oquenchil commented 5 years ago

This is not a bug. We intentionally add "." as an include directory for each cc_library. "malloc" happens to be a dependency that adds external/bazel_tools, but if it weren't this library, it could very well be a different implicit dependency that we add.

Then src/main/cpp/util from java_tools clashes with the one from external/bazel_tools. In any case the one from java_tools could have been renamed.

How headers and include directories work will be under going some modifications. The main bug thread to follow is this one: https://github.com/bazelbuild/bazel/issues/6790

meteorcloudy commented 5 years ago

We're seeing failure caused by this issue here again: https://buildkite.com/bazel/bazel-federation/builds/19#ee3795da-1088-4c27-b81e-2636e30e3587

meteorcloudy commented 5 years ago

https://buildkite.com/bazel/bazel-federation/builds/19#ee3795da-1088-4c27-b81e-2636e30e3587 The issue turned out to be https://github.com/bazelbuild/bazel/issues/9172, it has nothing to do with this one.