1.. _showcase-sense-tutorial-build: 2 3================ 43. Build the app 5================ 6You can start building right away. There's no need to manually 7install dependencies or toolchains; Sense takes full advantage of Bazel's 8ability to automate dependency and toolchain management. 9Try building an app now: 10 11.. _task: https://code.visualstudio.com/docs/editor/tasks 12 13.. tab-set:: 14 15 .. tab-item:: VS Code 16 :sync: vsc 17 18 #. In **Bazel Build Targets** right-click the **//apps/blinky** folder 19 and select **Build Package Recursively**. A `task`_ launches in a VS 20 Code terminal. 21 22 .. figure:: https://storage.googleapis.com/pigweed-media/sense/20240802/build_package_recursively_v3.png 23 24 Bazel builds all targets that it finds within the ``//apps/blinky`` 25 directory. If there were targets in subdirectories, those would 26 get built, too. A successful build looks similar to this: 27 28 .. code-block:: console 29 30 INFO: Found 17 targets... 31 INFO: Elapsed time: 174.103s, Critical Path: 13.34s 32 INFO: 2375 processes: 480 internal, 1895 linux-sandbox. 33 INFO: Build completed successfully, 2375 total actions 34 35 .. tip:: 36 37 When you want to build just a single target, you can use 38 **Build Target** instead. This is useful when you know you 39 only need to build a single target (such as compiling a binary 40 for a specific platform) and want to do it quickly. Here we 41 had you build all the ``blinky`` targets in one go because you'll 42 be using a lot of them in later parts of the tutorial anyways. 43 44 #. Once the build finishes, press any key to close the task's terminal. 45 46 .. tab-item:: CLI 47 :sync: cli 48 49 Run the following command: 50 51 .. code-block:: console 52 53 $ bazelisk build //apps/blinky/... 54 55 A successful build looks similar to this: 56 57 .. code-block:: console 58 59 $ bazelisk build //apps/blinky/... 60 INFO: Analyzed 17 targets (464 packages loaded, 28991 targets configured). 61 INFO: From Linking external/rules_libusb~~libusb~libusb/libusb-1.0.so: 62 # ... 63 INFO: Found 17 targets... 64 INFO: Elapsed time: 314.300s, Critical Path: 26.73s 65 INFO: 2496 processes: 582 internal, 1914 linux-sandbox. 66 INFO: Build completed successfully, 2496 total actions 67 68 .. tip:: 69 70 Pigweed recommends always running ``bazelisk`` rather than ``bazel`` 71 because ``bazelisk`` ensures that you always run the correct version 72 of Bazel, as defined in a project's ``.bazelversion`` file. In some 73 cases ``bazel`` also does the right thing, but it's easier to remember 74 to just always use ``bazelisk``. 75 76.. admonition:: Troubleshooting 77 78 * **Warnings during the build**. As long as you see ``Build completed 79 successfully`` you should be able to complete the rest of the 80 tutorial. We generally work to remove all these warnings but they 81 pop up from time-to-time as we continue to iterate on the Sense 82 codebase. 83 84 * **Long build times**. Two minutes is typical for the first 85 build. Pigweed builds a lot of things from source, such as 86 the Protocol Buffer compiler, ``libusb``, and more. 87 88.. _showcase-sense-tutorial-build-summary: 89 90------- 91Summary 92------- 93You've now got some familiarity with how to build binaries in Bazel-based 94projects. 95 96.. _target: https://bazel.build/concepts/build-ref#targets 97 98One interesting thing about Bazel: it's not actually necessary to build an app 99before flashing it. Imagine you have a Bazel `target`_ that automates the 100process of flashing a binary to some hardware. You will see an example of this 101later in :ref:`showcase-sense-tutorial-flash`. If that flashing target depends 102on another target for actually building the binary, Bazel figures out that it 103must do the "build the binary" target before it can do the "flash the hardware" 104target. 105 106Next, head over to :ref:`showcase-sense-tutorial-intel` to learn how to 107use the Pigweed extension for VS Code to navigate a codebase that 108supports multiple hardware platforms. If you're not using VS Code you 109can skip ahead to :ref:`showcase-sense-tutorial-hosttests` because this 110code intelligence feature is currently only supported in VS Code. 111