2. Explore build targets#

Throughout the Sense repository there are lots of BUILD.bazel files. Each BUILD.bazel file contains one or more targets. These targets are your entrypoints for doing lots of useful, common tasks, such as:

  • Building source code

  • Running unit tests

  • Connecting to a device over a console

  • Flashing a binary to a device

Query targets#

When you’re starting a new Bazel-based project, you’ll need to create your own Bazel targets. When you’re ramping up on an existing Bazel codebase, these targets are a good way to get an overview of how the project works. Explore Sense’s Bazel targets now:

  1. Press Control+Shift+E (Command+Shift+E on macOS) to open the Explorer view.

  2. Within the Explorer list, expand the Bazel Targets section.

    Where is this?

    Look at the bottom left of your VS Code window. The source code section (the one labeled Sense) is expanded by default so the Bazel Targets section gets pushed down to the far bottom. You can collapse the Sense section to make the Bazel Targets section easier to find.

    The Bazel Targets section should look like this:

    https://storage.googleapis.com/pigweed-media/sense/build_targets_v1.png

    Troubleshooting

    • There’s only a button that says REFRESH TARGET LIST. Click that button and wait 30-60 seconds. It should get populated after that.

    • The section is empty. Wait 30-60 seconds. It should get populated after that.

    This section provides an overview of all of the project’s build rules. Right-clicking a rule lets you build or run that rule. You’ll be using this UI a lot throughout the tutorial.

  3. Expand the //apps/blinky group.

    Note

    // means the root directory of your Sense repository. If you cloned Sense to ~/sense/, then // would be located at ~/sense/.

    https://storage.googleapis.com/pigweed-media/blinky_targets_v1.png
  1. List all Bazel targets:

    bazelisk query //...
    

You should see a long list of targets, like this:

//:copy_clangd
# //apps/blinky:blinky
# //device:bme688
# //modules/air_sensor:air_sensor
# //system:headers
# //targets:malloc
# //tools:air_measure
# 

Targets overview#

Here’s a quick summary of Sense’s targets:

  • //apps/<app>: Targets for <app>, where <app> is a placeholder for a real app name like blinky or production. Notice that each app has per-platform targets. E.g. :rp2040_blinky.elf produces a binary that can run on the Pico 1 (the RP2040 is the microprocessor on that board) whereas rp2350_blinky.elf produces a binary for the Pico 2, which is powered by the RP2350 microprocessor. :simulator_blinky produces a binary that can run on your development host.

  • //devices: Targets for building device drivers.

  • //modules/<module>: Targets for building platform-agnostic hardware abstraction layer modules.

  • //system: Targets for building the general middleware system that every application runs on top of.

  • //targets/<target>: Targets for compiling the applications on specific platforms such as the RP2040 or RP2350.

  • //tools: Targets for building and running tools that accompany the apps, such as the script for connecting to devices over pw_console.

Summary#

In a Bazel-based project, pretty much all common development tasks like building, testing, flashing, connecting to devices, and so on can be done through Bazel targets. Bazel makes it easy to see all targets at a glance. When onboarding onto a new project, browsing the list of targets can be a helpful way for building a top-down intuition about how the project works.

Next, head over to 3. Build an app to start building binaries the Bazel way.