• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _showcase-sense-tutorial-build:
2
3===============
43. Build an app
5===============
6You can start building right away. There's no need to manually
7install dependencies or toolchains. Bazel automates dependency and
8toolchain management. Try building the ``blinky`` bringup app now:
9
10.. _task: https://code.visualstudio.com/docs/editor/tasks
11
12.. tab-set::
13
14   .. tab-item:: VS Code
15      :sync: vsc
16
17      #. In **Bazel Targets** right-click the **//apps/blinky** folder
18         and select **Build Package Recursively**.
19
20         .. figure:: https://storage.googleapis.com/pigweed-media/sense/build_package_recursively_v4.png
21
22         A `task`_ launches in a VS Code terminal.
23         Bazel builds all targets that it finds within the ``//apps/blinky``
24         directory. If there were targets in subdirectories, those would
25         get built, too.
26
27         A successful build looks like this:
28
29         .. code-block:: console
30
31            INFO: Found 17 targets...
32            INFO: Elapsed time: 174.103s, Critical Path: 13.34s
33            INFO: 2375 processes: 480 internal, 1895 linux-sandbox.
34            INFO: Build completed successfully, 2375 total actions
35
36         .. tip::
37
38            When you want to build just a single target, you can use
39            **Build Target** instead. This is useful when you know you
40            only need to build a single target (such as compiling a binary
41            for a specific platform) and want to do it quickly. Here we
42            had you build all the ``blinky`` targets in one go because you'll
43            be using a lot of them in later parts of the tutorial anyways.
44
45      #. Once the build finishes, press any key to close the task's terminal.
46
47   .. tab-item:: CLI
48      :sync: cli
49
50      Run the following command:
51
52      .. code-block:: console
53
54         bazelisk build //apps/blinky/...
55
56      A successful build looks similar to this:
57
58      .. code-block:: console
59
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 the Sense codebase and its dependencies
82     evolve.
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
96Next, head over to :ref:`showcase-sense-tutorial-intel` to learn how to
97use the Pigweed extension for VS Code to navigate a codebase that
98supports multiple hardware platforms. If you're not using VS Code you
99can skip ahead to :ref:`showcase-sense-tutorial-hosttests` because this
100code intelligence feature is currently only supported in VS Code.
101