Linux clang build issue
Hi @gzmkl ,

As per Official documentation for building from source on Ubuntu OS, we have to use GCC compiler. Please confirm the GCC compiler version that you are using. Also currently master branch tested for bazel version 5.3.0. Please use this version only and higher versions may have compatibility issues.

You can find the tested configurations of TF with GCC, Bazel etc for Linux OS [here](https://www.tensorflow.org/install/source#linux).

Please update to tested configurations and let us know if having same problem with all the logs. Thanks! Hi @gzmkl ,

The issue is probably some kind of build cache corruption that comes from Bazel and can be fixed by changing the build options. Could you please check the cpu/gpu bazelrc files [here](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/tf_sig_build_dockerfiles/devel.usertools) and try to update the build command for testing? 

Please let us know if you have any further questions. Thanks! 
 @kanglant Thanks for the pointers. We do not use remote_cache. However, with some experiments the following build command worked for us.
`bazel  build --features=-layering_check --copt=-Wno-gnu-offsetof-extensions -c opt //tensorflow/tools/pip_package:build_pip_package`

Could you please comment on `--features=-layering_check`. Is there any implication in performance in doing so? How to avoid this flag? This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Hi @mdfaijul ! Sorry for the delayed response. I was able to fix the same error on Linux by setting the environment variables CC and BAZEL_COMPILER to the actual path to clang-16, e.g., /usr/lib/llvm-16/bin/clang. My build command was:

`bazel build -s --verbose_failures --copt=-Wno-gnu-offsetof-extensions //tensorflow/tools/pip_package:build_pip_package`

With `-s`, you can see the full command line for each command prior to executing it. 

Could you please try this method and see if it fixes the error? Some other optional env variables are `CLANG_CUDA_COMPILER_PATH`, `HOST_CXX_COMPILER`, and `HOST_C_COMPILER`. Bazel does not do well with symbolic links, so please use the actual path to clang. 

Given a target T with `layering_check` enabled and a source S in T, the build will fail if S #includes a header that is not part of T itself or listed in the hdrs. We should not disable it without a good reason.  Hi @gzmkl ,

Apologies for the delayed response. Starting from TF2.13v tensorflow uses Clang16 as compiler for Linux and the instructions are updated in the official [documentation](https://www.tensorflow.org/install/source#install_clang_recommended_linux_only).

Could you please confirm whether the above instructions can be helpful. Please confirm if this is still an issue. Thanks! Hello @SuryanarayanaY @kanglant  . I tried building the TF2.13v (Release tag commit) tensorflow from source using the clang-16 compiler and I run into same issue as mentioned in the description of this ticket.

I see same issue both on Intel ICELAKE (x86) and also on GRAVITON (Arm) with the latest TF.
However, we don't face any issues when we use GCC compiler both on x86 and ARM.

This looks like a bug with BAZEL + CLANG.

Can this issue be addressed?

This issue is been there for quite a while and I have seen many people complaining about the same issue even with previous clang versions with TF.

@mdfaijul Hack to use --features=-layering_check flag with the build helps. But is there any implication in using this?
This could be a temporary workaround. > bazel build -s --verbose_failures --copt=-Wno-gnu-offsetof-extensions //tensorflow/tools/pip_package:build_pip_package

@kanglant This doesn't resolve the issue. I made sure, I set the actual path to clang and also added the config -Wno-gnu-offsetof-extensions This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. @SuryanarayanaY @kanglant  
Any further comments from your end will help us to fix this compilation issue. Also let me know, if this is something we have to report it to the LLVM/CLANG community. Hello @mraunak, could you please share some details on how you fix this issue? See the above comment.  @kanglant  With TensorFlow master branch, and on Linux, try 
 1. Set up a couple of environment variables
      export CC=/usr/lib/llvm-16/bin/clang
      export CXX=/usr/lib/llvm-16/bin/clang++
    Note: you need adjust RHS with the path where your clang (in my case version 16) is installed
2. Add the following option with your bazel build command
     --copt=-Wno-gnu-offsetof-extensions 
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Build/Install

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

Latest master branch

### Custom Code

No

### OS Platform and Distribution

Linux Ubuntu 18.04.4

### Mobile device

_No response_

### Python version

3.9.16

### Bazel version

6.1.2

### GCC/Compiler version

Ubuntu clang version 16.0.1 

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

Clang build failure (on Linux):

[1mERROR: ^[[0m/localdisk/gzhuang/work2/build/external/llvm-project/llvm/BUILD.bazel:320:11: Compiling llvm/lib/Option/ArgList.cpp failed: undeclared inclusion(s) in rule '@llvm-project//llvm:Option':
this rule is missing dependency declarations for the following files included by 'llvm/lib/Option/ArgList.cpp':
  'bazel-out/k8-opt/bin/external/llvm-project/llvm/Demangle.cppmap'
  'bazel-out/k8-opt/bin/external/llvm_terminfo/terminfo.cppmap'
  'bazel-out/k8-opt/bin/external/llvm_zlib/zlib.cppmap'
^[[32m[6,146 / 21,193]^[[0m 55 actions running


### Standalone code to reproduce the issue

```shell
Build Tensorflow from scratch with latest master branch (as of 4/24/2023) with build command

bazel --output_base=$build_dir build --config=opt --cxxopt=-stdlib=libc++ --copt=-O3 --strip=never -c opt //tensorflow/tools/pip_package:build_pip_package -j 56


Also set CC environment to clang++ (/usr/lib/llvm-16/bin/clang++)
```


### Relevant log output

```shell
See the "Behaviour" section above for the snapshot of log.
```
</details>