<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63890>63890</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Bazel][Clang Tidy] Unable to find standard library
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jathu
</td>
</tr>
</table>
<pre>
## System
OS: macOS 13.4.1
Arch: M2 Pro
LLVM version: 53e33807860f3b48b6f409b186a3c76de5cf1bf8
Bazel version: 6.2.1
## Problem
I'm currently building [clang-tidy using bazel](https://github.com/llvm/llvm-project/blob/2f38604c792a6cfc22eedbe76f8ade5a13304f8d/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel#L370). Using the binary results in (standard) file not found diagnostic error.
```
$ bazel build @llvm-project//clang-tools-extra/clang-tidy:clang-tidy
$ bazel-bin/external/llvm-project/clang-tools-extra/clang-tidy/clang-tidy --config-file .clang-tidy example.cpp -- -std=c++17
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "example.cpp"
No compilation database found in /Users/someone/project or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
1 error generated.
Error while processing /Users/someone/project/example.cpp.
/Users/someone/project/example.cpp:1:10: error: 'iostream' file not found [clang-diagnostic-error]
1 | #include <iostream>
| ^~~~~~~~~~
Found compiler error(s).
```
## Context
`example.cpp` file:
```C++
#include <iostream>
auto main(int /*argc*/, char** /*argv[]*/) -> int {
std::cout << "hello world" << std::endl;
return 0;
}
```
`.clang-tidy` config file:
```
Checks: >
-*,
bugprone-*,
google-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*
```
`WORKSPACE` file:
``` starlark
new_git_repository(
name = "llvm-raw",
build_file_content = "# empty",
commit = "53e33807860f3b48b6f409b186a3c76de5cf1bf8",
remote = "https://github.com/llvm/llvm-project.git",
)
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
llvm_configure(name = "llvm-project")
```
`.bazelrc` file:
```starlark
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17
build --repo_env=CC=clang++
```
Xcode info:
```
$ xcode-select --print-path
/Library/Developer/CommandLineTools
$ xcrun --show-sdk-path
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
```
## Attempts
I tried explicitly including a sysroot, but that results in a different error:
```
$ bazel-bin/external/llvm-project/clang-tools-extra/clang-tidy/clang-tidy --config-file .clang-tidy example.cpp -- -std=c++17 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk
34253 warnings and 1 error generated.
Error while processing /Users/someone/project/example.cpp.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/wchar.h:89:10: error: 'stdarg.h' file not found [clang-diagnostic-error]
89 | #include <stdarg.h>
| ^~~~~~~~~~
Suppressed 34253 warnings (34253 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWE9z4joS_zTi0mWXkcCYAwcCQ9Xsy_yplze775aSrTZoRpZckhzCHPazb0kGYkhmJpnD1qMSg6Xulvqn_vOzuXNyqxEXZHpDpusR7_zO2MVX7nfdqDTisCCUEcrg7uA8NiRbk2z56Y6wJTS8-nQHY5ZO0nE_vrTVLsx8oPDZmn7s9vbfH-ABrZNGh7kpQ8aKbFbkWc3KSVHm9SSbl-Mi56ya5QKnVT0u66LXvuHfUQ3V85SeVjte--19tqZUp_311_eEzhqoOmtRe3WAspNKSL0FMr2pFNfbxEtxgM6FsTIsRKZrQoud960jbEnohtDNVvpdV6aVaQjdKPVw-kpaa75i5QndlMqUhG5ozYo8m1SzOeV5VVeUIooSZ3ldcIFTPmYsm9SFIHTTealc0IyrXhpMzANaxQ-Ebo67NEa5B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