How to Compile Bazel on Windows

Earlier I had been trying to compile Bazel on Windows < https://bazel.build/versions/master/docs/windows.html >. 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 < http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html >
  2. MSYS2 installer < https://msys2.github.io/ >.
  3. Visual Studio 2015 < https://www.visualstudio.com/downloads/ >, Community version is free to download.
  4. Python < https://www.python.org/downloads/release/python-2712/ >.
  5. Download version 0.4.0 < https://github.com/bazelbuild/bazel/archive/0.4.0.zip > and 0.4.2 < https://github.com/bazelbuild/bazel/archive/0.4.2.zip > 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 ./compile.sh
  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.sh 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 < https://bazel.build/versions/master/docs/windows.html

BUILD C++
$ 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
BUILD JAVA
$ 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
BUILD PYTHON

$ 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

5 comments:

  1. I completed to build bazel....
    and

    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): com.google.devtools.build.lib.shell.BadExitStatusException: 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\msvc_cl.py", 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\msvc_cl.py", 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\msvc_cl.py", 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\msvc_tools.py", line 503, in RunBinary
    line = line.decode('utf-8')
    File "C:\Python27\lib\encodings\utf_8.py", 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?

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

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

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  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?

    ReplyDelete

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...