blob: 946e609d1f8d0437512d40addf656c8bee00e40e [file] [log] [blame] [view]
Kristina Chodorow974b2082015-03-31 14:49:30 +00001---
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +00002layout: default
3title: FAQ
4nav: faq
Kristina Chodorow974b2082015-03-31 14:49:30 +00005---
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +00006
7What is Bazel?
8--------------
9
10Bazel is a tool that automates software builds and tests. Supported build tasks
11include running compilers and linkers to produce executable programs and
12libraries, and assembling deployable packages for Android, iOS and other target
13environments. Bazel is similar to other tools like Make, Ant, Gradle, Buck,
14Pants and Maven.
15
16What is special about Bazel?
17----------------------------
18
19Bazel was designed to fit the way software is developed at Google. It
20has 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
50Why 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
78Where did Bazel come from?
79--------------------------
80
81Bazel is a flavor of the tool that Google uses to build its server
82software internally. It has expanded to build other software as well,
83like mobile apps (iOS, Android) that connect to our servers.
84
85Did you rewrite your internal tool as open-source? Is it a fork?
86----------------------------------------------------------------
87
88Bazel shares most of its code with the internal tool and its rules
89are used for millions of builds every day.
90
91Why did Google build Bazel?
92---------------------------
93
94A long time ago, Google built its software using large, generated
95Makefiles. These led to slow and unreliable builds, which began to
96interfere with our developers' productivity and the company's
97agility. Bazel was a way to solve these problems.
98
99Does Bazel require a build cluster?
100-----------------------------------
101
102Google's in-house flavor of Bazel does use [build
103clusters](http://google-engtools.blogspot.com/2011/09/build-in-cloud-distributing-build-steps.html),
104so Bazel does have hooks in the code base to plug in a remote build
105cache or a remote execution system.
106
107The open source Bazel code runs build operations locally. We believe
Han-Wen Nienhuys0cd6d152016-10-25 20:18:38 +0000108that this is fast enough for most of our users, but work is underway
109to provide [distributed caching](https://github.com/bazelbuild/bazel/issues/904).
110
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000111
112How does the Google development process work?
113----------------------------------------------
114
115For 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
128Bazel is a cornerstone of this philosophy: since Bazel requires all
129dependencies to be fully specified, we can predict which programs and
130tests are affected by a change, and vet them before submission.
131
132More background on the development process at Google can be found on
133the [eng tools blog](http://google-engtools.blogspot.com/).
134
135Why are you opening up Bazel?
136-----------------------------
137
138Building software should be fun and easy. Slow and unpredictable
139builds take the fun out of programming.
140
141Why 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
157Can I see examples?
158-------------------
159
160Yes. For a simple example, see:
161
162 <https://github.com/bazelbuild/bazel/blob/master/examples/cpp/BUILD>
163
164The Bazel source code itself provides a more complex example:
165
166 <https://github.com/bazelbuild/bazel/blob/master/src/BUILD>
167
168What is Bazel best at?
169----------------------
170
171Bazel 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
178Where can I run Bazel?
179---------------------------------
180
181Currently, Linux and Mac OS X. Porting to other UNIX platforms should be
182straightforward, as long as a JDK is available for the platform.
183
184What about Windows?
185-------------------
186
187Due to its UNIX heritage, porting Bazel to Windows is significant work. For
188example, Bazel uses symlinks extensively, which has varying levels of support
189across Windows versions.
190
Laszlo Csomore1940f22016-11-09 15:42:49 +0000191As of version [0.3.0](https://github.com/bazelbuild/bazel/releases/tag/0.3.0)
192Bazel supports Windows (bootstrapping itself and running builds), and we are
193actively working on improving this support. See our
194[blog post](https://bazel.build/blog/2016/09/07/bazel-windows.html) for more
195information, 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-Guillerez95a54b92016-07-28 12:47:11 +0000196
197What 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
212How stable is Bazel's feature set?
213----------------------------------
214
215The core features (C++, Java, and shell rules) have extensive use
216inside Google, so they are thoroughly tested and have very little
217churn. Similarly, we test new versions of Bazel across hundreds of
218thousands of targets every day to find regressions, and we release new
219versions multiple times every month.
220
221In short, except for features marked as experimental, Bazel should Just Work.
222Changes to non-experimental rules will be backward compatible. A more detailed
223list of feature support statuses can be found in our
224[support document](support.html).
225
226How stable is Bazel as a binary?
227--------------------------------
228
229Inside Google, we make sure that Bazel crashes are very rare. This
230should also hold for our open source codebase.
231
232How can I start using Bazel?
233----------------------------
234
235See our [getting started document](docs/getting-started.html).
236
237Doesn't Docker solve the reproducibility problems?
238--------------------------------------------------
239
240With Docker you can easily create sandboxes with fixed OS releases,
241for example, Ubuntu 12.04, Fedora 21. This solves the problem of
242reproducibility for the system environment -- that is, "which version of
243/usr/bin/c++ do I need?"
244
245Docker does not address reproducibility with regard to changes in the
246source code. Running Make with an imperfectly written Makefile inside a
247Docker container can still yield unpredictable results.
248
249Inside Google, we check tools into source control for reproducibility.
250In this way, we can vet changes to tools ("upgrade GCC to 4.6.1") with
251the same mechanism as changes to base libraries ("fix bounds check in
252OpenSSL").
253
254Can I build binaries for deployment on Docker?
255----------------------------------------------
256
257With Bazel, you can build standalone, statically linked binaries in
258C/C++, and self-contained jar files for Java. These run with few
259dependencies on normal UNIX systems, and as such should be simple to
260install inside a Docker container.
261
262Bazel has conventions for structuring more complex programs, for example, a
263Java program that consumes a set of data files, or runs another
264program as subprocess. It is possible to package up such environments
265as standalone archives, so they can be deployed on different systems,
266including Docker images.
267
268Can I build Docker images with Bazel?
269-------------------------------------
270
271Yes, you can use our
Damien Martin-Guillerezba306ec2016-10-28 10:01:24 +0000272[Docker rules](http://bazel.build/docs/be/docker.html)
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000273to build reproducible Docker images.
274
275Will Bazel make my builds reproducible automatically?
276-----------------------------------------------------
277
278For Java and C++ binaries, yes, assuming you do not change the
279toolchain. If you have build steps that involve custom recipes
280(for example, executing binaries through a shell script inside a rule), you
281will 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
296Do you have binary releases?
297----------------------------
298
299Yes, you can find the latest release binaries
300[here](https://github.com/bazelbuild/bazel/releases/latest). Our release
Damien Martin-Guillerezba306ec2016-10-28 10:01:24 +0000301policy is documented [here](http://bazel.build/support.html).
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000302
Han-Wen Nienhuys0cd6d152016-10-25 20:18:38 +0000303I use Eclipse/IntelliJ/XCode. How does Bazel interoperate with IDEs?
304--------------------------------------------------------------------
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000305
Damien Martin-Guillerezba306ec2016-10-28 10:01:24 +0000306For IntelliJ, check out the [IntelliJ with Bazel plugin](https://ij.bazel.build).
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000307
Damien Martin-Guillerezba306ec2016-10-28 10:01:24 +0000308For XCode, check out [Tulsi](http://tulsi.bazel.build/).
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000309
Han-Wen Nienhuys0cd6d152016-10-25 20:18:38 +0000310For Eclipse, check out [E4B plugin](https://github.com/bazelbuild/e4b).
311
312For other IDEs, check out the [blog
Damien Martin-Guillerezba306ec2016-10-28 10:01:24 +0000313post](https://bazel.build/blog/2016/06/10/ide-support.html) on how these
Han-Wen Nienhuys0cd6d152016-10-25 20:18:38 +0000314plugins work.
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000315
316I use Jenkins/CircleCI/TravisCI. How does Bazel interoperate with CI systems?
317-----------------------------------------------------------------------------
318
319Bazel returns a non-zero exit code if the build or test invocation
320fails, and this should be enough for basic CI integration. Since
321Bazel does not need clean builds for correctness, the CI system should not
322be configured to clean before starting a build/test run.
323
324Further details on exit codes are in the [User Manual](docs/bazel-user-manual.html).
325
326What future features can we expect in Bazel?
327--------------------------------------------
328
329Our initial goal is to work on Google's internal use-cases. This
330includes Google's principal languages (C++, Java, Go) and major
331platforms (Linux, Android, iOS). For practical reasons, not all of
332these are currently open-sourced. For more details see our
333[roadmap](roadmap.html).
334
335What about Python?
336------------------
337
338It is possible to write Python rules as extensions (see below). See
339the following files for an example of generating self-contained zip
340files 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
345We have opened up a subset of our internal Python rules, so they
346can be used as helper scripts as part of a build.
347
348Simplistic support for PEX-style binaries is at
349[here](https://github.com/bazelbuild/bazel/blob/master/tools/build_rules/py_rules.bzl).
350
351
352What about Go?
353--------------
354
Han-Wen Nienhuys0cd6d152016-10-25 20:18:38 +0000355Bazel supports Go through an [external rule set](https://github.com/bazelbuild/rules_go)
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000356
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000357
358Can I use Bazel for my [INSERT LANGUAGE HERE] project?
359------------------------------------------------------
360
361We have an extension mechanism called Skylark that allows you to add new rules
362without recompiling Bazel.
363
364For documentation: see [here](/docs/skylark/index.html). We have support for
365several languages that use that extension mechanism, see our
366[build encyclopedia](/docs/be/overview.html) for the full
367list of supported languages.
368
369I need more functionality. Can I add rules that are compiled into Bazel?
370------------------------------------------------------------------------
371
372If our extension mechanism is insufficient for your use case, email
373the mailing list for advice: <bazel-discuss@googlegroups.com>.
374
375Can I contribute to the Bazel code base?
376----------------------------------------
377
378See our [contribution guidelines](contributing.html).
379
380Why isn't all development done in the open?
381-------------------------------------------
382
383We still have to refactor the interfaces between the public code in
384Bazel and our internal extensions frequently. This makes it hard to do
385much development in the open. See our [governance plan](governance.html)
386for more details.
387
388How do I contact the team?
389--------------------------
390
391We are reachable at <bazel-discuss@googlegroups.com>.
392
393Where do I report bugs?
394-----------------------
395
396Send an e-mail to <bazel-discuss@googlegroups.com> or file a bug
397[on GitHub](https://github.com/bazelbuild/bazel/issues).
398
399
400
401What's up with the word "Blaze" in the codebase?
402------------------------------------------------
403
404This is an internal name for the tool. Please refer to Bazel as
405Bazel.
406
407
408Why do other Google projects (Android, Chrome) use other build tools?
409---------------------------------------------------------------------
410
Laszlo Csomore1940f22016-11-09 15:42:49 +0000411Until the first (Alpha) release, Bazel was not available externally, so open
412source projects such as Chromium, Android, etc. could not use it. In addition,
413the original lack of Windows support was a problem for building Windows
414applications, such as Chrome.
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000415
416
417How do you pronounce "Bazel"?
418-----------------------------
419
420The same way as "basil" (the herb) in US English: "BAY-zel". It rhymes with
421"hazel". IPA: /ˈbeɪzˌəl/