1.. _showcase-sense-tutorial-explore: 2 3======================== 42. Explore build targets 5======================== 6.. _targets: https://bazel.build/concepts/build-ref#targets 7.. _BUILD.bazel files: https://bazel.build/concepts/build-files 8 9Throughout the Sense repository there are lots of `BUILD.bazel files`_. 10Each ``BUILD.bazel`` file contains one or more `targets`_. These targets 11are your entrypoints for doing lots of useful, common tasks, such as: 12 13* Building source code 14* Running unit tests 15* Connecting to a device over a console 16* Flashing a binary to a device 17 18------------- 19Query targets 20------------- 21When you're starting a new Bazel-based project, you'll need to create 22your own Bazel targets. When you're ramping up on an existing Bazel 23codebase, these targets are a good way to get an overview of how the 24project works. Explore Sense's Bazel targets now: 25 26.. tab-set:: 27 28 .. tab-item:: VS Code 29 :sync: vsc 30 31 #. Press :kbd:`Control+Shift+E` (:kbd:`Command+Shift+E` on macOS) to open 32 the **Explorer** view. 33 34 #. Within the **Explorer** list, expand the **Bazel Targets** 35 section. 36 37 .. admonition:: Where is this? 38 39 Look at the bottom left of your VS Code window. The source code 40 section (the one labeled **Sense**) is expanded by default so 41 the **Bazel Targets** section gets pushed down to the far bottom. 42 You can collapse the **Sense** section to make the **Bazel 43 Targets** section easier to find. 44 45 The **Bazel Targets** section should look like this: 46 47 .. figure:: https://storage.googleapis.com/pigweed-media/sense/build_targets_v1.png 48 49 .. admonition:: Troubleshooting 50 51 * There's only a button that says **REFRESH TARGET LIST**. Click that 52 button and wait 30-60 seconds. It should get populated after that. 53 54 * The section is empty. Wait 30-60 seconds. It should get populated 55 after that. 56 57 This section provides an overview of all of the project's build 58 rules. Right-clicking a rule lets you build or run that rule. You'll be 59 using this UI a lot throughout the tutorial. 60 61 #. Expand the **//apps/blinky** group. 62 63 .. note:: 64 65 ``//`` means the root directory of your Sense repository. 66 If you cloned Sense to ``~/sense/``, then ``//`` would 67 be located at ``~/sense/``. 68 69 .. figure:: https://storage.googleapis.com/pigweed-media/blinky_targets_v1.png 70 71 .. tab-item:: CLI 72 :sync: cli 73 74 #. List all Bazel targets: 75 76 .. code-block:: console 77 78 bazelisk query //... 79 80 You should see a long list of targets, like this: 81 82 .. code-block:: console 83 84 //:copy_clangd 85 # … 86 //apps/blinky:blinky 87 # … 88 //device:bme688 89 # … 90 //modules/air_sensor:air_sensor 91 # … 92 //system:headers 93 # … 94 //targets:malloc 95 # … 96 //tools:air_measure 97 # … 98 99.. _hardware abstraction layer: https://en.wikipedia.org/wiki/Hardware_abstraction 100.. _RP2040: https://www.raspberrypi.com/products/rp2040/ 101.. _RP2350: https://www.raspberrypi.com/products/rp2350/ 102 103---------------- 104Targets overview 105---------------- 106Here's a quick summary of Sense's targets: 107 108* **//apps/<app>**: Targets for ``<app>``, where ``<app>`` is a placeholder 109 for a real app name like ``blinky`` or ``production``. Notice that each app 110 has per-platform targets. E.g. ``:rp2040_blinky.elf`` produces a binary 111 that can run on the Pico 1 (the `RP2040`_ is the microprocessor on that 112 board) whereas ``rp2350_blinky.elf`` produces a binary for the Pico 2, 113 which is powered by the `RP2350`_ microprocessor. ``:simulator_blinky`` 114 produces a binary that can run on your development host. 115* **//devices**: Targets for building device drivers. 116* **//modules/<module>**: Targets for building platform-agnostic 117 `hardware abstraction layer`_ modules. 118* **//system**: Targets for building the general middleware system 119 that every application runs on top of. 120* **//targets/<target>**: Targets for compiling the applications 121 on specific platforms such as the RP2040 or RP2350. 122* **//tools**: Targets for building and running tools that accompany 123 the apps, such as the script for connecting to devices over 124 :ref:`module-pw_console`. 125 126.. _showcase-sense-tutorial-explore-summary: 127 128------- 129Summary 130------- 131In a Bazel-based project, pretty much all common development tasks like 132building, testing, flashing, connecting to devices, and so on can be done 133through Bazel targets. Bazel makes it easy to see all targets at a 134glance. When onboarding onto a new project, browsing the list of targets 135can be a helpful way for building a top-down intuition about how the 136project works. 137 138Next, head over to :ref:`showcase-sense-tutorial-build` to start building 139binaries the Bazel way. 140