- Bazel is a tool to build and test software at any scale
- It's extremely fast and makes builds reproducible
- It's able to build any language
- It's used by many big companies
- The
WORKSPACEfile marks the root of a Bazel workspace BUILDfiles mark a directory as a package- Build targets are defined inside
BUILDfiles - Targets are defined by rules
- Rules are written in Starlark (But most end users won't rules themselves)
Installation
- Install Bazelisk to manage different version of Bazel
- With NPM:
npm i -g @bazel/bazelisk(requires Node.js) - On macOS:
brew install bazelisk
- With NPM:
Commands
bazel version(Get version of Bazel)bazel build //...(Build everything)bazel clean(Clean Bazel outputs)bazel build //files/...(Build everything inside thefilespackage)bazel build //:bazel_slogan(Only build thebazel_slogantarget)bazel test //...(Test everything)bazel query ...(List all targets)bazel query --noimplicit_deps 'deps(:bazel_slogan_test)' --output graph | dot -Tpng > graph.png(Generate a graph dependency graph of the:bazel_slogan_testtarget)
💡 You can also omit the
//
Development Environment
- Install the official Bazel extensions
- Install Buildifier for formatting
- With NPM:
npm i -g @bazel/buildifier(requires Node.js) - On macOS:
brew install buildifier
- With NPM: