ASimpleOne
ASimpleOne

Reputation: 41

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!

Upvotes: 4

Views: 3621

Answers (2)

Gunnar
Gunnar

Reputation: 2359

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.

Upvotes: 1

SG_Bazel
SG_Bazel

Reputation: 355

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.

Upvotes: 2

Related Questions