Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davidzchen opened this issue Mar 26, 2024 · 13 comments
Open

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

davidzchen opened this issue Mar 26, 2024 · 13 comments
Labels
explorer Action items related to Carbon explorer code

Comments

@davidzchen
Copy link

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

@davidzchen davidzchen added the explorer Action items related to Carbon explorer code label Mar 26, 2024
@jonmeow
Copy link
Contributor

jonmeow commented Mar 26, 2024

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

This comment was marked as off-topic.

@justzh

This comment was marked as abuse.

@justzh

This comment was marked as off-topic.

@justzh

This comment was marked as off-topic.

@justzh

This comment was marked as off-topic.

@justzh

This comment was marked as off-topic.

@justzh

This comment was marked as duplicate.

@chandlerc
Copy link
Contributor

@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

This comment was marked as spam.

@davidzchen
Copy link
Author

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

$ brew install \
  bazelisk \
  gh \
  llvm \
  [email protected] \
  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
Copy link
Author

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
Copy link
Contributor

jonmeow commented Apr 8, 2024

$ 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}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
explorer Action items related to Carbon explorer code
Projects
None yet
Development

No branches or pull requests

4 participants