Mac M1 使用 Bazel 低版本

Posted by Vove on February 20, 2022

在mac m1芯片 上使用 bazel 遇到问题:

1
2
3
4
5
ERROR: The project you're trying to build requires Bazel 3.1.0 (specified in /Users/libra/Projects/tensorflow/.bazelversion), but it wasn't found in /opt/homebrew/Cellar/bazel/5.0.0/libexec/bin. <br>
Bazel binaries for all official releases can be downloaded from here:
  https://github.com/bazelbuild/bazel/releases <br>
You can download the required version directly using this command:
  (cd "/opt/homebrew/Cellar/bazel/5.0.0/libexec/bin" && curl -fLO https://releases.bazel.build/3.1.0/release/bazel-3.1.0-darwin-arm64 && chmod +x bazel-3.1.0-darwin-arm64)

按照提示:下载 bazel-3.1.0-darwin-arm64 然后会报404,因为bazel-3.1.0 没有编译darwin-arm64版本:
在这里插入图片描述

此时直接 修改 命令 下载x86版本

1
2
3
(cd "/opt/homebrew/Cellar/bazel/5.0.0/libexec/bin" && \
   curl -fL -o bazel-3.1.0 https://releases.bazel.build/3.1.0/release/bazel-3.1.0-darwin-x86_64 && \ 
   chmod +x bazel-3.1.0)

注意 不要使用默认文件名 bazel-3.1.0-darwin-x86_64

如果遇到 提示可执行文件架构不支持,需执行shell:softwareupdate --install-rosetta 安装 rosetta