Kristina Chodorow | 974b208 | 2015-03-31 14:49:30 +0000 | [diff] [blame] | 1 | --- |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 2 | layout: default |
| 3 | title: FAQ |
| 4 | nav: faq |
Kristina Chodorow | 974b208 | 2015-03-31 14:49:30 +0000 | [diff] [blame] | 5 | --- |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 6 | |
| 7 | What is Bazel? |
| 8 | -------------- |
| 9 | |
| 10 | Bazel is a tool that automates software builds and tests. Supported build tasks |
| 11 | include running compilers and linkers to produce executable programs and |
| 12 | libraries, and assembling deployable packages for Android, iOS and other target |
| 13 | environments. Bazel is similar to other tools like Make, Ant, Gradle, Buck, |
| 14 | Pants and Maven. |
| 15 | |
| 16 | What is special about Bazel? |
| 17 | ---------------------------- |
| 18 | |
| 19 | Bazel was designed to fit the way software is developed at Google. It |
| 20 | has the following features: |
| 21 | |
| 22 | * Multi-language support: Bazel supports Java, Objective-C and C++ out |
| 23 | of the box, and can be extended to support arbitrary programming |
| 24 | languages. |
| 25 | |
| 26 | * High-level build language: Projects are described in the BUILD |
| 27 | language, a concise text format that describes a project as sets of |
| 28 | small interconnected libraries, binaries and tests. In contrast, with |
| 29 | tools like Make, you have to describe individual files and compiler |
| 30 | invocations. |
| 31 | |
| 32 | * Multi-platform support: The same tool and the same BUILD files can |
| 33 | be used to build software for different architectures, and even |
| 34 | different platforms. At Google, we use Bazel to build everything from |
| 35 | server applications running on systems in our data centers to client apps |
| 36 | running on mobile phones. |
| 37 | |
| 38 | * Reproducibility: In BUILD files, each library, test and binary must |
| 39 | specify its direct dependencies completely. Bazel uses this |
| 40 | dependency information to know what must be rebuilt when you make |
| 41 | changes to a source file, and which tasks can run in parallel. This |
| 42 | means that all builds are incremental and will always produce the |
| 43 | same result. |
| 44 | |
| 45 | * Scalable: Bazel can handle large builds; at Google, it is common for |
| 46 | a server binary to have 100k source files, and builds where no files |
| 47 | were changed take about ~200ms. |
| 48 | |
| 49 | |
| 50 | Why doesn't Google use ...? |
| 51 | --------------------------- |
| 52 | |
| 53 | * Make, Ninja: These tools give very exact control over what commands |
| 54 | get invoked to build files, but it's up to the user to write rules |
| 55 | that are correct. |
| 56 | |
| 57 | Users interact with Bazel on a higher level. For example, Bazel has |
| 58 | built-in rules for "Java test", "C++ binary", and notions such as |
| 59 | "target platform" and "host platform". These rules have been battle |
| 60 | tested to be foolproof. |
| 61 | |
| 62 | * Ant and Maven: Ant and Maven are primarily geared toward Java, while |
| 63 | Bazel handles multiple languages. Bazel encourages subdividing |
| 64 | codebases in smaller reusable units, and can rebuild only ones that |
| 65 | need rebuilding. This speeds up development when working with larger |
| 66 | codebases. |
| 67 | |
| 68 | * Gradle: Bazel configuration files are much more structured than |
| 69 | Gradle's, letting Bazel understand exactly what each action does. |
| 70 | This allows for more parallelism and better reproducibility. |
| 71 | |
| 72 | * Pants, Buck: Both tools were created and developed by ex-Googlers at |
| 73 | Twitter and Foursquare, and Facebook respectively. They have been modeled |
| 74 | after Bazel, but their feature sets are different, so they aren't viable |
| 75 | alternatives for us. |
| 76 | |
| 77 | |
| 78 | Where did Bazel come from? |
| 79 | -------------------------- |
| 80 | |
| 81 | Bazel is a flavor of the tool that Google uses to build its server |
| 82 | software internally. It has expanded to build other software as well, |
| 83 | like mobile apps (iOS, Android) that connect to our servers. |
| 84 | |
| 85 | Did you rewrite your internal tool as open-source? Is it a fork? |
| 86 | ---------------------------------------------------------------- |
| 87 | |
| 88 | Bazel shares most of its code with the internal tool and its rules |
| 89 | are used for millions of builds every day. |
| 90 | |
| 91 | Why did Google build Bazel? |
| 92 | --------------------------- |
| 93 | |
| 94 | A long time ago, Google built its software using large, generated |
| 95 | Makefiles. These led to slow and unreliable builds, which began to |
| 96 | interfere with our developers' productivity and the company's |
| 97 | agility. Bazel was a way to solve these problems. |
| 98 | |
| 99 | Does Bazel require a build cluster? |
| 100 | ----------------------------------- |
| 101 | |
| 102 | Google's in-house flavor of Bazel does use [build |
| 103 | clusters](http://google-engtools.blogspot.com/2011/09/build-in-cloud-distributing-build-steps.html), |
| 104 | so Bazel does have hooks in the code base to plug in a remote build |
| 105 | cache or a remote execution system. |
| 106 | |
| 107 | The open source Bazel code runs build operations locally. We believe |
Han-Wen Nienhuys | 0cd6d15 | 2016-10-25 20:18:38 +0000 | [diff] [blame] | 108 | that this is fast enough for most of our users, but work is underway |
| 109 | to provide [distributed caching](https://github.com/bazelbuild/bazel/issues/904). |
| 110 | |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 111 | |
| 112 | How does the Google development process work? |
| 113 | ---------------------------------------------- |
| 114 | |
| 115 | For our server code base, we use the following development workflow: |
| 116 | |
| 117 | * All our server code is in a single, gigantic version control |
| 118 | system. |
| 119 | |
| 120 | * Everybody builds their software with Bazel. |
| 121 | |
| 122 | * Different teams own different parts of the source tree, and make |
| 123 | their components available as BUILD targets. |
| 124 | |
| 125 | * Branching is primarily used for managing releases, so everybody |
| 126 | develops their software at the head revision. |
| 127 | |
| 128 | Bazel is a cornerstone of this philosophy: since Bazel requires all |
| 129 | dependencies to be fully specified, we can predict which programs and |
| 130 | tests are affected by a change, and vet them before submission. |
| 131 | |
| 132 | More background on the development process at Google can be found on |
| 133 | the [eng tools blog](http://google-engtools.blogspot.com/). |
| 134 | |
| 135 | Why are you opening up Bazel? |
| 136 | ----------------------------- |
| 137 | |
| 138 | Building software should be fun and easy. Slow and unpredictable |
| 139 | builds take the fun out of programming. |
| 140 | |
| 141 | Why would I want to use Bazel? |
| 142 | ------------------------------ |
| 143 | |
| 144 | * Bazel may give you faster build times because it can recompile only |
| 145 | the files that need to be recompiled. Similarly, it can skip |
| 146 | re-running tests that it knows haven't changed. |
| 147 | |
| 148 | * Bazel produces deterministic results. This eliminates skew |
| 149 | between incremental and clean builds, laptop and CI system, etc. |
| 150 | |
| 151 | * Bazel can build different client and server apps with the same tool |
| 152 | from the same workspace. For example, you can change a client/server |
| 153 | protocol in a single commit, and test that the updated mobile app |
| 154 | works with the updated server, building both with the same tool, |
| 155 | reaping all the aforementioned benefits of Bazel. |
| 156 | |
| 157 | Can I see examples? |
| 158 | ------------------- |
| 159 | |
| 160 | Yes. For a simple example, see: |
| 161 | |
| 162 | <https://github.com/bazelbuild/bazel/blob/master/examples/cpp/BUILD> |
| 163 | |
| 164 | The Bazel source code itself provides a more complex example: |
| 165 | |
| 166 | <https://github.com/bazelbuild/bazel/blob/master/src/BUILD> |
| 167 | |
| 168 | What is Bazel best at? |
| 169 | ---------------------- |
| 170 | |
| 171 | Bazel shines at building and testing projects with the following properties: |
| 172 | |
| 173 | * Projects with a large codebase |
| 174 | * Projects written in (multiple) compiled languages |
| 175 | * Projects that deploy on multiple platforms |
| 176 | * Projects that have extensive tests |
| 177 | |
| 178 | Where can I run Bazel? |
| 179 | --------------------------------- |
| 180 | |
| 181 | Currently, Linux and Mac OS X. Porting to other UNIX platforms should be |
| 182 | straightforward, as long as a JDK is available for the platform. |
| 183 | |
| 184 | What about Windows? |
| 185 | ------------------- |
| 186 | |
| 187 | Due to its UNIX heritage, porting Bazel to Windows is significant work. For |
| 188 | example, Bazel uses symlinks extensively, which has varying levels of support |
| 189 | across Windows versions. |
| 190 | |
Laszlo Csomor | e1940f2 | 2016-11-09 15:42:49 +0000 | [diff] [blame] | 191 | As of version [0.3.0](https://github.com/bazelbuild/bazel/releases/tag/0.3.0) |
| 192 | Bazel supports Windows (bootstrapping itself and running builds), and we are |
| 193 | actively working on improving this support. See our |
| 194 | [blog post](https://bazel.build/blog/2016/09/07/bazel-windows.html) for more |
| 195 | information, as well as the [list of open bugs](https://github.com/bazelbuild/bazel/issues?q=is%3Aissue+is%3Aopen+label%3A%22category%3A+multi-platform+%3E+windows%22). |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 196 | |
| 197 | What should I not use Bazel for? |
| 198 | -------------------------------- |
| 199 | |
| 200 | * Bazel tries to be smart about caching. This means that it is not good |
| 201 | for running build operations whose outputs should not be cached. For example, |
| 202 | the following steps should not be run from Bazel: |
| 203 | |
| 204 | * A compilation step that fetches data from the internet. |
| 205 | * A test step that connects to the QA instance of your site. |
| 206 | * A deployment step that changes your site's cloud configuration. |
| 207 | |
| 208 | * Bazel tries to minimize expensive compilation steps. If you are only |
| 209 | using interpreted languages directly, such as JavaScript or Python, |
| 210 | Bazel will likely not interest you. |
| 211 | |
| 212 | How stable is Bazel's feature set? |
| 213 | ---------------------------------- |
| 214 | |
| 215 | The core features (C++, Java, and shell rules) have extensive use |
| 216 | inside Google, so they are thoroughly tested and have very little |
| 217 | churn. Similarly, we test new versions of Bazel across hundreds of |
| 218 | thousands of targets every day to find regressions, and we release new |
| 219 | versions multiple times every month. |
| 220 | |
| 221 | In short, except for features marked as experimental, Bazel should Just Work. |
| 222 | Changes to non-experimental rules will be backward compatible. A more detailed |
| 223 | list of feature support statuses can be found in our |
| 224 | [support document](support.html). |
| 225 | |
| 226 | How stable is Bazel as a binary? |
| 227 | -------------------------------- |
| 228 | |
| 229 | Inside Google, we make sure that Bazel crashes are very rare. This |
| 230 | should also hold for our open source codebase. |
| 231 | |
| 232 | How can I start using Bazel? |
| 233 | ---------------------------- |
| 234 | |
| 235 | See our [getting started document](docs/getting-started.html). |
| 236 | |
| 237 | Doesn't Docker solve the reproducibility problems? |
| 238 | -------------------------------------------------- |
| 239 | |
| 240 | With Docker you can easily create sandboxes with fixed OS releases, |
| 241 | for example, Ubuntu 12.04, Fedora 21. This solves the problem of |
| 242 | reproducibility for the system environment -- that is, "which version of |
| 243 | /usr/bin/c++ do I need?" |
| 244 | |
| 245 | Docker does not address reproducibility with regard to changes in the |
| 246 | source code. Running Make with an imperfectly written Makefile inside a |
| 247 | Docker container can still yield unpredictable results. |
| 248 | |
| 249 | Inside Google, we check tools into source control for reproducibility. |
| 250 | In this way, we can vet changes to tools ("upgrade GCC to 4.6.1") with |
| 251 | the same mechanism as changes to base libraries ("fix bounds check in |
| 252 | OpenSSL"). |
| 253 | |
| 254 | Can I build binaries for deployment on Docker? |
| 255 | ---------------------------------------------- |
| 256 | |
| 257 | With Bazel, you can build standalone, statically linked binaries in |
| 258 | C/C++, and self-contained jar files for Java. These run with few |
| 259 | dependencies on normal UNIX systems, and as such should be simple to |
| 260 | install inside a Docker container. |
| 261 | |
| 262 | Bazel has conventions for structuring more complex programs, for example, a |
| 263 | Java program that consumes a set of data files, or runs another |
| 264 | program as subprocess. It is possible to package up such environments |
| 265 | as standalone archives, so they can be deployed on different systems, |
| 266 | including Docker images. |
| 267 | |
| 268 | Can I build Docker images with Bazel? |
| 269 | ------------------------------------- |
| 270 | |
| 271 | Yes, you can use our |
Damien Martin-Guillerez | ba306ec | 2016-10-28 10:01:24 +0000 | [diff] [blame] | 272 | [Docker rules](http://bazel.build/docs/be/docker.html) |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 273 | to build reproducible Docker images. |
| 274 | |
| 275 | Will Bazel make my builds reproducible automatically? |
| 276 | ----------------------------------------------------- |
| 277 | |
| 278 | For Java and C++ binaries, yes, assuming you do not change the |
| 279 | toolchain. If you have build steps that involve custom recipes |
| 280 | (for example, executing binaries through a shell script inside a rule), you |
| 281 | will need to take some extra care: |
| 282 | |
| 283 | * Do not use dependencies that were not declared. Sandboxed |
| 284 | execution (--spawn_strategy=sandboxed, only on Linux) can |
| 285 | help find undeclared dependencies. |
| 286 | |
| 287 | * Avoid storing timestamps and user-IDs in generated files. ZIP files and |
| 288 | other archives are especially prone to this. |
| 289 | |
| 290 | * Avoid connecting to the network. Sandboxed execution can help here |
| 291 | too. |
| 292 | |
| 293 | * Avoid processes that use random numbers, in particular, dictionary |
| 294 | traversal is randomized in many programming languages. |
| 295 | |
| 296 | Do you have binary releases? |
| 297 | ---------------------------- |
| 298 | |
| 299 | Yes, you can find the latest release binaries |
| 300 | [here](https://github.com/bazelbuild/bazel/releases/latest). Our release |
Damien Martin-Guillerez | ba306ec | 2016-10-28 10:01:24 +0000 | [diff] [blame] | 301 | policy is documented [here](http://bazel.build/support.html). |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 302 | |
Han-Wen Nienhuys | 0cd6d15 | 2016-10-25 20:18:38 +0000 | [diff] [blame] | 303 | I use Eclipse/IntelliJ/XCode. How does Bazel interoperate with IDEs? |
| 304 | -------------------------------------------------------------------- |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 305 | |
Damien Martin-Guillerez | ba306ec | 2016-10-28 10:01:24 +0000 | [diff] [blame] | 306 | For IntelliJ, check out the [IntelliJ with Bazel plugin](https://ij.bazel.build). |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 307 | |
Damien Martin-Guillerez | ba306ec | 2016-10-28 10:01:24 +0000 | [diff] [blame] | 308 | For XCode, check out [Tulsi](http://tulsi.bazel.build/). |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 309 | |
Han-Wen Nienhuys | 0cd6d15 | 2016-10-25 20:18:38 +0000 | [diff] [blame] | 310 | For Eclipse, check out [E4B plugin](https://github.com/bazelbuild/e4b). |
| 311 | |
| 312 | For other IDEs, check out the [blog |
Damien Martin-Guillerez | ba306ec | 2016-10-28 10:01:24 +0000 | [diff] [blame] | 313 | post](https://bazel.build/blog/2016/06/10/ide-support.html) on how these |
Han-Wen Nienhuys | 0cd6d15 | 2016-10-25 20:18:38 +0000 | [diff] [blame] | 314 | plugins work. |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 315 | |
| 316 | I use Jenkins/CircleCI/TravisCI. How does Bazel interoperate with CI systems? |
| 317 | ----------------------------------------------------------------------------- |
| 318 | |
| 319 | Bazel returns a non-zero exit code if the build or test invocation |
| 320 | fails, and this should be enough for basic CI integration. Since |
| 321 | Bazel does not need clean builds for correctness, the CI system should not |
| 322 | be configured to clean before starting a build/test run. |
| 323 | |
| 324 | Further details on exit codes are in the [User Manual](docs/bazel-user-manual.html). |
| 325 | |
| 326 | What future features can we expect in Bazel? |
| 327 | -------------------------------------------- |
| 328 | |
| 329 | Our initial goal is to work on Google's internal use-cases. This |
| 330 | includes Google's principal languages (C++, Java, Go) and major |
| 331 | platforms (Linux, Android, iOS). For practical reasons, not all of |
| 332 | these are currently open-sourced. For more details see our |
| 333 | [roadmap](roadmap.html). |
| 334 | |
| 335 | What about Python? |
| 336 | ------------------ |
| 337 | |
| 338 | It is possible to write Python rules as extensions (see below). See |
| 339 | the following files for an example of generating self-contained zip |
| 340 | files for python: |
| 341 | |
| 342 | <https://github.com/bazelbuild/bazel/blob/master/tools/build_rules/py_rules.bzl>\\ |
| 343 | <https://github.com/bazelbuild/bazel/tree/master/examples/py> |
| 344 | |
| 345 | We have opened up a subset of our internal Python rules, so they |
| 346 | can be used as helper scripts as part of a build. |
| 347 | |
| 348 | Simplistic support for PEX-style binaries is at |
| 349 | [here](https://github.com/bazelbuild/bazel/blob/master/tools/build_rules/py_rules.bzl). |
| 350 | |
| 351 | |
| 352 | What about Go? |
| 353 | -------------- |
| 354 | |
Han-Wen Nienhuys | 0cd6d15 | 2016-10-25 20:18:38 +0000 | [diff] [blame] | 355 | Bazel supports Go through an [external rule set](https://github.com/bazelbuild/rules_go) |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 356 | |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 357 | |
| 358 | Can I use Bazel for my [INSERT LANGUAGE HERE] project? |
| 359 | ------------------------------------------------------ |
| 360 | |
| 361 | We have an extension mechanism called Skylark that allows you to add new rules |
| 362 | without recompiling Bazel. |
| 363 | |
| 364 | For documentation: see [here](/docs/skylark/index.html). We have support for |
| 365 | several languages that use that extension mechanism, see our |
| 366 | [build encyclopedia](/docs/be/overview.html) for the full |
| 367 | list of supported languages. |
| 368 | |
| 369 | I need more functionality. Can I add rules that are compiled into Bazel? |
| 370 | ------------------------------------------------------------------------ |
| 371 | |
| 372 | If our extension mechanism is insufficient for your use case, email |
| 373 | the mailing list for advice: <bazel-discuss@googlegroups.com>. |
| 374 | |
| 375 | Can I contribute to the Bazel code base? |
| 376 | ---------------------------------------- |
| 377 | |
| 378 | See our [contribution guidelines](contributing.html). |
| 379 | |
| 380 | Why isn't all development done in the open? |
| 381 | ------------------------------------------- |
| 382 | |
| 383 | We still have to refactor the interfaces between the public code in |
| 384 | Bazel and our internal extensions frequently. This makes it hard to do |
| 385 | much development in the open. See our [governance plan](governance.html) |
| 386 | for more details. |
| 387 | |
| 388 | How do I contact the team? |
| 389 | -------------------------- |
| 390 | |
| 391 | We are reachable at <bazel-discuss@googlegroups.com>. |
| 392 | |
| 393 | Where do I report bugs? |
| 394 | ----------------------- |
| 395 | |
| 396 | Send an e-mail to <bazel-discuss@googlegroups.com> or file a bug |
| 397 | [on GitHub](https://github.com/bazelbuild/bazel/issues). |
| 398 | |
| 399 | |
| 400 | |
| 401 | What's up with the word "Blaze" in the codebase? |
| 402 | ------------------------------------------------ |
| 403 | |
| 404 | This is an internal name for the tool. Please refer to Bazel as |
| 405 | Bazel. |
| 406 | |
| 407 | |
| 408 | Why do other Google projects (Android, Chrome) use other build tools? |
| 409 | --------------------------------------------------------------------- |
| 410 | |
Laszlo Csomor | e1940f2 | 2016-11-09 15:42:49 +0000 | [diff] [blame] | 411 | Until the first (Alpha) release, Bazel was not available externally, so open |
| 412 | source projects such as Chromium, Android, etc. could not use it. In addition, |
| 413 | the original lack of Windows support was a problem for building Windows |
| 414 | applications, such as Chrome. |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 415 | |
| 416 | |
| 417 | How do you pronounce "Bazel"? |
| 418 | ----------------------------- |
| 419 | |
| 420 | The same way as "basil" (the herb) in US English: "BAY-zel". It rhymes with |
| 421 | "hazel". IPA: /ˈbeɪzˌəl/ |