Before we start building, we need to install Bazel and any other tools and frameworks required (e.g., compilers). In this chapter, we will demonstrate the necessary steps among several operating systems.
Note
Throughout the course of this book, we will be using Bazel version 1.0.0. Bazel is evolving rapidly, with new capabilities and configurations coming all the time. In this evolution, there may be changes to the dependencies which require tweaks to the build code. For the sake of the examples here, it is best for you to normalize against version 1.0.0. Once you have gotten the hang of Bazel, you can upgrade to later versions and tweak the examples as necessary.
We will cover the installation instructions for the following operating systems: Windows, MacOS, and Ubuntu Linux. Additional installation instructions may be found at https://docs.bazel.build/versions/master/install.html.
Since we are focused on version 1.0.0 of Bazel, we can find the installation binaries required for all of our platforms at https://github.com/bazelbuild/bazel/releases/.
For all operating systems, we will need some basic tools in order to bootstrap Bazel. These include the tools and frameworks for building and running Python, Java, and C++. Although we won’t be explicitly building any C++ projects in the course of this book, we will be depending upon projects which do build C++ (e.g., Protocol Buffers).
Note
Java, Python, and C++ are “special” with regard to Bazel because they largely comprise the built-in languages whose rules come out of the box with Bazel. That is, the rules for building libraries and binary using these languages come as a part of Bazel itself.
Other languages that we will build over the course of this book are Go and Swift; however, we don’t need to explicitly download tools for them. Instead, we will see that by virtue of depending upon external projects and registering the appropriate toolchains, we will get the components to build these languages for “free.” There will be more on this in later chapters.
MacOS
Installing Xcode
For installation on MacOS, we will first need to install Xcode for performing the basic build actions. The simplest way to retrieve Xcode is to open the App Store application on MacOS and download the application.
Once you have downloaded the application, you will need to open the application and accept the license agreement.
Installing Bazel
Once you have set up Xcode, you are now ready to install Bazel onto your machine. Download the Bazel binary installer for 1.0.0. This can be found at https://github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-installer-darwin-x86_64.sh.
Installing Java
You will need at least Java 8 for the examples presented in this book. For MacOS 10.7 and above, Java is no longer installed by default; instead, we need to explicitly download and install it.
Head over to https://java.com/en/download/mac_download.jsp to download Java. Once you have downloaded the file to your computer, follow the instructions to install Java on your computer.
Verifying Your Python Version
Note
At the time of this writing, both Python 2 and Python 3 work with Bazel, with a migration path currently in place to get to the latter. You can set your default to be one or the other; however, this is considered outside the scope of this book for the sake of the examples presented therein; currently they should work with either version.
Ubuntu Linux
Installing Required Packages
Installation on Ubuntu is very similar to MacOS. However, in this case, instead of downloading Xcode, we will be installing a set of required packages (i.e., pkg-config, zip, g++, zlib1g-dev, unzip, python3).
This may require you to install additional packages as well. Press “Y” when asked if additional packages should be installed.
Installing Bazel
Having retrieved the prerequisites, you are ready to download Bazel. Retrieve the installation script from https://github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-installer-linux-x86_64.sh.
Installing Java
In each case, it may be necessary to install additional packages in order to complete the Java installation.
Windows
Setting Up Your System
Under Use developer features, select Developer mode. It may be necessary to wait for the Developer package to be downloaded.
Installing Required Applications
You will need several applications prior to actually retrieving Bazel itself.
Visual C++ Redistributable for Visual Studio 2015
Download the package and install it on your computer.
MSYS2
MSYS2 is a platform that provides some basic tools for software distribution and building; in this context, we will be most interested in the fact that it provides a bash shell for Windows. It also provides a package management system to make it easy to install software, similar to what might be seen in Linux (e.g., through apt-get) or MacOS (e.g., through something like Homebrew).
You may need to install additional packages in order to complete the installations.
Bazel Installation
Having taken care of the necessary components, you are now ready to download and install Bazel itself. Retrieve the executable from https://github.com/bazelbuild/bazel/releases/download/1.0.0/bazel-1.0.0-windows-x86_64.exe.
Unlike Linux and MacOS, the downloaded executable is the Bazel executable; there is no separate installation script. Once you have downloaded the application, move the application to a directory (e.g., C:Users<user name>in) and rename it to bazel.exe.
Installing Language Support
In order to work with several languages (C++, Java, and Python), you will need to install the appropriate supporting frameworks and applications.
C++
Java
Many examples in this book do use Java. Navigate to www.oracle.com/technetwork/java/javase/downloads/index.html. You will need to download at least Java SE Development Kit 10 for Windows x64. Download an appropriate installation executable and install it on your computer.
Note
MSYS2 has difficulty with spaces within paths. The default path places Java into Program Files. In order to avoid any issues, you should change your installation path to someplace without spaces (e.g., C:Users<user name>inJava<jdk-version>).
Python
Finally, in order to build for Python, you will need to download either Python 2.7 or 3 for Windows. Navigate to www.python.org/downloads/release/python-2716 and download the Windows x86-64 MSI Installer. After you have downloaded the installer, execute it in order to install Python.
Final Word
At this stage, you should be able to execute the Bazel examples within this book. For additional operating systems that you may want to install Bazel on, navigate to https://docs.bazel.build/versions/master/install.html.
Having taken care of the scaffolding necessary to run Bazel, you are now ready to jump in and start having some fun.