How to Compile Bazel on Windows

Earlier I had been trying to compile Bazel on Windows < >. Even though the instructions were clear but they do not seem to work. I figured out the following way to compile Bazel on Windows 10.

First of all, we need to download different tools at the following links:

  1. Java JDK < >
  2. MSYS2 installer < >.
  3. Visual Studio 2015 < >, Community version is free to download.
  4. Python < >.
  5. Download version 0.4.0 < > and 0.4.2 < > source code.
Compile instructions:
  1. Install all the software's in default locations except MSYS2 which you can install in c:\tools\msys64.
  2. Enter pacman -Syuu gcc git curl zip unzip zlib-devel
  3. Enter export JAVA_HOME="$(ls -d C:/Program\ Files/Java/jdk* | sort | tail -n 1)"
  4. Enter export BAZEL_SH=c:/tools/msys64/usr/bin/bash.exe
  5. Enter export BAZEL_VS="C:/Program Files (x86)/Microsoft Visual Studio 14.0"
  6. Enter export BAZEL_PYTHON=C:/Python27/python.exe
  7. Extract bazel-0.4.0.
  8. Run c:\tools\msys64\msys2.exe
  9. Enter path to bazel-0.4.0 using cd /c/path/to/bazel-0.4.0
  10. Run ./
  11. After successful compilation, you should be able to find bazel.exe in the output folder
  12. Extract bazel-0.4.2
  13. Enter path to bazel-0.4.2 using cd /c/path/to/bazel-0.4.2
  14. Run ./ compile /c/path/to/bazel-0.4.0/output/bazel.exe
After successful compilation you can test by running the following commands as mentioned on author's website <

$ bazel build --cpu=x64_windows_msvc examples/cpp:hello-world
$ ./bazel-bin/examples/cpp/hello-world.exe
$ bazel run --cpu=x64_windows_msvc examples/cpp:hello-world
$ bazel build examples/java-native/src/main/java/com/example/myproject:hello-world
$ ./bazel-bin/examples/java-native/src/main/java/com/example/myproject/hello-world
$ bazel run examples/java-native/src/main/java/com/example/myproject:hello-world

$ bazel build examples/py_native:bin
$ ./bazel-bin/examples/py_native/bin
$ python ./bazel-bin/examples/py_native/bin    # This works in both msys and cmd.exe
$ bazel run examples/py_native:bin


  1. I completed to build bazel....

    KDH@DESKTOP-U2JGCNL MSYS /c/tools/bazel-0.4.2
    $ output/bazel build --cpu=x64_windows_msvc examples/cpp:hello-world

    ERROR: C:/tools/bazel-0.4.2/examples/cpp/BUILD:3:1: C++ compilation of rule '//examples/cpp:hello-lib' failed: msvc_cl.bat failed: error executing command external/local_config_cc/wrapper/bin/msvc_cl.bat -m64 /D__inline__=__inline /DOS_WINDOWS=OS_WINDOWS /DCOMPILER_MSVC /DNOGDI /DNOMINMAX /DPRAGMA_SUPPORTED /D_WIN32_WINNT=0x0600 ... (remaining 29 argument(s) skipped): Process exited with status 1.
    Traceback (most recent call last):
    File "C:\tools\msys64\tmp\_bazel_KDH\Av4xf9bt\execroot\bazel-0.4.2\external\local_config_cc\wrapper\bin\pydir\", line 125, in
    sys.exit(main(sys.argv[1:])) # need to skip the first argument
    File "C:\tools\msys64\tmp\_bazel_KDH\Av4xf9bt\execroot\bazel-0.4.2\external\local_config_cc\wrapper\bin\pydir\", line 121, in main
    return MsvcCompiler().Run(argv[1:])
    File "C:\tools\msys64\tmp\_bazel_KDH\Av4xf9bt\execroot\bazel-0.4.2\external\local_config_cc\wrapper\bin\pydir\", line 113, in Run
    return self.RunBinary(compiler, parser.options, parser.target_arch, parser)
    File "C:\tools\msys64\tmp\_bazel_KDH\Av4xf9bt\execroot\bazel-0.4.2\external\local_config_cc\wrapper\bin\pydir\", line 503, in RunBinary
    line = line.decode('utf-8')
    File "C:\Python27\lib\encodings\", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 0: invalid continuation byte
    Target //examples/cpp:hello-world failed to build
    Use --verbose_failures to see the command lines of failed build steps.
    INFO: Elapsed time: 0.825s, Critical Path: 0.33s

    help me please...
    what is problem and how can i solve it?

  2. Hi.. How to build tensorflow after this bazel installation? thank you.

    1. I will do a video in a few days to compile tensorflow on windows. You can subscribe to youtube channel to get notification.

  3. This comment has been removed by the author.

  4. i got this error while building bazel
    Auto-Configuration Error:"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/VCVARSALL.BAT"' is not recognized as an internal or external command,
    operable program or batch file.
    Any solutions ,please?


How to run R code in Python

R is freely available language and computational tool which is very popular among the statisticians and bioinformatics community. In this p...