Bazel style guide and best practices

Overview

This guide defines the formatting, coding conventions, and best practices for Bazel BUILD.bazel and .bzl files within the Fuchsia platform codebase.

The Fuchsia project follows the public Bazel BUILD Style Guide and .bzl Style Guide, with a few exceptions. In addition, the Fuchsia project enforces some recommendations and best practices.

In addition to covering those exceptions, this guide captures advice from other parts of the Bazel documentation, codifies some best practices, provides guidance related to paths and symbols specific to the Fuchsia codebase, highlights equivalents and differences for those familiar with the use of GN in the Fuchsia codebase, and adds guidance to facilitate consistency and readability in the Fuchsia codebase.

Status

This document is under active development. It represents the current set of common practices and expectations for Bazel files in the Fuchsia platform codebase. It is not yet comprehensive, and will evolve.

See Feedback for information on how to provide feedback or suggest additions or other changes.

Fuchsia-specific style and best practices

The common style guide and best practices apply to all Bazel files.

There is additional guidance specific to:

Automated tooling

Format code locally using fx format-code before uploading for review.

Over time, mechanically verifiable parts of this guidance will be enforced on the static-checks CQ bots via SHAC checks. This already includes running buildifier.

It is recommended to run these checks locally before uploading for review by running fx host-tool shac check.

Process

This document is owned by the Fuchsia Build team.

Feedback

Contact the Fuchsia Build team and/or file a bug.