blob: a6f74d96d264e2aa788086d626d8dddcfefb06f9 [file] [log] [blame] [view]
Googler12e99472017-03-03 16:23:40 +00001---
2layout: documentation
3title: Bazel Overview
4---
5
spomorskiedca92e2017-10-24 19:59:57 +02006# What is Bazel?
Googler12e99472017-03-03 16:23:40 +00007
spomorskiedca92e2017-10-24 19:59:57 +02008Bazel is an open-source build and test tool similar to Make, Maven, and Gradle.
9It uses a human-readable, high-level build language. Bazel supports projects in
10multiple languages and builds outputs for multiple platforms. Bazel supports
11large codebases across multiple repositories, and large numbers of users.
Googler12e99472017-03-03 16:23:40 +000012
13
spomorskiedca92e2017-10-24 19:59:57 +020014# Why should I use Bazel?
Googler12e99472017-03-03 16:23:40 +000015
spomorskiedca92e2017-10-24 19:59:57 +020016Bazel offers the following advantages:
Googler12e99472017-03-03 16:23:40 +000017
spomorskiedca92e2017-10-24 19:59:57 +020018* **High-level build language.** Bazel uses an abstract, human-readable
19 language to describe the build properties of your project at a high
20 semantical level. Unlike other tools, Bazel operates on the *concepts*
21 of libraries, binaries, scripts, and data sets, shielding you from the
22 complexity of writing individual calls to tools such as compilers and
23 linkers.
Googler12e99472017-03-03 16:23:40 +000024
spomorskiedca92e2017-10-24 19:59:57 +020025* **Bazel is fast and reliable.** Bazel caches all previously done work and
26 tracks changes to both file content and build commands. This way, Bazel
27 knows when something needs to be rebuilt, and rebuilds only that. To further
28 speed up your builds, you can set up your project to build in a highly
29 parallel and incremental fashion.
Googler12e99472017-03-03 16:23:40 +000030
Googler9ea02e52018-03-28 10:35:37 -070031* **Bazel is multi-platform.** Bazel runs on Linux, macOS, and Windows. Bazel
32 can build binaries and deployable packages for multiple platforms, including
33 desktop, server, and mobile, from the same project.
spomorskiedca92e2017-10-24 19:59:57 +020034
35* **Bazel scales.** Bazel maintains agility while handling builds with 100k+
36 source files. It works with multiple repositories and user bases in the tens
37 of thousands.
38
39* **Bazel is extensible.** You can extend Bazel to support your language of
40 choice.
41
42
spomorskiedca92e2017-10-24 19:59:57 +020043# How do I use Bazel?
44
45To build or test a project with Bazel, you typically do the following:
46
471. **Set up Bazel.** Download and [install Bazel](https://docs.bazel.build/versions/master/install.html).
48
Umesh Yadave35047e2017-11-27 12:12:08 -0800492. **Set up a project [workspace](https://docs.bazel.build/versions/master/build-ref.html#workspaces)**,
spomorskiedca92e2017-10-24 19:59:57 +020050 which is a directory where Bazel looks for build inputs and `BUILD` files,
51 and where it stores build outputs.
52
Roller, David0dcf4252017-11-28 07:59:41 -0800533. **Write a `BUILD` file**, which tells Bazel what to build and how to
spomorskiedca92e2017-10-24 19:59:57 +020054 build it.
55
56 You write your `BUILD` file by declaring build targets using an abstract
57 Python-like language. (See example [here](https://github.com/bazelbuild/bazel/blob/master/examples/cpp/BUILD).)
58
59 A build target specifies a set of input artifacts that Bazel will build plus
60 their dependencies, the build rule Bazel will use to build it, and options
61 that configure the build rule.
62
63 A build rule specifies the build tools Bazel will use, such as compilers and
64 linkers, and their configurations. Bazel ships with a number of build rules
65 covering the most common artifact types in the supported languages on
66 supported platforms.
67
684. **Run Bazel** from the [command line](https://docs.bazel.build/versions/master/command-line-reference.html).
69 Bazel places your outputs within the workspace.
70
71In addition to building, you can also use Bazel to run [tests](https://docs.bazel.build/versions/master/test-encyclopedia.html)
72and [query](https://docs.bazel.build/versions/master/query-how-to.html) the
73build to trace dependencies in your code.
74
75
76# How does Bazel work?
77
78When running a build or a test, Bazel does the following:
79
801. **Loads** the `BUILD` files relevant to the target.
81
822. **Analyzes** the inputs and their [dependencies](https://docs.bazel.build/versions/master/build-ref.html#dependencies),
83 applies the specified build rules, and produces an [action](https://docs.bazel.build/versions/master/skylark/concepts.html#evaluation-model)
84 graph.
85
863. **Executes** the build actions on the inputs until the final build outputs
87 are produced.
88
89Since all previous build work is cached, Bazel can identify and reuse cached
90artifacts and only rebuild or retest what's changed. To further enforce
Jingwen Chen7633ab02018-03-05 09:30:14 -080091correctness, you can set up Bazel to run builds and tests [hermetically](https://docs.bazel.build/versions/master/user-manual.html#sandboxing)
92through sandboxing, minimizing skew and maximizing [reproducibility](https://docs.bazel.build/versions/master/user-manual.html#correctness).
spomorskiedca92e2017-10-24 19:59:57 +020093
94
95## What is the action graph?
96
97The action graph represents the build artifacts, the relationships between them,
98and the build actions that Bazel will perform. Thanks to this graph, Bazel can
Jingwen Chen7633ab02018-03-05 09:30:14 -080099[track](https://docs.bazel.build/versions/master/user-manual.html#build-consistency-and-incremental-builds)
spomorskiedca92e2017-10-24 19:59:57 +0200100changes to file content as well as changes to actions, such as build or test
101commands, and know what build work has previously been done. The graph also
102enables you to easily [trace dependencies](https://docs.bazel.build/versions/master/query-how-to.html)
103in your code.
104
105
106# How do I get started?
107
108To get started with Bazel, see [Getting Started](https://docs.bazel.build/versions/master/getting-started.html)
109or jump directly to the Bazel tutorials:
110
111* [Tutorial: Build a C++ Project](https://docs.bazel.build/versions/master/tutorial/cpp.html)
112* [Tutorial: Build a Java Project](https://docs.bazel.build/versions/master/tutorial/java.html)
113* [Tutorial: Build an Android Application](https://docs.bazel.build/versions/master/tutorial/android-app.html)
114* [Tutorial: Build an iOS Application](https://docs.bazel.build/versions/master/tutorial/ios-app.html)