Xcode version must be specified to use an Apple CROSSTOOL

I try to build tensorflow-serving using bazel but I've encountered some errors during the building

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.

I've already tried to use bazel clean and bazel clean --expunge but it didn't help and still Bazel doesn't see my xcode (I suppose) but it's completely installed. I even reinstalled it to make sure that all works fine but the error didn't disappeared

My Bazel version is

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 is MacOS Sierra version 10.12.5

What should I do to specify Xcode version in bazel to avoid this error? It seems that the error is common but I haven't found how I can make the bazel build. P.S I'm trying to install tensorflow-serving the way it's explained here. https://tensorflow.github.io/serving/setup


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

Had the same problem, and since I am using a beta version of XCode, I had to find the installation in /Downloads/Xcode-beta.app instead.

Incidentally, the solution for me was to open XCode, go to Preferences, and select the Locations tab. The Command Line Tools drop-down was blank, and I had to press it and select a version (Xcode 9.0 in my case). I then ran bazel clean --expunge and repeated the build process without getting the error. Hope this helps someone.