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

https://github.com/nnichols/bite-sized-bazel

Step-by-step guides to Bazel 8
https://github.com/nnichols/bite-sized-bazel

bazel bazel-examples guide tutorial

Last synced: 2 days ago
JSON representation

Step-by-step guides to Bazel 8

Awesome Lists containing this project

README

          

# Bite-Sized Bazel

This repository is an educational, narrative guide to creating a new Bazel project from scratch.
The wiki for this repository contains a step-by-step guide that iteratively builds up a Bazel project in bite-sized pieces.
We'll cover the basics of Bazel, how to set up your workspace, how to define and build your own targets, and more.

## Lessons

The lessons can be found in the [wiki of this repository.](https://github.com/nnichols/bite-sized-bazel/wiki)
They progressively build up the repository from an initial, empty commit to the current state.

- [Lesson 1: Installing Bazel](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-1:-Installing-Bazel)
- Installs Bazel on your machine and sets up the repository as a Bazel project.
- [Lesson 2: Creating Packages](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-2:-Creating-Packages)
- Creates a few basic packages, links them together, and explores the dependency graph.
- [Lesson 3: Building Artifacts](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-3:-Building-Artifacts)
- Installs Java and Python, and builds executable binaries with both languages.
- [Lesson 4: Dependency Management](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-4:-Dependency-Management)
- Develops internally usable Java and Python libraries, and downloads external artifacts from Maven Central and PyPI.
- [Lesson 5: Executing Tests](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-5:-Executing-Tests)
- Writes and runs unit tests for both Java and Python code.
- [Lesson 6: General Rules](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-6:-General-Rules)
- Explores the built-in general rules provided by Bazel.
- [Lesson 7: Authoring Rules](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-7:-Authoring-Rules)
- Extends Bazel by writing custom rules in Starlark.
- [Lesson 8: Build Tools](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-8:-Build-Tools)
- Introduces `buildifier` and `buildozer` for the programmatic manipulation of BUILD and .bzl files.
- [Lesson 9: Symbolic Macros](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-9:-Symbolic-Macros)
- Extends Bazel by creating a symbolic macro which generates multiple targets at once.
- [Lesson 10: Toolchains](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-10:-Toolchains)
- Extends Bazel with rules which have system-specific dependencies.
- [Lesson 11: Advanced Toolchains](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-11:-Advanced-Toolchains)
- Extends Bazel with rules that require their own, language-specific source code.
- [Lesson 12: Stardoc](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-12:-Stardoc)
- Generating API documentation for custom Starlark rules.
- [Lesson 13: Aspects](https://github.com/nnichols/bite-sized-bazel/wiki/Lesson-13:-Aspects)
- Explores additional routes for dependency metadata to flow through the graph.

## Disclaimers

This is intended as an educational resource, not a production-ready project.
For the sake of narrative consistency, we'll be pinning versions of most dependencies and Bazel itself.
Over time, these will naturally fall out of date- please refer to the official documentation for the most current information.

Furthermore, this guide is not exhaustive.
Bazel is a powerful tool that can be used in many different ways and enables developers to build their own tooling, workflows, and more.
This guide is intended to help understand the fundamentals of Bazel, not to prescribe a particular toolchain, workflow, or process.

### Pinned Versions

Explicitly pinned tools will be documented below:

- [**Bazel**](https://bazel.build/): 8.3.1
- The build tool this repository describes
- [**rules_java**](https://github.com/bazelbuild/rules_java/tree/8.12.0): 8.12.0
- A Bazel toolchain for the Java Programming Language
- [**rules_python**](https://github.com/bazel-contrib/rules_python): 1.6.1
- A Bazel toolchain for the Python Programming Language
- [**OpenJDK**](https://openjdk.org/projects/jdk/21/): 21.0.8
- An open-source Java Development Kit
- [**Python**](https://www.python.org/downloads/release/python-3137/): 3.11.9
- The Python Programming Language
- [**rules_jvm_external**](https://github.com/bazel-contrib/rules_jvm_external?tab=readme-ov-file): 6.8
- A Bazel toolchain for managing external Maven dependencies
- [**Gson**](https://github.com/google/gson): 2.13.2
- A Java library for handling JSON
- [**json-lineage**](https://github.com/Salaah01/json-lineage): 0.2.2
- A Python library for handling JSON
- [**jUnit**](https://junit.org/junit4/): 4.13.2
- A Java testing library and framework
- [**buildifier**](https://github.com/bazelbuild/buildtools/blob/main/buildifier/README.md): 8.2.1
- A command-line linter for Starlark
- [**buildozer**](https://github.com/bazelbuild/buildtools/blob/main/buildozer/README.md): 8.2.1
- A command-line tool for manipulating Starlark
- [**babashka**](https://github.com/babashka/babashka): 1.12.209
- A hosted port of the Clojure Programming language on GraalVM
- [**platforms**](https://github.com/bazelbuild/platforms): 1.0.0
- A Bazel repository which defines system constraints
- [**clojure**](https://github.com/clojure/clojure): 1.12.3
- The Clojure Programming Language
- [**clojure.spec.alpha**](https://github.com/clojure/spec.alpha): 0.5.238
- A Clojure library for schema validation
- [**clojure.core.specs.alpha**](https://github.com/clojure/core.specs.alpha): 0.4.74
- A Clojure library containing clojure.spec.alpha definitions for functionality in the core language
- [**Cheshire**](https://github.com/dakrone/cheshire): 6.1.0
- A Clojure library for handling JSON
- [**Stardoc**](https://github.com/bazelbuild/stardoc): 0.8.0
- Rules to generate API documentation for Starlark
- [**Skylib**](https://github.com/bazelbuild/bazel-skylib): 1.8.1
- A collection of Starlark utility functions

### Unpinned Tools

- [**bazelisk**](https://github.com/bazelbuild/bazelisk)
- Used to manage the running Bazel version
- [**Graphviz**](https://graphviz.org/)
- Used to visualize dependency graphs as images.
- [**jEnv**](https://github.com/jenv/jenv)
- Java version manager.
- [**pyenv**](https://github.com/pyenv/pyenv)
- Python version manager.

## Additional Resources

- [Glossary](https://github.com/nnichols/bite-sized-bazel/wiki/Glossary)
- [Further Reading Index](https://github.com/nnichols/bite-sized-bazel/wiki/Further-Reading)

## Licensing

This repository, the documentation, and all included code is licensed under the MIT License.
That said, it was primarily created for educational purposes, so please use accordingly.
See the [LICENSE](LICENSE) file for more details.