Xcode 必须指定版本才能使用 Apple CROSSTOOL

Xcode version must be specified to use an Apple CROSSTOOL

我尝试使用 bazel 构建 tensorflow-serving,但在构建过程中遇到了一些错误

ERROR:/private/var/tmp/_bazel_Kakadu/3f0c35881c95d2c43f04614911c03a57/external/local_config_cc/BUILD:49:5: in apple_cc_toolchain rule @local_config_cc//:cc-compiler-darwin_x86_64: Xcode version must be specified to use an Apple CROSSTOOL.

ERROR: Analysis of target '//tensorflow_serving/sources/storage_path:file_system_storage_path_source_proto' failed; build aborted.

我已经尝试使用 bazel cleanbazel clean --expunge 但它没有帮助而且 Bazel 仍然没有看到我的 xcode (我想)但它已完全安装.我什至重新安装它以确保一切正常,但错误并没有消失

我的 Bazel 版本是

Build label: 0.5.2-homebrew
Build target: bazel-out/darwin_x86_64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Jul 13 12:29:40 2017 (1499948980)
Build timestamp: 1499948980
Build timestamp as int: 1499948980
KakaduDevs-Mac-mini:serving Kakadu$ 

OS 是 MacOS Sierra 版本 10.12.5

我应该如何在 bazel 中指定 Xcode 版本以避免此错误?似乎错误很常见,但我还没有找到如何构建 bazel。 P.S 我正在尝试按照此处说明的方式安装 tensorflow-serving。 https://tensorflow.github.io/serving/setup

为了构建 objc,Bazel 要求您指定一个 xcode 版本——这通常由 xcode_configure 自动完成。如果这不起作用,您可以使用 --xcode_version 标志在命令行上手动指定 xcode 版本。

看起来 xcode_configure 没有正确识别您安装了 xcode。如果您安装 xcode 但尚未完全打开它,有时会发生这种情况(它可能会要求您在完全运行之前同意条款和条件)。如果这是问题所在,您需要在此之后再次 bazel clean --expunge...

如果这没有帮助,您可以通过调用(在构建失败后)获取一些调试信息以确定出了什么问题:

cat $(bazel info output_base)/external/local_config_xcode/BUILD

这应该包含一些关于无法找到您安装的 xcodes 的评论。

对我来说,这是 xcodebuild 的许可问题。 运行宁之后 bazel clean --expunge 我已经尝试 运行 再次 bazel 并且我得到了 运行 的说明 sudo xcodebuild -license。 我已执行并接受许可条款,运行 再次 bazel clean --expunge 一切都重新开始工作。 希望它能解决一些问题。

bazel clean --expunge 
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license
bazel clean --expunge 
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

有同样的问题,因为我使用的是 XCode 的测试版,所以我不得不在 /Downloads/Xcode-beta.app 中找到安装。

顺便说一下,我的解决方案是打开 XCode,转到首选项,然后 select 位置选项卡。 Command Line Tools 下拉菜单是空白的,我不得不按下它和 select 一个版本(在我的例子中是 Xcode 9.0)。然后我 运行 bazel clean --expunge 并重复构建过程而没有收到错误。希望这对某人有所帮助。