An open API service indexing awesome lists of open source software.

https://github.com/flolu/bazel

🌿 Getting started with Bazel for absolute beginners
https://github.com/flolu/bazel

bazel bazel-rules bazelisk build-tool buildifier github-actions starlark tutorial

Last synced: 11 months ago
JSON representation

🌿 Getting started with Bazel for absolute beginners

Awesome Lists containing this project

README

          


🌿 Bazel for beginners


Getting started with Bazel for absolute beginners


# About Bazel

- [Bazel](https://bazel.build) 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](https://bazel.build/community/users)

# Bazel Basics

- The `WORKSPACE` file marks the root of a Bazel **workspace**
- `BUILD` files mark a directory as a **package**
- Build **targets** are defined inside`BUILD` files
- Targets are defined by **rules**
- Rules are written in Starlark (But most end users won't rules themselves)

# Usage

**Installation**

- Install [Bazelisk](https://github.com/bazelbuild/bazelisk) to manage different version of Bazel
- With NPM: `npm i -g @bazel/bazelisk` (requires Node.js)
- On macOS: `brew install bazelisk`

**Commands**

- `bazel version` (Get version of Bazel)
- `bazel build //...` (Build everything)
- `bazel clean` (Clean Bazel outputs)
- `bazel build //files/...` (Build everything inside the `files` package)
- `bazel build //:bazel_slogan` (Only build the `bazel_slogan` target)
- `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_test` target)

> 💡 You can also omit the `//`

**Development Environment**

- Install the official [Bazel extensions](https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel)
- Install [Buildifier](https://github.com/bazelbuild/buildtools/tree/master/buildifier) for formatting
- With NPM: `npm i -g @bazel/buildifier` (requires Node.js)
- On macOS: `brew install buildifier`