xref: /aosp_15_r20/external/pigweed/docs/targets.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _docs-targets:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker================
4*61c4878aSAndroid Build Coastguard WorkerHardware targets
5*61c4878aSAndroid Build Coastguard Worker================
6*61c4878aSAndroid Build Coastguard WorkerPigweed is designed to be portable to many different hardware platforms.
7*61c4878aSAndroid Build Coastguard WorkerPigweed's GN build comes with an extensible target system that allows it to be
8*61c4878aSAndroid Build Coastguard Workerconfigured to build for any number of platforms, which all build simultaneously.
9*61c4878aSAndroid Build Coastguard Worker
10*61c4878aSAndroid Build Coastguard WorkerDefining a target
11*61c4878aSAndroid Build Coastguard Worker=================
12*61c4878aSAndroid Build Coastguard WorkerEach Pigweed target built by a project is defined within the GN build as a
13*61c4878aSAndroid Build Coastguard Workertoolchain providing the target's build parameters.
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard WorkerIn Pigweed, these target toolchains are defined as GN scopes, which are fed into
16*61c4878aSAndroid Build Coastguard Workera ``generate_toolchain`` template to create the complete GN toolchain.
17*61c4878aSAndroid Build Coastguard Worker
18*61c4878aSAndroid Build Coastguard WorkerHierarchical target structure
19*61c4878aSAndroid Build Coastguard Worker-----------------------------
20*61c4878aSAndroid Build Coastguard WorkerThe rationale for scope-based toolchains is to make Pigweed targets extensible.
21*61c4878aSAndroid Build Coastguard WorkerVariables from a toolchain can be forwarded into new scopes and then extended
22*61c4878aSAndroid Build Coastguard Workeror overriden. This facilitates the sharing of common configuration options
23*61c4878aSAndroid Build Coastguard Workerbetween toolchains, and allows for hierarchical structures. Upstream Pigweed
24*61c4878aSAndroid Build Coastguard Workermakes use of this heavily; it defines basic compiler-only configurations, uses
25*61c4878aSAndroid Build Coastguard Workerthese as a base for board-specific toolchains, then creates its final targets on
26*61c4878aSAndroid Build Coastguard Workertop of those.
27*61c4878aSAndroid Build Coastguard Worker
28*61c4878aSAndroid Build Coastguard Worker.. mermaid::
29*61c4878aSAndroid Build Coastguard Worker
30*61c4878aSAndroid Build Coastguard Worker  graph TD
31*61c4878aSAndroid Build Coastguard Worker    arm_gcc --> arm_gcc_cortex_m4
32*61c4878aSAndroid Build Coastguard Worker    arm_gcc --> arm_gcc_cortex_m4f
33*61c4878aSAndroid Build Coastguard Worker    arm_gcc_cortex_m4f --> arm_gcc_cortex_m4f_debug
34*61c4878aSAndroid Build Coastguard Worker    arm_gcc_cortex_m4f --> arm_gcc_cortex_m4f_size_optimized
35*61c4878aSAndroid Build Coastguard Worker    arm_gcc_cortex_m4f_debug --> stm32f429i_disc1_debug
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard WorkerToolchain target variables
38*61c4878aSAndroid Build Coastguard Worker--------------------------
39*61c4878aSAndroid Build Coastguard WorkerThe core of a toolchain is defining the tools it uses. This is done by setting
40*61c4878aSAndroid Build Coastguard Workerthe variables ``ar``, ``cc``, and ``cxx`` to the appropriate compilers. Pigweed
41*61c4878aSAndroid Build Coastguard Workerprovides many commonly used compiler configurations in the ``pw_toolchain``
42*61c4878aSAndroid Build Coastguard Workermodule.
43*61c4878aSAndroid Build Coastguard Worker
44*61c4878aSAndroid Build Coastguard WorkerThe rest of a Pigweed target's configuration is listed within a ``defaults``
45*61c4878aSAndroid Build Coastguard Workerscope in its toolchain. Every variable in this scope is an override of a GN
46*61c4878aSAndroid Build Coastguard Workerbuild argument defined in Pigweed. Some notable arguments include:
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard Worker* ``default_configs``: A list of GN configs to apply to every ``pw_*`` GN
49*61c4878aSAndroid Build Coastguard Worker  template. This is typically used to set compiler flags, optimization levels,
50*61c4878aSAndroid Build Coastguard Worker  global #defines, etc.
51*61c4878aSAndroid Build Coastguard Worker* ``default_public_deps``: List of GN targets which are added as a dependency
52*61c4878aSAndroid Build Coastguard Worker  to all ``pw_*`` GN targets. This is used to add global module dependencies.
53*61c4878aSAndroid Build Coastguard Worker* Facade backends: Pigweed defines facades to provide a common interface for
54*61c4878aSAndroid Build Coastguard Worker  core system features such as logging without assuming an implementation.
55*61c4878aSAndroid Build Coastguard Worker  When building a Pigweed target, the implementations for each of these must be
56*61c4878aSAndroid Build Coastguard Worker  chosen. The ``*_BACKEND`` build args that Pigweed defines are used to set
57*61c4878aSAndroid Build Coastguard Worker  these.
58*61c4878aSAndroid Build Coastguard Worker
59*61c4878aSAndroid Build Coastguard WorkerThere are many other build arguments that can be set, some of which are
60*61c4878aSAndroid Build Coastguard Workermodule-specific. A full list can be seen by running ``gn args --list out``,
61*61c4878aSAndroid Build Coastguard Workerand further documentation can be found within their respective modules.
62*61c4878aSAndroid Build Coastguard Worker
63*61c4878aSAndroid Build Coastguard WorkerExample Pigweed target
64*61c4878aSAndroid Build Coastguard Worker======================
65*61c4878aSAndroid Build Coastguard WorkerThe code below demonstrates how a project might configure one of its Pigweed
66*61c4878aSAndroid Build Coastguard Workertargets.
67*61c4878aSAndroid Build Coastguard Worker
68*61c4878aSAndroid Build Coastguard Worker.. code-block::
69*61c4878aSAndroid Build Coastguard Worker
70*61c4878aSAndroid Build Coastguard Worker   import("//build_overrides/pigweed.gni")
71*61c4878aSAndroid Build Coastguard Worker
72*61c4878aSAndroid Build Coastguard Worker   import("$dir_pw_toolchain/arm_gcc/toolchains.gni")
73*61c4878aSAndroid Build Coastguard Worker   import("$dir_pw_toolchain/generate_toolchain.gni")
74*61c4878aSAndroid Build Coastguard Worker
75*61c4878aSAndroid Build Coastguard Worker   my_target_scope = {
76*61c4878aSAndroid Build Coastguard Worker     # Use Pigweed's Cortex M4 toolchain as a base.
77*61c4878aSAndroid Build Coastguard Worker     _toolchain_base = pw_toolchain_arm_gcc.cortex_m4f_debug
78*61c4878aSAndroid Build Coastguard Worker
79*61c4878aSAndroid Build Coastguard Worker     # Forward everything except the defaults scope from that toolchain.
80*61c4878aSAndroid Build Coastguard Worker     forward_variables_from(_toolchain_base, "*", [ "defaults" ])
81*61c4878aSAndroid Build Coastguard Worker
82*61c4878aSAndroid Build Coastguard Worker     defaults = {
83*61c4878aSAndroid Build Coastguard Worker       # Forward everything from the base toolchain's defaults.
84*61c4878aSAndroid Build Coastguard Worker       forward_variables_from(_toolchain_base.defaults, "*")
85*61c4878aSAndroid Build Coastguard Worker
86*61c4878aSAndroid Build Coastguard Worker       # Extend with custom build arguments for the target.
87*61c4878aSAndroid Build Coastguard Worker       pw_log_BACKEND = dir_pw_log_tokenized
88*61c4878aSAndroid Build Coastguard Worker     }
89*61c4878aSAndroid Build Coastguard Worker   }
90*61c4878aSAndroid Build Coastguard Worker
91*61c4878aSAndroid Build Coastguard Worker   # Create the actual GN toolchain from the scope.
92*61c4878aSAndroid Build Coastguard Worker   generate_toolchain("my_target") {
93*61c4878aSAndroid Build Coastguard Worker     forward_variables_from(my_target_scope, "*")
94*61c4878aSAndroid Build Coastguard Worker   }
95*61c4878aSAndroid Build Coastguard Worker
96*61c4878aSAndroid Build Coastguard WorkerUpstream targets
97*61c4878aSAndroid Build Coastguard Worker================
98*61c4878aSAndroid Build Coastguard WorkerThe following is a list of targets used for upstream Pigweed development.
99*61c4878aSAndroid Build Coastguard Worker
100*61c4878aSAndroid Build Coastguard Worker.. toctree::
101*61c4878aSAndroid Build Coastguard Worker  :maxdepth: 1
102*61c4878aSAndroid Build Coastguard Worker  :glob:
103*61c4878aSAndroid Build Coastguard Worker
104*61c4878aSAndroid Build Coastguard Worker  targets/*/target_docs
105*61c4878aSAndroid Build Coastguard Worker
106*61c4878aSAndroid Build Coastguard WorkerWork-in-progress targets
107*61c4878aSAndroid Build Coastguard Worker------------------------
108*61c4878aSAndroid Build Coastguard WorkerYou can see a list of hardware targets that are under development but not
109*61c4878aSAndroid Build Coastguard Workeryet landed `here <https://issues.pigweed.dev/issues/300646347/dependencies>`_.
110