Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.79 KB

README.md

File metadata and controls

47 lines (35 loc) · 1.79 KB

🌿 Bazel for beginners

Getting started with Bazel for absolute beginners

About Bazel

  • 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

Bazel Basics

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

Usage

Installation

  • Install 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
  • Install Buildifier for formatting
    • With NPM: npm i -g @bazel/buildifier (requires Node.js)
    • On macOS: brew install buildifier