Issue 63890
Summary [Bazel][Clang Tidy] Unable to find standard library
Labels new issue
Assignees
Reporter jathu
    ## 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).
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to