Skip to content

Instantly share code, notes, and snippets.

@pcj
Last active October 27, 2018 18:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pcj/46553228eb782221a1bacd68b37b3d49 to your computer and use it in GitHub Desktop.
Save pcj/46553228eb782221a1bacd68b37b3d49 to your computer and use it in GitHub Desktop.
Installing bazel 0.4.5 on Windows

Installing bazel 0.4.5 on Windows 10

  1. Read the steps in https://bazel.build/versions/master/docs/windows.html.
  2. Read the github issues bazelbuild/bazel#2431 and related bazelbuild/bazel#2449.
  3. May be useful to consult https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl.

Install Msys2

  1. Make sure you install the Feb 5 2016 Msys2 version from https://sourceforge.net/projects/msys2/files/Base/x86_64/msys2-x86_64-20160205.exe/download.
  2. The install path must be c:\tools\msys64 (hardcoded into bazel).
  3. Open an msys2 shell.
  4. Upgrade the installation with pacman -Syuu gcc git curl zip unzip zlib-devel as per instructions. This triggered a bunch of cygwin errors but the command completed. Close the msys2 shell and re-open it.
  5. In my case this did not include python within msys2, so I did pacman -S python2 also.

Install Bazel

I downloaded bazel within msys2 shell using the link from the bazel releases page as $ curl -O -J -L https://github.com/bazelbuild/bazel/releases/download/0.4.5/bazel-0.4.5-windows-x86_64.exe (which I then renamed to bazel.exe).

Install Visual Studio

Although the bazel windows instructions suggested that VS was only a compile dependency, bazel.exe would not run without it.

Specifically, the cc_configure.bzl script needed the vsvarsall.bat script, which is part of Visual Studio.

I already had VS2015 installed, but the C++ build tools were not installed, so I had to get this installed via Control Panel > Programs > Programs and Features, right click Microsoft Visual Studio Enterprise 2015 with Updates "Change", choose the [Modify] button, and then select the Programming Languages / Visual C++ checkbox. This added 5G of stuff.

Setup environment

A few environment variables needed to be set:

$ env | grep BAZEL
BAZEL_PYTHON=/usr/bin/python2.exe
BAZEL_VS=C:/Program Files (x86)/Microsoft Visual Studio 14.0
BAZEL_SH=c:/tools/msys64/usr/bin/bash.exe

Finally

After all that I was able to build a simple java project:

$ ~/bazel.exe run :app
INFO: Found 1 target...
Target //src/main/java:app up-to-date:
  C:/tools/msys64/tmp/_bazel_paulj/rklkin_f/execroot/atweb/bazel-out/local-fastbuild/bin/src/main/java/app.jar
  C:/tools/msys64/tmp/_bazel_paulj/rklkin_f/execroot/atweb/bazel-out/local-fastbuild/bin/src/main/java/app
  C:/tools/msys64/tmp/_bazel_paulj/rklkin_f/execroot/atweb/bazel-out/local-fastbuild/bin/src/main/java/app.cmd
INFO: Elapsed time: 0.540s, Critical Path: 0.01s

INFO: Running command line: C:/tools/msys64/tmp/_bazel_paulj/rklkin_f/execroot/atweb/bazel-out/local-fastbuild/bin/src/main/java/app.cmd
Hello World!

Yay! Good luck.

@petemounce
Copy link

Hi; that's a great guide. I maintain the Bazel chocolatey package for Windows. Out of interest, does that work for you too? If there are any problems with it, please let me know.

@pcj
Copy link
Author

pcj commented Apr 21, 2017

Thanks for stepping up with the chocolatey package. No, it didn't work for me but maybe my chocolatey permissions or pre-existing msys2 install was blocking it. I'll try it again with 0.4.6 or 0.5.0.

@jbduncan
Copy link

@pcj Can you clarify for me what commands one should run to set the environment variables specified under Setup environment?

@pcj
Copy link
Author

pcj commented Apr 26, 2017

Msys2 is a bash-like clone, so you'd use the standard:

$ export BAZEL_PYTHON="/usr/bin/python2.exe"
$ export BAZEL_VS="C:/Program Files (x86)/Microsoft Visual Studio 14.0"
$ export BAZEL_SH="c:/tools/msys64/usr/bin/bash.exe"

The quotes may or may not be necessary. These export commands can also be put in your ~/.bash_profile file.

@jaylordpagal
Copy link

@pcj Can you clarify for me where did you install the python ?

@pcj
Copy link
Author

pcj commented Aug 11, 2017

@petemounce Sorry for long delay, just wanted to drop a note that choco install did indeed work for bazel 0.5.3. Hopefully these instructions are for the wayback machine 😄

@guruprasaad123
Copy link

how to set path $JAVA_HOME in ubuntu bash on window ?

@guruprasaad123
Copy link

Am getting this Error

It shows No message about any cause of the failed Task

`$ bazel build -c opt //tensorflow/examples/android:tensorflow_demo
...............................................................................................
____Loading package: tensorflow/examples/android
____Loading package: @bazel_tools//tools/cpp
____Loading package: @local_config_xcode//
____Loading package: @local_jdk//
____Loading package: @local_config_cc//
____Loading complete. Analyzing...
____Loading package: tensorflow/examples/android/assets
____Loading package: @bazel_tools//tools/android
____Loading package: tensorflow/contrib/android
ERROR: Analysis of target '//tensorflow/examples/android:tensorflow_demo' failed; build aborted.
____Elapsed time: 59.338s

`

@pcj
Copy link
Author

pcj commented Sep 9, 2017

@guruprasaad123 I would take this up with tensorflow on stackoverflow or forum. Looks like you were able to at least install bazel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment