Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 1 | --- |
| 2 | layout: documentation |
| 3 | title: Bazel Glossary |
| 4 | --- |
| 5 | |
| 6 | # Bazel Glossary |
| 7 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 8 | ### Action |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 9 | |
| 10 | A command to run during the build, for example, a call to a compiler that takes |
| 11 | [artifacts](#artifact) as inputs and produces other artifacts as outputs. |
| 12 | Includes metadata like the command line arguments, action key, environment |
| 13 | variables, and declared input/output artifacts. |
| 14 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 15 | **See also:** [Rules documentation](skylark/rules.html#actions) |
| 16 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 17 | ### Action cache |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 18 | |
| 19 | An on-disk cache that stores a mapping of executed [actions](#action) to the |
| 20 | outputs they created. The cache key is known as the [action key](#action-key). A |
| 21 | core component for Bazel's incrementality model. The cache is stored in the |
| 22 | output base directory and thus survives Bazel server restarts. |
| 23 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 24 | ### Action graph |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 25 | |
| 26 | An in-memory graph of [actions](#action) and the [artifacts](#artifact) that |
| 27 | these actions read and generate. The graph might include artifacts that exist as |
| 28 | source files (for example, in the file system) as well as generated |
| 29 | intermediate/final artifacts that are not mentioned in BUILD files. Produced |
| 30 | during the [analysis phase](#analysis-phase) and used during the [execution |
| 31 | phase](#execution-phase). |
| 32 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 33 | ### Action graph query (aquery) |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 34 | |
| 35 | A [query](#query-concept) tool that can query over build [actions](#action). |
| 36 | This provides the ability to analyze how [build rules](#rule) translate into the |
| 37 | actual work builds do. |
| 38 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 39 | ### Action key |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 40 | |
| 41 | The cache key of an [action](#action). Computed based on action metadata, which |
| 42 | might include the command to be execution in the action, compiler flags, library |
| 43 | locations, or system headers, depending on the action. Enables Bazel to cache or |
| 44 | invalidate individual actions deterministically. |
| 45 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 46 | ### Analysis phase |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 47 | |
| 48 | The second phase of a build. Processes the [target graph](#target-graph) |
| 49 | specified in [BUILD files](#build-file) to produce an in-memory [action |
| 50 | graph](#action-graph) that determines the order of actions to run during the |
| 51 | [execution phase](#execution-phase). This is the phase in which rule |
| 52 | implementations are evaluated. |
| 53 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 54 | ### Artifact |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 55 | |
| 56 | A source file or a generated file. Can also be a directory of files, known as |
| 57 | "tree artifacts". Tree artifacts are black boxes to Bazel: Bazel does not treat |
| 58 | the files in tree artifacts as individual artifacts and thus cannot reference |
| 59 | them directly as action inputs / outputs. An artifact can be an input to |
| 60 | multiple actions, but must only be generated by at most one action. |
| 61 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 62 | ### Aspect |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 63 | |
| 64 | A mechanism for rules to create additional [actions](#action) in their |
| 65 | dependencies. For example, if target A depends on B, one can apply an aspect on |
| 66 | A that traverses *up* a dependency edge to B, and runs additional actions in B |
| 67 | to generate and collect additional output files. These additional actions are |
| 68 | cached and reused between targets requiring the same aspect. Created with the |
| 69 | `aspect()` Starlark Build API function. Can be used, for example, to generate |
| 70 | metadata for IDEs, and create actions for linting. |
| 71 | |
| 72 | **See also:** [Aspects documentation](skylark/aspects.html) |
| 73 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 74 | ### Aspect-on-aspect |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 75 | |
| 76 | An aspect composition mechanism, where aspects can be applied on other aspects. |
| 77 | For an aspect A to inspect aspect B, aspect A must declare the *providers* it |
| 78 | needs from aspect B (with the `required_aspect_providers` attribute), and aspect |
| 79 | B must declare the providers it returns (with the `provides` attribute). For |
| 80 | example, this can be used by IDE aspects to generate files using information |
| 81 | also generated by aspects, like the `java_proto_library` aspect. |
| 82 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 83 | ### .bazelrc |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 84 | |
| 85 | Bazel’s configuration file used to change the default values for [startup |
| 86 | flags](#startup-flags) and [command flags](#command-flags), and to define common |
| 87 | groups of options that can then be set together on the Bazel command line using |
| 88 | a `--config` flag. Bazel can combine settings from multiple bazelrc files |
| 89 | (systemwide, per-workspace, per-user, or from a custom location), and a |
| 90 | bazelrc file may also import settings from other bazelrcs. |
| 91 | |
wyv | b9cb480 | 2020-05-06 04:02:16 -0700 | [diff] [blame] | 92 | ### Blaze |
| 93 | |
| 94 | <!-- "Bazel" gets scrubbed to "Bazel", so we use the corresponding HTML entity |
| 95 | to circumvent that here. B = "B" --> |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 96 | |
| 97 | The Google-internal version of Bazel. Google’s main build system for its |
| 98 | mono-repository. |
| 99 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 100 | ### BUILD File |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 101 | |
| 102 | A BUILD file is the main configuration file that tells Bazel what software |
| 103 | outputs to build, what their dependencies are, and how to build them. Bazel |
| 104 | takes a BUILD file as input and uses the file to create a graph of dependencies |
| 105 | and to derive the actions that must be completed to build intermediate and final |
| 106 | software outputs. A BUILD file marks a directory and any sub-directories not |
| 107 | containing a BUILD file as a [package](#package), and can contain |
| 108 | [targets](#target) created by [rules](#rule). The file can also be named |
| 109 | BUILD.bazel. |
| 110 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 111 | ### BUILD.bazel File |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 112 | |
| 113 | See [BUILD File](#build-file). Takes precedence over a `BUILD` file in the same |
| 114 | directory. |
| 115 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 116 | ### .bzl File |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 117 | |
| 118 | A file that defines rules, [macros](#macro), and constants written in |
| 119 | [Starlark](#starlark). These can then be imported into [BUILD |
| 120 | files](#build-file) using the load() function. |
| 121 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 122 | <!-- TODO: ### Build event protocol --> |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 123 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 124 | <!-- TODO: ### Build flag --> |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 125 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 126 | ### Build graph |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 127 | |
| 128 | The dependency graph that Bazel constructs and traverses to perform a build. |
| 129 | Includes nodes like [targets](#target), [configured |
| 130 | targets](#configured-target), [actions](#action), and [artifacts](#artifact). A |
| 131 | build is considered complete when all [artifacts](#artifact) on which a set of |
| 132 | requested targets depend are verified as up-to-date. |
| 133 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 134 | ### Build setting |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 135 | |
| 136 | A Starlark-defined piece of [configuration](#configuration). |
| 137 | [Transitions](#transition) can set build settings to change a subgraph's |
| 138 | configuration. If exposed to the user as a [command-line flag](#command-flags), |
| 139 | also known as a build flag. |
| 140 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 141 | ### Clean build |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 142 | |
| 143 | A build that doesn't use the results of earlier builds. This is generally slower |
| 144 | than an [incremental build](#incremental-build) but commonly considered to be |
| 145 | more [correct](#correctness). Bazel guarantees both clean and incremental builds |
| 146 | are always correct. |
| 147 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 148 | ### Client-server model |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 149 | |
| 150 | The `bazel` command-line client automatically starts a background server on the |
| 151 | local machine to execute Bazel [commands](#command). The server persists across |
| 152 | commands but automatically stops after a period of inactivity (or explicitly via |
| 153 | bazel shutdown). Splitting Bazel into a server and client helps amortize JVM |
| 154 | startup time and supports faster [incremental builds](#incremental-build) |
| 155 | because the [action graph](#action-graph) remains in memory across commands. |
| 156 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 157 | ### Command |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 158 | |
| 159 | Used on the command line to invoke different Bazel functions, like `bazel |
| 160 | build`, `bazel test`, `bazel run`, and `bazel query`. |
| 161 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 162 | ### Command flags |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 163 | |
| 164 | A set of flags specific to a [command](#command). Command flags are specified |
| 165 | *after* the command (`bazel build <command flags>`). Flags can be applicable to |
| 166 | one or more commands. For example, `--configure` is a flag exclusively for the |
| 167 | `bazel sync` command, but `--keep_going` is applicable to `sync`, `build`, |
| 168 | `test` and more. Flags are often used for [configuration](#configuration) |
| 169 | purposes, so changes in flag values can cause Bazel to invalidate in-memory |
| 170 | graphs and restart the [analysis phase](#analysis-phase). |
| 171 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 172 | ### Configuration |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 173 | |
| 174 | Information outside of [rule](#rule) definitions that impacts how rules generate |
| 175 | [actions](#action). Every build has at least one configuration specifying the |
| 176 | target platform, action environment variables, and command-line [build |
| 177 | flags](#command-flags). [Transitions](#transition) may create additional |
| 178 | configurations, e.g. for host tools or cross-compilation. |
| 179 | |
Greg | 39a6fd4 | 2020-02-28 13:37:19 -0800 | [diff] [blame] | 180 | **See also:** [Configurations](skylark/rules.html#configurations) |
| 181 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 182 | <!-- TODO: ### Configuration fragment --> |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 183 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 184 | ### Configuration trimming |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 185 | |
| 186 | The process of only including the pieces of [configuration](#configuration) a |
| 187 | target actually needs. For example, if you build Java binary `//:j` with C++ |
| 188 | dependency `//:c`, it's wasteful to include the value of `--javacopt` in the |
| 189 | configuration of `//:c` because changing `--javacopt` unnecessarily breaks C++ |
| 190 | build cacheability. |
| 191 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 192 | ### Configured query (cquery) |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 193 | |
| 194 | A [query](#query-concept) tool that queries over [configured |
| 195 | targets](#configured-target) (after the [analysis phase](#analysis-phase) |
| 196 | completes). This means `select()` and [build flags](#command-flags) (e.g. |
| 197 | `--platforms`) are accurately reflected in the results. |
| 198 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 199 | **See also:** [cquery documentation](cquery.html) |
| 200 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 201 | ### Configured target |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 202 | |
| 203 | The result of evaluating a [target](#target) with a |
| 204 | [configuration](#configuration). The [analysis phase](#analysis-phase) produces |
| 205 | this by combining the build's options with the targets that need to be built. |
| 206 | For example, if `//:foo` builds for two different architectures in the same |
| 207 | build, it has two configured targets: `<//:foo, x86>` and `<//:foo, arm>`. |
| 208 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 209 | ### Correctness |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 210 | |
| 211 | A build is correct when its output faithfully reflects the state of its |
| 212 | transitive inputs. To achieve correct builds, Bazel strives to be |
| 213 | [hermetic](#hermeticity), reproducible, and making [build |
| 214 | analysis](#analysis-phase) and [action execution](#execution-phase) |
| 215 | deterministic. |
| 216 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 217 | ### Dependency |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 218 | |
| 219 | A directed edge between two [targets](#target). A target `//:foo` has a *target |
| 220 | dependency* on target `//:bar` if `//:foo`'s attribute values contain a |
| 221 | reference to `//:bar`. `//:foo` has an *action dependency* on `//:bar` if an |
| 222 | action in `//:foo` depends on an input [artifact](#artifact) created by an |
| 223 | action in `//:bar`. |
| 224 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 225 | ### Depset |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 226 | |
| 227 | A data structure for collecting data on transitive dependencies. Optimized so |
| 228 | that merging depsets is time and space efficient, because it’s common to have |
| 229 | very large depsets (e.g. hundreds of thousands of files). Implemented to |
| 230 | recursively refer to other depsets for space efficiency reasons. [Rule](#rule) |
| 231 | implementations should not "flatten" depsets by converting them to lists unless |
| 232 | the rule is at the top level of the build graph. Flattening large depsets incurs |
| 233 | huge memory consumption. Also known as *nested sets* in Bazel's internal |
| 234 | implementation. |
| 235 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 236 | **See also:** [Depset documentation](skylark/depsets.html) |
| 237 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 238 | ### Disk cache |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 239 | |
| 240 | A local on-disk blob store for the remote caching feature. Can be used in |
| 241 | conjunction with an actual remote blob store. |
| 242 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 243 | ### Distdir |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 244 | |
| 245 | A read-only directory containing files that Bazel would otherwise fetch from the |
| 246 | internet using repository rules. Enables builds to run fully offline. |
| 247 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 248 | ### Dynamic execution |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 249 | |
| 250 | An execution strategy that selects between local and remote execution based on |
| 251 | various heuristics, and uses the execution results of the faster successful |
| 252 | method. Certain [actions](#action) are executed faster locally (for example, |
| 253 | linking) and others are faster remotely (for example, highly parallelizable |
| 254 | compilation). A dynamic execution strategy can provide the best possible |
| 255 | incremental and clean build times. |
| 256 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 257 | ### Execution phase |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 258 | |
| 259 | The third phase of a build. Executes the [actions](#action) in the [action |
| 260 | graph](#action-graph) created during the [analysis phase](#analysis-phase). |
| 261 | These actions invoke executables (compilers, scripts) to read and write |
| 262 | [artifacts](#artifact). *Spawn strategies* control how these actions are |
| 263 | executed: locally, remotely, dynamically, sandboxed, docker, and so on. |
| 264 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 265 | ### Execution root |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 266 | |
| 267 | A directory in the [workspace](#workspace)’s [output base](#output-base) |
| 268 | directory where local [actions](#action) are executed in |
| 269 | non-[sandboxed](#sandboxing) builds. The directory contents are mostly symlinks |
| 270 | of input [artifacts](#artifact) from the workspace. The execution root also |
| 271 | contains symlinks to external repositories as other inputs and the `bazel-out` |
| 272 | directory to store outputs. Prepared during the [loading phase](#loading-phase) |
| 273 | by creating a *symlink forest* of the directories that represent the transitive |
| 274 | closure of packages on which a build depends. Accessible with `bazel info |
| 275 | execution_root` on the command line. |
| 276 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 277 | ### File |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 278 | |
| 279 | See [Artifact](#artifact). |
| 280 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 281 | ### Hermeticity |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 282 | |
| 283 | A build is hermetic if there are no external influences on its build and test |
| 284 | operations, which helps to make sure that results are deterministic and |
| 285 | [correct](#correctness). For example, hermetic builds typically disallow network |
| 286 | access to actions, restrict access to declared inputs, use fixed timestamps and |
| 287 | timezones, restrict access to environment variables, and use fixed seeds for |
| 288 | random number generators |
| 289 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 290 | ### Incremental build |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 291 | |
| 292 | An incremental build reuses the results of earlier builds to reduce build time |
| 293 | and resource usage. Dependency checking and caching aim to produce correct |
| 294 | results for this type of build. An incremental build is the opposite of a clean |
| 295 | build. |
| 296 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 297 | <!-- TODO: ### Install base --> |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 298 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 299 | ### Label |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 300 | |
| 301 | An identifier for a [target](#target). A fully-qualified label such as |
| 302 | `//path/to/package:target` consists of `//` to mark the workspace root |
| 303 | directory, `path/to/package` as the directory that contains the [BUILD |
| 304 | file](#build-file) declaring the target, and `:target` as the name of the target |
| 305 | declared in the aforementioned BUILD file. May also be prefixed with |
| 306 | `@my_repository//<..>` to indicate that the target is declared in an ]external |
| 307 | repository] named `my_repository`. |
| 308 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 309 | ### Loading phase |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 310 | |
| 311 | The first phase of a build where Bazel parses `WORKSPACE`, `BUILD`, and [.bzl |
| 312 | files](#bzl-file) to create [packages](#package). [Macros](#macro) and certain |
| 313 | functions like `glob()` are evaluated in this phase. Interleaved with the second |
| 314 | phase of the build, the [analysis phase](#analysis-phase), to build up a [target |
| 315 | graph](#target-graph). |
| 316 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 317 | ### Macro |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 318 | |
| 319 | A mechanism to compose multiple [rule](#rule) target declarations together under |
| 320 | a single [Starlark](#starlark) function. Enables reusing common rule declaration |
| 321 | patterns across BUILD files. Expanded to the underlying rule target declarations |
| 322 | during the [loading phase](#loading-phase). |
| 323 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 324 | **See also:** [Macro documentation](skylark/macros.html) |
| 325 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 326 | ### Mnemonic |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 327 | |
| 328 | A short, human-readable string selected by a rule author to quickly understand |
| 329 | what an [action](#action) in the rule is doing. Mnemonics can be used as |
| 330 | identifiers for *spawn strategy* selections. Some examples of action mnemonics |
| 331 | are `Javac` from Java rules, `CppCompile` from C++ rules, and |
| 332 | `AndroidManifestMerger` from Android rules. |
| 333 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 334 | ### Native rules |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 335 | |
| 336 | [Rules](#rule) that are built into Bazel and implemented in Java. Such rules |
| 337 | appear in [`.bzl` files](#bzl-file) as functions in the native module (for |
| 338 | example, `native.cc_library` or `native.java_library`). User-defined rules |
| 339 | (non-native) are created using [Starlark](#starlark). |
| 340 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 341 | ### Output base |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 342 | |
| 343 | A [workspace](#workspace)-specific directory to store Bazel output files. Used |
| 344 | to separate outputs from the *workspace*'s source tree. Located in the [output |
| 345 | user root](#output-user-root). |
| 346 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 347 | ### Output groups |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 348 | |
| 349 | A group of files that is expected to be built when Bazel finishes building a |
| 350 | target. [Rules](#rule) put their usual outputs in the "default output group" |
| 351 | (e.g the `.jar` file of a `java_library`, `.a` and `.so` for `cc_library` |
| 352 | targets). The default output group is the output group whose |
| 353 | [artifacts](#artifact) are built when a target is requested on the command line. |
| 354 | Rules can define more named output groups that can be explicitly specified in |
| 355 | [BUILD files](#build-file) (`filegroup` rule) or the command line |
| 356 | (`--output_groups` flag). |
| 357 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 358 | ### Output user root |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 359 | |
| 360 | A user-specific directory to store Bazel's outputs. The directory name is |
| 361 | derived from the user's system username. Prevents output file collisions if |
| 362 | multiple users are building the same project on the system at the same time. |
| 363 | Contains subdirectories corresponding to build outputs of individual workspaces, |
| 364 | also known as [output bases](#output-base). |
| 365 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 366 | ### Package |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 367 | |
| 368 | The set of [targets](#target) defined by a [BUILD file](#build-file). A |
| 369 | package's name is the BUILD file's path relative to the workspace root. A |
| 370 | package can contain subpackages, or subdirectories containing BUILD files, thus |
| 371 | forming a package hierarchy. |
| 372 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 373 | ### Package group |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 374 | |
| 375 | A [target](#target) representing a set of packages. Often used in visibility |
| 376 | attribute values. |
| 377 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 378 | ### Platform |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 379 | |
| 380 | A "machine type" involved in a build. This includes the machine Bazel runs on |
| 381 | (the "host" platform), the machines build tools execute on ("exec" platforms), |
| 382 | and the machines targets are built for ("target platforms"). |
| 383 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 384 | ### Provider |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 385 | |
| 386 | A set of information passed from a rule [target](#target) to other rule targets. |
| 387 | Usually contains information like: compiler options, transitive source files, |
| 388 | transitive output files, and build metadata. Frequently used in conjunction with |
| 389 | [depsets](#depset). |
| 390 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 391 | **See also:** [Provider documentation](rules.html#providers) |
| 392 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 393 | ### Query (concept) |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 394 | |
| 395 | The process of analyzing a [build graph](#build-graph) to understand |
| 396 | [target](#target) properties and dependency structures. Bazel supports three |
| 397 | query variants: [query](#query-command), [cquery](#configured-query-cquery), and |
| 398 | [aquery](#action-graph-query-aquery). |
| 399 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 400 | ### query (command) |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 401 | |
| 402 | A [query](#query-concept) tool that operates over the build's post-[loading |
| 403 | phase](#loading-phase) [target graph](#target-graph). This is relatively fast, |
| 404 | but can't analyze the effects of `select()`, [build flags](#command-flags), |
| 405 | [artifacts](#artifact), or build [actions](#action). |
| 406 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 407 | **See also:** [Query how-to](query-how-to.html), [Query reference](query.html) |
| 408 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 409 | ### Repository cache |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 410 | |
| 411 | A shared content-addressable cache of files downloaded by Bazel for builds, |
| 412 | shareable across [workspaces](#workspace). Enables offline builds after the |
| 413 | initial download. Commonly used to cache files downloaded through repository |
| 414 | rules like `http_archive` and repository rule APIs like |
| 415 | `repository_ctx.download`. Files are cached only if their SHA-256 checksums are |
| 416 | specified for the download. |
| 417 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 418 | <!-- TODO: ### Repository rule --> |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 419 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 420 | ### Reproducibility |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 421 | |
| 422 | The property of a build or test that a set of inputs to the build or test will |
| 423 | always produce the same set of outputs every time, regardless of time, method, |
| 424 | or environment. Note that this does not necessarily imply that the outputs are |
| 425 | [correct](#correctness) or the desired outputs. |
| 426 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 427 | ### Rule |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 428 | |
| 429 | A function implementation that registers a series of [actions](#action) to be |
| 430 | performed on input [artifacts](#artifact) to produce a set of output artifacts. |
| 431 | Rules can read values from *attributes* as inputs (e.g. deps, testonly, name). |
| 432 | Rule targets also produce and pass along information that may be useful to other |
| 433 | rule targets in the form of [providers](#provider) (e.g. `DefaultInfo` |
| 434 | provider). |
| 435 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 436 | **See also:** [Rules documentation](skylark/rules.html) |
| 437 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 438 | ### Runfiles |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 439 | |
| 440 | The runtime dependencies of an executable [target](#target). Most commonly, the |
| 441 | executable is the executable output of a test rule, and the runfiles are runtime |
| 442 | data dependencies of the test. Before the invocation of the executable (during |
| 443 | bazel test), Bazel prepares the tree of runfiles alongside the test executable |
| 444 | according to their source directory structure. |
| 445 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 446 | **See also:** [Runfiles documentation](skylark/rules.html#runfiles) |
| 447 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 448 | ### Sandboxing |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 449 | |
| 450 | A technique to isolate a running [action](#action) inside a restricted and |
| 451 | temporary [execution root](#execution-root), helping to ensure that it doesn’t |
| 452 | read undeclared inputs or write undeclared outputs. Sandboxing greatly improves |
| 453 | [hermeticity](#hermeticity), but usually has a performance cost, and requires |
| 454 | support from the operating system. The performance cost depends on the platform. |
| 455 | On Linux, it's not significant, but on macOS it can make sandboxing unusable. |
| 456 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 457 | ### Skyframe |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 458 | |
| 459 | The core parallel, functional, and incremental evaluation framework of Bazel. |
| 460 | [https://bazel.build/designs/skyframe.html](https://bazel.build/designs/skyframe.html) |
| 461 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 462 | <!-- TODO: ### Spawn strategy --> |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 463 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 464 | ### Stamping |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 465 | |
| 466 | A feature to embed additional information into Bazel-built |
| 467 | [artifacts](#artifact). For example, this can be used for source control, build |
| 468 | time and other workspace or environment-related information for release builds. |
| 469 | Enable through the `--workspace_status_command` flag and [rules](rules) that |
| 470 | support the stamp attribute. |
| 471 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 472 | ### Starlark |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 473 | |
| 474 | The extension language for writing [rules](rules) and [macros](#macro). A |
| 475 | restricted subset of Python (syntactically and grammatically) aimed for the |
| 476 | purpose of configuration, and for better performance. Uses the [`.bzl` |
| 477 | file](#bzl-file) extension. [BUILD files](#build-file) use an even more |
| 478 | restricted version of Starlark (e.g. no `def` function definitions). Formerly |
| 479 | known as Skylark. |
| 480 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 481 | **See also:** [Starlark language documentation](skylark/language.html) |
| 482 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 483 | <!-- TODO: ### Starlark rules --> |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 484 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 485 | <!-- TODO: ### Starlark rule sandwich --> |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 486 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 487 | ### Startup flags |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 488 | |
| 489 | The set of flags specified between `bazel` and the [command](#query-command), |
| 490 | for example, bazel `--host_jvm_debug` build. These flags modify the |
| 491 | [configuration](#configuration) of the Bazel server, so any modification to |
| 492 | startup flags causes a server restart. Startup flags are not specific to any |
| 493 | command. |
| 494 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 495 | ### Target |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 496 | |
| 497 | A buildable unit. Can be a [rule](#rule) target, file target, or a [package |
| 498 | group](#package-group). Rule targets are instantiated from rule declarations in |
| 499 | [BUILD files](#build-file). Depending on the rule implementation, rule targets |
| 500 | can also be testable or runnable. Every file used in BUILD files is a file |
| 501 | target. Targets can depend on other targets via attributes (most commonly but |
| 502 | not necessarily `deps`). A [configured target](#configured-target) is a pair of |
| 503 | target and [build configuration](#configuration). |
| 504 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 505 | ### Target graph |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 506 | |
| 507 | An in-memory graph of [targets](#target) and their dependencies. Produced during |
| 508 | the [loading phase](#loading-phase) and used as an input to the [analysis |
| 509 | phase](#analysis-phase). |
| 510 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 511 | ### Target pattern |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 512 | |
| 513 | A way to specify a group of [targets](#target) on the command line. Commonly |
| 514 | used patterns are `:all` (all rule targets), `:*` (all rule + file targets), |
| 515 | `...` (current [package](#package) and all subpackages recursively). Can be used |
| 516 | in combination, for example, `//...:*` means all rule and file targets in all |
| 517 | packages recursively from the root of the [workspace](#workspace). |
| 518 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 519 | ### Tests |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 520 | |
| 521 | Rule [targets](#target) instantiated from test rules, and therefore contains a |
| 522 | test executable. A return code of zero from the completion of the executable |
| 523 | indicates test success. The exact contract between Bazel and tests (e.g. test |
| 524 | environment variables, test result collection methods) is specified in the [Test |
| 525 | Encyclopedia](test-encyclopedia.html). |
| 526 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 527 | ### Toolchain |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 528 | |
| 529 | A set of tools to build outputs for a language. Typically, a toolchain includes |
| 530 | compilers, linkers, interpreters or/and linters. A toolchain can also vary by |
| 531 | platform, that is, a Unix compiler toolchain's components may differ for the |
| 532 | Windows variant, even though the toolchain is for the same language. Selecting |
| 533 | the right toolchain for the platform is known as toolchain resolution. |
| 534 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 535 | ### Top-level target |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 536 | |
| 537 | A build [target](#target) is top-level if it’s requested on the Bazel command |
| 538 | line. For example, if `//:foo` depends on `//:bar`, and `bazel build //:foo` is |
| 539 | called, then for this build, `//:foo` is top-level, and `//:bar` isn’t |
| 540 | top-level, although both targets will need to be built. An important difference |
| 541 | between top-level and non-top-level targets is that [command |
| 542 | flags](#command-flags) set on the Bazel command line (or via |
| 543 | [.bazelrc](#bazelrc)) will set the [configuration](#configuration) for top-level |
| 544 | targets, but might be modified by a [transition](#transition) for non-top-level |
| 545 | targets. |
| 546 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 547 | ### Transition |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 548 | |
| 549 | A mapping of [configuration](#configuration) state from one value to another. |
| 550 | Enables [targets](#target) in the [build graph](#build-graph) to have different |
| 551 | configurations, even if they were instantiated from the same [rule](#rule). A |
| 552 | common usage of transitions is with *split* transitions, where certain parts of |
| 553 | the [target graph](#target-graph) is forked with distinct configurations for |
| 554 | each fork. For example, one can build an Android APK with native binaries |
| 555 | compiled for ARM and x86 using split transitions in a single build. |
| 556 | |
Greg | 39a6fd4 | 2020-02-28 13:37:19 -0800 | [diff] [blame] | 557 | **See also:** [User-defined transitions](skylark/config.html#user-defined-transitions) |
| 558 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 559 | ### Tree artifact |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 560 | |
| 561 | See [Artifact](#artifact). |
| 562 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 563 | ### Visibility |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 564 | |
| 565 | Defines whether a [target](#target) can be depended upon by other targets. By |
| 566 | default, target visibility is private. That is, the target can only be depended |
| 567 | upon by other targets in the same [package](#package). Can be made visible to |
| 568 | specific packages or be completely public. |
| 569 | |
laurentlb | 41fe876 | 2020-02-20 12:04:30 -0800 | [diff] [blame] | 570 | **See also:** [Visibility documentation](be/common-definitions.html#common-attributes) |
| 571 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 572 | ### Workspace |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 573 | |
| 574 | A directory containing a `WORKSPACE` file and source code for the software you |
| 575 | want to build. Labels that start with `//` are relative to the workspace |
| 576 | directory. |
| 577 | |
jingwen | 3decf6d | 2020-02-20 15:12:36 -0800 | [diff] [blame] | 578 | ### WORKSPACE file |
Jingwen Chen | a7f5253 | 2020-02-19 07:53:26 -0800 | [diff] [blame] | 579 | |
| 580 | Defines a directory to be a [workspace](#workspace). The file can be empty, |
| 581 | although it usually contains external repository declarations to fetch |
| 582 | additional dependencies from the network or local filesystem. |
| 583 | |
| 584 | ## Contributing |
| 585 | |
| 586 | We welcome contributions to this glossary. |
| 587 | |
| 588 | The definitions should strive to be crisp, concise, and easy to understand. |
| 589 | |
| 590 | Principles: |
| 591 | |
| 592 | * Use the simplest words possible. Try to avoid technical jargon. |
| 593 | * Use the simplest grammar possible. Try not to string too many concepts into a |
| 594 | sentence. |
| 595 | * Make the last word of each sentence count. |
| 596 | * Make each adjective *really* count. |
| 597 | * Avoid adverbs. |
| 598 | * Keep definitions as self-contained as possible. |
| 599 | * Calibrate a word's value by considering what would be lost without it. |
| 600 | * Hit core concepts foremost. Avoid pedantry. |
| 601 | * Enlightening the reader is more important than being thorough. |
| 602 | * Links can provide deeper dives, for those who want it. |