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
- Host: GitHub
- URL: https://github.com/flolu/bazel
- Owner: flolu
- Created: 2023-02-23T12:00:08.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-25T10:04:00.000Z (almost 3 years ago)
- Last Synced: 2025-01-09T06:28:43.983Z (about 1 year ago)
- Topics: bazel, bazel-rules, bazelisk, build-tool, buildifier, github-actions, starlark, tutorial
- Language: Starlark
- Homepage: https://www.youtube.com/watch?v=6MXjAZWmn4Y
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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`