blob: ec2e5b0b5eb63d8666fb17780001cd5ffa47014b [file] [log] [blame] [view]
Googler12e99472017-03-03 16:23:40 +00001---
2layout: documentation
3title: Bazel Overview
4---
5
6# Bazel Overview
7
8Bazel is a build tool which coordinates builds and run tests. It works with
9source files written in any language, with native support for Java, C, C++ and
10Python. Bazel produces builds and runs tests for multiple platforms.
11
12## BUILD files use a simple declarative language
13
14Bazels BUILD files describe how Bazel should build your project. They have a
15declarative structure and use a build language similar to Python. BUILD files
16allow you to work at a high level of the system by listing rules and their
17attributes. The complexity of the build process is handled by these pre-existing
18rules. You can modify rules to tweak the build process, or write new rules to
19extend Bazel to work with any language or platform.
20
21Below is the content of one of the BUILD files from a Hello World program. The
Googler1b91de72017-03-08 15:39:20 +000022two rules used here are `cc_library` and `cc_binary`.
Googler12e99472017-03-03 16:23:40 +000023
24```
25cc_library(
26 name = "hello-time",
27 srcs = ["hello-time.cc"],
28 hdrs = ["hello-time.h"],
29)
30
31cc_binary(
32 name = "hello-world",
33 srcs = ["hello-world.cc"],
34 deps = [
35 ":hello-time",
36 "//lib:hello-greet",
37 ],
38)
39```
40
Googler1b91de72017-03-08 15:39:20 +000041## The dependency graph describes the entire system
Googler12e99472017-03-03 16:23:40 +000042
43Build dependencies are declared explicitly in the BUILD files, allowing Bazel
44to create an accurate dependency graph of the entire source code. The graph is
45maintained in memory, and incremental builds and parallel execution are possible
46because of this accurate dependency graph.
47
48Heres the graph of the target hello-world from the BUILD file above:
49
50![Dependency graph of a hello-world target](/assets/graph_hello-world.svg)
51
52
53Bazels query language allows you to produce images of the graph like the one
54above. You can also use the query language to access information about build
55dependencies and their relationships.
56
Googler1b91de72017-03-08 15:39:20 +000057## Build and tests are fast, correct, and reproducible
Googler12e99472017-03-03 16:23:40 +000058
59Hermetic rules and sandboxing allows Bazel to produce correct, reproducible
60artifacts and test results. Caching allows reuse of build artifacts and test
61results.
62
63Bazels builds are fast. Incremental builds allows Bazel to do the minimum
64required work for a rebuild or retest. Correct and reproducible builds allow
65Bazel to reuse cached artifacts for whatever is not changed. If you change a
66library, Bazel will not rebuild your entire source.
67
68Confidence in these correct results also means that you will never need to run
69`bazel clean`. If you ever need to run `bazel clean`, theres a bug in Bazel.