2. WHAT IS BAZEL?
• An open-source build and test tool
similar to Make, Maven, and Gradle.
• Uses a human-readable, high-level
build language.
• Supports projects in multiple languages.
• Supports large codebases across multiple repositories,
and large numbers of users.
3. HISTORY OF BAZEL
• Developed by Google in MARCH 2015.
• Written in Java and can work on any cross platform.
• Has provided its users with an official website called
bazel.build.
WHO USE BAZEL?
Nearly 17 companies reportedly use Bazel in their tech
stacks, including Google, Asana, and Square.
4. WHY TO USE BAZEL?
• Produces deterministic results.
• Eliminates skew between incremental and clean
builds, laptop and CI system, etc.
• It can build different client and server apps with
the same tool from the same workspace.
5. LOGO AND TAGLINE
• Initial release the logo was a green letter "b" stylized into a stem
of a basil plant with two leaves.
• On July 5, 2017, the Bazel Blog announced a new logo,
consisting of three green building blocks arranged to shape a
heart.
• Bazel advertises itself with the tagline “{Fast, Correct} –
Choose two”.
6. Versions of BAZEL
• Initial version - 0.17.1
• Latest version - 3.5.0, Master
• Intermediate version - 3.4.0 · 3.3.0 · 3.2.0 · 3.1.0 ·
3.0.0 · 2.2.0 · 2.1.0 · 2.0.0 · 1.2.0 · 1.1.0 · 1.0.0 ·
0.29.1 · 0.29.0 · 0.28.0 · 0.27.0 · 0.26.0 · 0.25.0 ·
0.24.0 · 0.23.0 · 0.22.0 · 0.21.0 · 0.20.0 · 0.19.2 ·
0.19.1 · 0.18.1 · 0.17.2
• Some versions of Bazel contain a bundled
version of OpenJDK.
7. WHY IS BAZEL WRITTEN IN JAVA?
Bazel is being developed in java
because; Java builds are so larded with user-
defined annotation processors and Error
Prone checks.
8. HOW DO I USE BAZEL?
• Set up Bazel. Download and install BAZEL.
• Set up a project workspace.
• Write a build file, which tells Bazel what to
build and how to build it.
• Write your file by declaring build targets using
starlack , a domain-specific language.
• A build target specifies a set of input artifacts
that Bazel will build plus their dependencies,
the build rule Bazel will use to build it.
9. • A build rule specifies the build tools Bazel will use, such
as compilers and linkers, and their configurations.
• Bazel ships with a number of build rules covering the
most common artifact types in the supported languages on
supported platforms.
• Finally run BAZEL, from the command line. Bazel places
your outputs within the workspace.
10. UNDERSTANDING BAZEL
• LOADS – Load the relevant build file respective to target.
• ANALYZES – Examine the inputs and their dependencies, and then
perform the specified build rules, and produces an action graph.
• EXECUTES – Run the build actions until final build outputs are
provided.
• BUILD – Files which tell Bazel how to build various parts of the
project which is defined by rules and these rules are called targets.
• WORKSPACE – File, and similar to BUILD files, there can only be
one WORKSPACE in a package. It keeps track of the external
dependencies of the project, and some rule adds each external
dependency.
11. Bazel is rich in languages supports, platform supports, and have some
fantastic tools; some are mentioned below –
• Bazel-watcher – Automatically run commands when source files
change.
• Dazel – For running Bazel inside the Docker container.
• Spotify/bazel-tools – Tools for dealing with substantial Bazel-
managed repo.
BAZEL TOOLS
12. First clone the provided repository by Bazel and
check the folders inside github.
Create a WORKSPACE text file. As we know we put our
workspace file in the root folder, so here, we are putting out a
file inside the tutorial folder.
Now create library modules. Go to
src/main/java/com/example/bazel/ and create BUILD text file
under it.
Now, we want to add the android_binary which builds the APK file.
For this, we had to add one more top-level BUILD text file. Go to
src/main and create the file under it.
BUILDING AN ANDROID APP
13. Now, we are ready to build our application. Go to the tutorial folder again on
your terminal and run bazel build //src/main:app . Or you can open this project
inside android studio by following steps. This will generate three folders:
bazel-bin stores.apk
bazel-genfiles stores intermediary source files that are
generated by bazel rules.
bazel-out stores other types of build outputs
14. THE BAZEL QUERY REFERENCE
Bazel comes with a query language for the dependency graph.
When you use bazel query to analyze build dependencies, you use
a little language, the Bazel Query Language. This document is the
reference manual for that language. This document also describes
the output formats that bazel query supports.
Traditional bazel query runs on the post-loading phase target graph
and therefore has no concept of configurations and their related
concepts. Notably, this means it does not correctly resolve select
statements and rather returns all possible resolutions of selects. A
newer query environment, cquery, properly handles configurations
but doesn't provide all of the functionality of this original query.
15. ADVANTAGES OF BAZEL
Bazel is fast, reliable, support human-readable languages, and have
lots of other benefits too –
High-level build language – It uses human-readable language to
describe the build properties of someone’s project. It operates on the
concepts of binaries, libraries, data sets, and scripts.
Fast and correct – It can cache build results and only rebuild what it
needs to, which make it fast.
Platform independent – It can run on Linux, macOS, Windows.
Scales – It can handle large source files easily. It works with various
repositories and user bases in the tens of thousands.
Flexible – Build and test C/C++, Objective-C, Java, Python, and
Bourne Shell scripts and a wide variety of other language platforms.
16. Comparing with other tools like Gradle, and its configuration files are
more structured and allow Bazel to understand each action clearly, which
result in better reproducibility. It has many built-in commands which make it
fast and easy to use, such as command like “mobile-install,” which allows for
agile and iterative development of Android apps.
17. DISADVANTAGES OF BAZEL
Bazel does not have a high level declarative build language that makes
the build easy to use for developers. At Google this can be compensated
with a specialized service team that owns the build tool.
Bazel is not built for extensibility (although the Bazel development team
has since countered this with assurances that they are working on
extensibility).
Speed is optimized around the idea that all transitive dependencies are
stored in one big repo; all libraries and tools are checked in to this
central repository. Most Enterprises have more distributed dependency
management requirements.
18. When compared with gradle which is an alternate to bazel, gradle has
built-in support for both Maven and Ivy repositories. Bazel provides
an official rule with support only for Maven repositories, with some
boilerplate code is required to use it.
Bazel does not run on Windows. This eliminates a large number of
potential Enterprises.
There is no plugin ecosystem in bazel whereas, Plugins are the central
feature of Maven that allow for the reuse of common build logic
across multiple projects.
19. DEBUGGING IN BAZEL
For debugging the C++ client you can just run it from gdb or lldb
as you normally would. But if you want to debug the Java code, you
must attach to the server using the following:
Run Bazel with debugging option --host_jvm_debug before the
command (e.g., bazel --host_jvm_debug build //src:bazel).
20. CONCLUSION
Thus the goal of Bazel is to create a build system where build
target inputs and outputs are fully specified and therefore precisely
known to the build system. This allows a more accurate analysis and
determination of out-of-date build artifacts in build
system's dependency graph.
And making the dependency graph analysis more deterministic
leads to potential improvements in build times by avoiding re-
executing unnecessary build targets. Build reliability is
improved by avoiding errors where build targets might depend on
out-of-date input artifacts.