1.. _showcase-sense-tutorial-explore: 2 3======================== 42. Explore build targets 5======================== 6.. _targets: https://bazel.build/concepts/build-ref#targets 7 8Throughout the Sense repository there are lots of ``BUILD.bazel`` files. 9Each ``BUILD.bazel`` file contains one or more `targets`_. These targets 10are your entrypoints for doing lots of useful, common tasks, such as: 11 12* Building a binary 13* Running unit tests 14* Connecting to a device over a console 15* Flashing a binary to a device 16 17When you're starting a new Bazel-based project, you'll need to create 18your own Bazel targets. When you're ramping up on an existing Bazel 19codebase, these targets are a good way to get an overview of how the 20project works. Explore Sense's Bazel targets now: 21 22.. tab-set:: 23 24 .. tab-item:: VS Code 25 :sync: vsc 26 27 #. Press :kbd:`Control+Shift+E` (:kbd:`Command+Shift+E` on macOS) to open 28 the **Explorer** view. 29 30 #. Within the **Explorer** list, expand the **Bazel Build Targets** 31 section. 32 33 .. admonition:: Where is this? 34 35 Look at the bottom left of your VS Code window. The source code 36 is expanded by default so the **Bazel Build Targets** section gets 37 pushed down to the far bottom. You can collapse the source code 38 section (the one labeled **Sense**) to make the **Bazel Build 39 Targets** section easier to find. 40 41 .. figure:: https://storage.googleapis.com/pigweed-media/sense/20240802/build_targets.png 42 43 This section provides an overview of all of the project's build 44 rules. Right-clicking a rule lets you build or run that rule. You'll be 45 using this UI a lot throughout the tutorial. 46 47 .. admonition:: Troubleshooting 48 49 * **The section is empty**. Just wait a little bit. It should get 50 populated after 30 seconds or so. It takes the Bazel extension 51 some time to find all the Bazel targets. 52 53 .. note:: 54 55 Although this UI is called **Bazel Build Targets** you may want to 56 think of it instead as just **Bazel Targets**. This UI isn't just 57 used for building. You also use it to run tests, connect to a device 58 over a console, and so on. 59 60 #. Expand the **//apps/blinky** group. 61 62 .. figure:: https://storage.googleapis.com/pigweed-media/sense/20240802/apps_blinky.png 63 64 .. note:: 65 66 ``//`` means the root directory of your Sense repository. 67 If you cloned Sense to ``~/sense``, then ``//apps/blinky`` would 68 be located at ``~/sense/apps/blinky``. 69 70 .. tab-item:: CLI 71 :sync: cli 72 73 #. List all Bazel targets: 74 75 .. code-block:: console 76 77 $ bazelisk query //... 78 79 You should see output like this: 80 81 .. code-block:: console 82 83 Starting local Bazel server and connecting to it... 84 //:copy_clangd 85 //:pw_console_config 86 //:refresh_compile_commands 87 //:refresh_compile_commands.check_python_version.py 88 //:refresh_compile_commands.py 89 //apps/blinky:blinky 90 //apps/blinky:flash 91 //apps/blinky:flash_rp2040 92 //apps/blinky:rp2040_blinky.elf 93 //apps/blinky:rp2040_console 94 //apps/blinky:rp2040_example_script 95 //apps/blinky:rp2040_toggle_blinky 96 //apps/blinky:rp2040_webconsole 97 //apps/blinky:simulator_blinky 98 //apps/blinky:simulator_console 99 //apps/blinky:simulator_webconsole 100 # ... 101 102.. _hardware abstraction layer: https://en.wikipedia.org/wiki/Hardware_abstraction 103 104Here's a quick summary of Sense's targets: 105 106* **//apps/<app>**: Targets for building ``<app>``, 107 flashing ``<app>`` to a Pico, simulating ``<app>`` 108 on your development host, and communicating with a device 109 running ``<app>`` over a console. We're using ``<app>`` as a placeholder 110 here, the real app names are ``blinky``, ``production``, and so on. 111 Note that there are different targets for building apps for different 112 platforms, e.g. ``:rp2040_blinky.elf`` for building the binary that runs 113 ``blinky`` on a Raspberry Pi RP2040 versus ``:simulator_blinky`` 114 for the binary that runs 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 for specific platforms such as the Raspberry Pi RP2040 MCU or 122 your development host. 123* **//tools**: Targets for building and running tools that accompany 124 the apps, such as the script for connecting to devices over 125 :ref:`module-pw_console`. 126 127.. _showcase-sense-tutorial-explore-summary: 128 129------- 130Summary 131------- 132In a Bazel-based project, pretty much all common development tasks like 133building, flashing, connecting to devices, and so on are usually done 134through Bazel targets. Bazel makes it easy to see all targets at a 135glance. When onboarding onto a new project, browsing the list of targets 136can be a helpful way for building a top-down intuition about how the 137project works. 138 139Next, head over to :ref:`showcase-sense-tutorial-build` to start building 140binaries the Bazel way. 141