Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bazel build failed for `does not contain a toolchain for cpu 'darwin_arm64'`

when I try to build bazel, I got the below errors:

/private/var/tmp/_bazel_user/a436f601856ed4b73afb5a5d5d56a412/external/llvm_toolchain/BUILD:24:18: 
in cc_toolchain_suite rule @llvm_toolchain//:host_toolchain: 
cc_toolchain_suite '@llvm_toolchain//:host_toolchain' does not contain a toolchain for cpu 'darwin_arm64'

I'm not clear what the error means. Can anyone help me? This is my system configuration:

  1. macOS Monterey(M1 chip)
  2. bazel 5.1.1-homebrew

Thanks!

like image 370
ASimpleOne Avatar asked Oct 23 '25 16:10

ASimpleOne


2 Answers

I would request you to follow below steps

  1. Install Xcode
  2. bazel clean --expunge
  3. optionally remove all unnecesairly targets (all)
  4. run bazel build

Please reach me back if the above issue is not resolved.

like image 125
SG_Bazel Avatar answered Oct 26 '25 23:10

SG_Bazel


We observe this error quite often after an environmental change. Not sure if it's caused by an OS update or something else. However, the following recipe helped to overcome the problem without cleaning the Bazel cache, which could potentially be very expensive.

  1. Run bazel sync --configure
  2. Try again

Source: https://github.com/bazelbuild/bazel/issues/3787

sync --configure will rerun toolchains that need system configuration (like when the JDK changes or XCode is updated etc.)

Note, this answer assumes your XCode is installed properly and you opened it at least once to accept the license and let it finish installations. We also noticed that Bazel needs a full XCode not just the CLI.

like image 42
Gunnar Avatar answered Oct 26 '25 22:10

Gunnar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!