carbon-lang
carbon-lang copied to clipboard
Unable to compile with bazel
$ bazel run //explorer -- ./explorer/testdata/basic_syntax/print.carbon
INFO: Invocation ID: b5172173-67be-4b3a-82b3-1d5168eca9ac
INFO: Repository bazel_cc_toolchain instantiated at:
/home/gonzo/github/carbon-lang/WORKSPACE:41:26: in <toplevel>
Repository rule configure_clang_toolchain defined at:
/home/gonzo/github/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl:147:44: in <toplevel>
ERROR: An error occurred during the fetch of repository 'bazel_cc_toolchain':
Traceback (most recent call last):
File "/home/gonzo/github/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl", line 120, column 18, in _configure_clang_toolchain_impl
clang = clang.realpath.dirname.get_child("clang++")
Error: /home/gonzo/.cache/bazel/_bazel_gonzo/6c39f1f380369b8f90f4c7a534ab2325/external/bazel_cc_toolchain/clang-12 (No such file or directory)
ERROR: /home/gonzo/github/carbon-lang/WORKSPACE:41:26: fetching configure_clang_toolchain rule //external:bazel_cc_toolchain: Traceback (most recent call last):
File "/home/gonzo/github/carbon-lang/bazel/cc_toolchains/clang_configuration.bzl", line 120, column 18, in _configure_clang_toolchain_impl
clang = clang.realpath.dirname.get_child("clang++")
Error: /home/gonzo/.cache/bazel/_bazel_gonzo/6c39f1f380369b8f90f4c7a534ab2325/external/bazel_cc_toolchain/clang-12 (No such file or directory)
ERROR: /home/gonzo/github/carbon-lang/explorer/BUILD:31:10: //explorer:explorer depends on @bazel_cc_toolchain//:bazel_cc_toolchain in repository @bazel_cc_toolchain which failed to fetch. no such package '@bazel_cc_toolchain//': /home/gonzo/.cache/bazel/_bazel_gonzo/6c39f1f380369b8f90f4c7a534ab2325/external/bazel_cc_toolchain/clang-12 (No such file or directory)
ERROR: Analysis of target '//explorer:explorer' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.355s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (39 packages loaded, 131 targets configured)
FAILED: Build did NOT complete successfully (39 packages loaded, 131 targets configured)
Fetching @local_config_cc; fetching
Fetching @llvm-project; fetching
I tried cleaning and switching over to export CXX=clang++-12 but I don't know how to reconfigure this project. I usually build with clang++-15 from trunk. Any help?
There are notes on using LLVM here that may be useful: https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/contribution_tools.md#clang-and-llvm
Note in particular we use some non-default flags for compilation.
That said -- right now https://source.corp.google.com/piper///depot/google3/third_party/carbon/lang/bazel/cc_toolchains/clang_configuration.bzl only detects based on CC, not CXX. If you're trying to get it to work, either adding clang to your PATH or setting CC should work.
I feel like we should probably add CXX to detection, though. The above is just a workaround.
The link you uploaded needs authentication, but still the env variables workaround doesn't work
@cdecompilador
After installing all build tools, you can check that some tools are installed correctly and appended to PATH (make sure that you followed adding PATHs):
which clang-format # if you used brew on macOS and followed the docs, it'd return something like "/usr/local/opt/llvm/bin/clang-format",
which clang-tidy
If that still does not help, you can try cleaning build outputs and try again:
bazel clean
https://docs.bazel.build/versions/main/user-manual.html#clean
Also having this issue even after ensuring that the clang tools are correct (from the LLVM directory), and starting fresh with bazel clean.
It may be helpful to ask on #build-help on Discord (for responsiveness). There are a few things to check first, just to be sure of which binary is in use:
grep llvm_bindir bazel-execroot/external/bazel_cc_toolchain/clang_detected_variables.bzl- This will tell me the actual detected path.
- In general, looking for paths like
/path/to/homebrew/opt/llvm/bin/clang - Try in order, noting the first success:
echo $CC-- should either be unset or the expected pathwhich clang-13-- should either not be found, or be the expected path- I think this may need to be updated, it probably shouldn't still check for clang-13, but it does and thus is a possible cause since brew is probably clang-14 now.
which clang-- the last fallback, which should be the expected path
We've added docs to help troubleshoot build issues. I'm closing this issue because I think there's a limit to how much we can detect here right now.