carbon-language / carbon-lang

Carbon Language's main repository: documents, design, implementation, and related tools. (NOTE: Carbon Language is experimental; see README)
http://docs.carbon-lang.dev/
Other
32.27k stars 1.47k forks source link

llvm-ar not found when building with clang-tidy #3812

Closed davidzchen closed 4 days ago

davidzchen commented 5 months ago

Description of the bug:

Building Carbon with the clang-tidy configuration results in an error reporting that "llvm-ar not found in PATH or adjacent to clang"

What did you do, or what's a simple way to reproduce the bug?

Fresh check-out of the repo and then run:

bazel build --config=clang-tidy //...

What did you expect to happen?

The build to succeed.

What actually happened?

$ bazel build --config=clang-tidy //...
Starting local Bazel server and connecting to it...
WARNING: ignoring JAVA_TOOL_OPTIONS in environment.
INFO: Invocation ID: bd9757e5-f9b5-4af3-b441-9582d5293a96
INFO: Repository _main~clang_toolchain_extension~bazel_cc_toolchain instantiated at:
  <builtin>: in <toplevel>
Repository rule configure_clang_toolchain defined at:
  /Users/dzc/Repos/github/OpenEmu/OpenEmu/carbon-language/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl:229:44: in <toplevel>
ERROR: An error occurred during the fetch of repository '_main~clang_toolchain_extension~bazel_cc_toolchain':
   Traceback (most recent call last):
        File "/Users/dzc/Repos/github/OpenEmu/OpenEmu/carbon-language/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl", line 202, column 17, in _configure_clang_toolchain_impl
                fail("`llvm-ar` not found in PATH or adjacent to clang")
Error in fail: `llvm-ar` not found in PATH or adjacent to clang
ERROR: <builtin>: fetching configure_clang_toolchain rule //:_main~clang_toolchain_extension~bazel_cc_toolchain: Traceback (most recent call last):
        File "/Users/dzc/Repos/github/OpenEmu/OpenEmu/carbon-language/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl", line 202, column 17, in _configure_clang_toolchain_impl
                fail("`llvm-ar` not found in PATH or adjacent to clang")
Error in fail: `llvm-ar` not found in PATH or adjacent to clang
WARNING: Target pattern parsing failed.
ERROR: Skipping '//...': error loading package under directory '': no such package '@@_main~clang_toolchain_extension~bazel_cc_toolchain//': `llvm-ar` not found in PATH or adjacent to clang
ERROR: error loading package under directory '': no such package '@@_main~clang_toolchain_extension~bazel_cc_toolchain//': `llvm-ar` not found in PATH or adjacent to clang
INFO: Elapsed time: 6.924s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
FAILED:
    Fetching repository @@bazel_features~; Patching repository

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

No response

jonmeow commented 5 months ago

This is a common issue for os-provided llvm installs, particularly when you're using an older macos system install (from "/Users" I assume this is macos). See contribution tools for advice on installing llvm.

If that doesn't address your issue, please provide the output of these troubleshooting commands:

echo $CC
which clang
which clang-16
clang --version
grep llvm_bindir $(bazel info workspace)/bazel-execroot/external/bazel_cc_toolchain/clang_detected_variables.bzl

# If on macOS:
brew --prefix llvm
justzh commented 4 months ago

I think I know what went wrong here; there needs to be a semi-colon for the end of line 364 or 367, I'm not sure. Let me know how this solution goes.

justzh commented 4 months ago

In that case, delete every single goddamn semicolon from this goddamn file. See if that works.

justzh commented 4 months ago

Cool. #Mark issue as resolved

justzh commented 4 months ago

Sorry if I seem crazy, but I'm not sure what's going on for this issue.

justzh commented 4 months ago

I'm on a MacBook btw.

justzh commented 4 months ago

You just need to run npm update or something like that. Please mark this issue as resolved.

justzh commented 4 months ago

Am I wrong?

chandlerc commented 4 months ago

@justzh - Please keep comments on PRs and issues constructive and on-topic. I'm hiding yours, but you've had warnings now and so I will block if this continues.

Rapid-fire asking of questions, or speaking for the reporter isn't a constructive or appropriate use of issues.

justzh commented 4 months ago

I found the issue. Please look at line 32 and correct your code, thanks.

davidzchen commented 4 months ago

Sorry for the delay. I followed the instructions at Contribution Tools but I am still getting the same error:

$ brew install \
  bazelisk \
  gh \
  llvm \
  python@3.10 \
  pre-commit
---snipped---
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
$ bazel test //...:all
2024/04/07 15:34:48 Downloading https://releases.bazel.build/7.1.0/release/bazel-7.1.0-darwin-arm64...
Downloading: 61 MB out of 61 MB (100%)
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
WARNING: ignoring JAVA_TOOL_OPTIONS in environment.
INFO: Invocation ID: 9f0eb370-661d-495e-8e64-61ba0554c834
INFO: Repository _main~clang_toolchain_extension~bazel_cc_toolchain instantiated at:
  <builtin>: in <toplevel>
Repository rule configure_clang_toolchain defined at:
  /Users/dzc/Repos/github/carbon-language/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl:229:44: in <toplevel>
ERROR: An error occurred during the fetch of repository '_main~clang_toolchain_extension~bazel_cc_toolchain':
   Traceback (most recent call last):
        File "/Users/dzc/Repos/github/carbon-language/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl", line 202, column 17, in _configure_clang_toolchain_impl
                fail("`llvm-ar` not found in PATH or adjacent to clang")
Error in fail: `llvm-ar` not found in PATH or adjacent to clang
ERROR: <builtin>: fetching configure_clang_toolchain rule //:_main~clang_toolchain_extension~bazel_cc_toolchain: Traceback (most recent call last):
        File "/Users/dzc/Repos/github/carbon-language/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl", line 202, column 17, in _configure_clang_toolchain_impl
                fail("`llvm-ar` not found in PATH or adjacent to clang")
Error in fail: `llvm-ar` not found in PATH or adjacent to clang
ERROR: Skipping '//...:all': error loading package under directory '': no such package '@@_main~clang_toolchain_extension~bazel_cc_toolchain//': `llvm-ar` not found in PATH or adjacent to clang
ERROR: error loading package under directory '': no such package '@@_main~clang_toolchain_extension~bazel_cc_toolchain//': `llvm-ar` not found in PATH or adjacent to clang
INFO: Elapsed time: 2.995s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Couldn't start the build. Unable to run tests
davidzchen commented 4 months ago

Outputs for the requested commands:

$ which $CC
# no output
$ which clang
/usr/bin/clang
$ which clang-16
clang-16 not found
$ clang --version
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ grep llvm_bindir $(bazel info workspace)/bazel-execroot/external/bazel_cc_toolchain/clang_detected_variables.bzl
INFO: Invocation ID: ce012800-43b0-4d82-b9f5-9ddb32bfb8fe
grep: /Users/dzc/Repos/github/carbon-language/carbon-lang/bazel-execroot/external/bazel_cc_toolchain/clang_detected_variables.bzl: No such file or directory
$ brew --prefix llvm
/opt/homebrew/opt/llvm
jonmeow commented 4 months ago
$ which clang
/usr/bin/clang

It looks like you need to add brew's llvm to your path, as described at https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/contribution_tools.md#macos:

# For `brew`, `gh`, and other tools:
export PATH="${HOME}/.brew/bin:${PATH}"
# For `llvm`:
export PATH="$(brew --prefix llvm)/bin:${PATH}"
github-actions[bot] commented 5 days ago

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the inactive label. The long term label can also be added for issues which are expected to take time.

This issue is labeled inactive because the last activity was over 90 days ago.

jonmeow commented 4 days ago

Closing, please let us know if the PATH fixes don't address this for you.