Repository: google/jax

Issue:
Build on linux, got "@local_config_cuda//crosstool:cc-compiler-windows" error
Built jax on master 78c804772e47f98721acd31a7e0953504aa504a8 gives

```
➜  jax git:(master) python build/build.py --enable_march_native --enable_mkl_dnn --enable_cuda

     _   _  __  __
    | | / \ \ \/ /
 _  | |/ _ \ \  /
| |_| / ___ \/  \
 \___/_/   \/_/\_\


Bazel binary path: /home/titan/bin/bazel
Python binary path: /home/titan/frameworks/miniconda3/envs/ml/bin/python
MKL-DNN enabled: yes
-march=native: yes
CUDA enabled: yes

Building XLA and installing it in the jaxlib source tree...
INFO: An error occurred during the fetch of repository 'local_config_python'
INFO: Call stack for the definition of repository 'local_config_python':
 - /home/titan/.cache/bazel/_bazel_titan/0fa25a5a75e40e18875f78640c2a6d59/external/org_tensorflow/tensorflow/workspace.bzl:69:5
 - /home/titan/resources/oss/machine-learning/Google/jax/WORKSPACE:41:1
ERROR: /home/titan/.cache/bazel/_bazel_titan/0fa25a5a75e40e18875f78640c2a6d59/external/local_config_cuda/crosstool/BUILD:64:1: in cc_toolchain rule @local_config_cuda//crosstool:cc-compiler-windows: attributes 'cpu' and 'compiler' have been deprecated, please remove them. See https://github.com/bazelbuild/bazel/issues/7075 for details.
ERROR: Analysis of target '//build:install_xla_in_source_tree' failed; build aborted: Analysis of target '@local_config_cuda//crosstool:cc-compiler-windows' failed; build aborted
INFO: Elapsed time: 0.095s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 1 target configured)
FAILED: Build did NOT complete successfully (0 packages loaded, 1 target configured)
Traceback (most recent call last):
  File "build/build.py", line 324, in <module>
    main()
  File "build/build.py", line 320, in main
    [":install_xla_in_source_tree", os.getcwd()])
  File "build/build.py", line 50, in shell
    output = subprocess.check_output(cmd)
  File "/home/titan/frameworks/miniconda3/envs/ml/lib/python3.7/subprocess.py", line 395, in check_output
    **kwargs).stdout
  File "/home/titan/frameworks/miniconda3/envs/ml/lib/python3.7/subprocess.py", line 487, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/home/titan/bin/bazel', 'run', '--verbose_failures=true', '--config=opt', '--config=mkl_open_source_only', '--config=cuda', ':install_xla_in_source_tree', '/home/titan/resources/oss/machine-learning/Google/jax/build']' returned non-zero exit status 1.
```

I have successfully built jax before without encounter this error.


Discussion:
If I'm parsing the log correctly, it's picking up your own version of bazel (/home/titan/bin/bazel), rather than one it automatically downloads. What version of bazel is that?
This is my bazel version:

```
Build label: 0.25.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed May 1 21:45:01 2019 (1556747101)
Build timestamp: 1556747101
Build timestamp as int: 1556747101
```
Also try to remove my local bazel to let jax use a download bazel, still an issue:

```
jax git:(master) python build/build.py --enable_march_native --enable_mkl_dnn --enable_cuda

     _   _  __  __
    | | / \ \ \/ /
 _  | |/ _ \ \  /
| |_| / ___ \/  \
 \___/_/   \/_/\_\


Downloading bazel from: https://github.com/bazelbuild/bazel/releases/download/0.25.1/bazel-0.25.1-linux-x86_64
bazel-0.25.1-linux-x86_64 [########################################] 100%
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
Bazel binary path: ./bazel-0.25.1-linux-x86_64
Python binary path: /home/titan/frameworks/miniconda3/envs/ml/bin/python
MKL-DNN enabled: yes
-march=native: yes
CUDA enabled: yes

Building XLA and installing it in the jaxlib source tree...
ERROR: /home/titan/.cache/bazel/_bazel_titan/0fa25a5a75e40e18875f78640c2a6d59/external/local_config_cuda/crosstool/BUILD:34:1: in cc_toolchain rule @local_config_cuda//crosstool:cc-compiler-local: attributes 'cpu' and 'compiler' have been deprecated, please remove them. See https://github.com/bazelbuild/bazel/issues/7075 for details.
INFO: An error occurred during the fetch of repository 'local_config_python'
INFO: Call stack for the definition of repository 'local_config_python':
 - /home/titan/.cache/bazel/_bazel_titan/0fa25a5a75e40e18875f78640c2a6d59/external/org_tensorflow/tensorflow/workspace.bzl:69:5
 - /home/titan/resources/oss/machine-learning/Google/jax/WORKSPACE:41:1
INFO: An error occurred during the fetch of repository 'cython'
INFO: Call stack for the definition of repository 'cython':
 - /home/titan/.cache/bazel/_bazel_titan/0fa25a5a75e40e18875f78640c2a6d59/external/org_tensorflow/tensorflow/workspace.bzl:727:5
 - /home/titan/resources/oss/machine-learning/Google/jax/WORKSPACE:41:1
INFO: Repository 'cython' used the following cache hits instead of downloading the corresponding file.
 * Hash 'bccc9aa050ea02595b2440188813b936eaf345e85fb9692790cecfe095cf91aa' for http://mirror.tensorflow.org/github.com/cython/cython/archive/0.28.4.tar.gz
If the definition of 'cython' was updated, verify that the hashes were also updated.
ERROR: Analysis of target '//build:install_xla_in_source_tree' failed; build aborted: Analysis of target '@local_config_cuda//crosstool:cc-compiler-local' failed; build aborted
INFO: Elapsed time: 1.291s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (27 packages loaded, 76 targets configured)
FAILED: Build did NOT complete successfully (27 packages loaded, 76 targets configured)
    currently loading: @org_tensorflow//tensorflow/core ... (5 packages)
Traceback (most recent call last):
  File "build/build.py", line 324, in <module>
    main()
  File "build/build.py", line 320, in main
    [":install_xla_in_source_tree", os.getcwd()])
  File "build/build.py", line 50, in shell
    output = subprocess.check_output(cmd)
  File "/home/titan/frameworks/miniconda3/envs/ml/lib/python3.6/subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "/home/titan/frameworks/miniconda3/envs/ml/lib/python3.6/subprocess.py", line 418, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['./bazel-0.25.1-linux-x86_64', 'run', '--verbose_failures=true', '--config=opt', '--config=mkl_open_source_only', '--config=cuda', ':install_xla_in_source_tree', '/home/titan/resources/oss/machine-learning/Google/jax/build']' returned non-zero exit status 1.
```
I also tried to clean `.cache/bazel`, still the same error as above.
Thanks for raising this, and for looking into it so thoroughly! Sure looks like jaxlib's building process is broken.
I'm not very familiar with bazel, but [this recent pr by @hawkinsp](https://github.com/google/jax/pull/698/files) might have some clues. Presumably the build worked then...
7f9e1809bbd035b1998268cde68c1b9567c26a21 seems to be the issue. Hard reset to 60918077c285a787c697b694d8d7bb04da56a9e5 works for me.

Resolving patch:
diff --git a/build/build.py b/build/build.py
--- a/build/build.py
+++ b/build/build.py
@@ -60,19 +60,19 @@ def get_python_bin_path(python_bin_path_flag):
 
 # Bazel
 
-BAZEL_BASE_URI = "https://github.com/bazelbuild/bazel/releases/download/0.25.1/"
+BAZEL_BASE_URI = "https://github.com/bazelbuild/bazel/releases/download/0.24.1/"
 BazelPackage = collections.namedtuple("BazelPackage", ["file", "sha256"])
 bazel_packages = {
     "Linux":
         BazelPackage(
-            file="bazel-0.25.1-linux-x86_64",
+            file="bazel-0.24.1-linux-x86_64",
             sha256=
-            "9fe5a74fa319e771b0328b42f79bf00496592fd9c0989247b4dd322ce9a082e9"),
+            "e18e2877e18a447eb5d94f5efbec375366d82af6443c6a83a93c62657a7b1c32"),
     "Darwin":
         BazelPackage(
-            file="bazel-0.25.1-darwin-x86_64",
+            file="bazel-0.24.1-darwin-x86_64",
             sha256=
-            "436e34cf8cf47f43620a70927e3fcdb1f23659e3e0ae22e42ff8b6d8b7626cfa"),
+            "cf763752550050d117e03659aaa6ccd6f97da1f983a6029300a497fdaeaaec46"),
 }
 
 
@@ -140,8 +140,8 @@ def get_bazel_path(bazel_path_flag):
   sys.exit(-1)
 
 
-def check_bazel_version(bazel_path, min_version):
-  """Checks Bazel's version is at least `min_version`."""
+def check_bazel_version(bazel_path, min_version, max_version):
+  """Checks Bazel's version is in the range [`min_version`, `max_version`)."""
   version_output = shell([bazel_path, "--bazelrc=/dev/null", "version"])
   match = re.search("Build label: *([0-9\\.]+)[^0-9\\.]", version_output)
   if match is None:
@@ -155,6 +155,12 @@ def check_bazel_version(bazel_path, min_version):
     print("Outdated bazel revision (>= {} required, found {})".format(
         min_version, version))
     sys.exit(0)
+  if max_version is not None:
+    max_ints = [int(x) for x in max_version.split(".")]
+    if actual_ints >= max_ints:
+      print("Please downgrade your bazel revision to build JAX (>= {} and < {}"
+            " required, found {})".format(min_version, max_version, version))
+      sys.exit(0)
 
 
 BAZELRC_TEMPLATE = """
@@ -283,7 +289,7 @@ def main():
 
   # Find a working Bazel.
   bazel_path = get_bazel_path(args.bazel_path)
-  check_bazel_version(bazel_path, "0.25.0")
+  check_bazel_version(bazel_path, min_version="0.24.0", max_version="0.25.0")
   print("Bazel binary path: {}".format(bazel_path))
 
   python_bin_path = get_python_bin_path(args.python_bin_path)


Test patch: