aboutsummaryrefslogtreecommitdiff
path: root/BUILD.gn
blob: 6a9a231453d330b8e9639764e646e919ddcacdad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

import("//build_overrides/pi_pico.gni")
import("//build_overrides/pigweed.gni")

import("$dir_pw_android_toolchain/android.gni")
import("$dir_pw_arduino_build/arduino.gni")
import("$dir_pw_build/coverage_report.gni")
import("$dir_pw_build/host_tool.gni")
import("$dir_pw_build/python.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_perf_test/perf_test.gni")
import("$dir_pw_rpc/config.gni")
import("$dir_pw_rust/rust.gni")
import("$dir_pw_third_party/ambiq/ambiq.gni")
import("$dir_pw_third_party/fuzztest/fuzztest.gni")
import("$dir_pw_third_party/mcuxpresso/mcuxpresso.gni")
import("$dir_pw_toolchain/c_optimization.gni")
import("$dir_pw_toolchain/generate_toolchain.gni")
import("$dir_pw_toolchain/non_c_toolchain.gni")
import("$dir_pw_trace/backend.gni")
import("$dir_pw_unit_test/test.gni")

# Main build file for upstream Pigweed.

declare_args() {
  # The default C++ optimization level for building upstream Pigweed targets.
  #
  # Must be one of "debug", "size_optimized", or "speed_optimized".
  pw_DEFAULT_C_OPTIMIZATION_LEVEL = "debug"

  # The C++ optimization levels for which to generate targets.
  #
  # Supported levels are "debug", "size_optimized", or "speed_optimized".
  pw_C_OPTIMIZATION_LEVELS = [
    "debug",
    "size_optimized",
  ]

  # List of application image GN targets specific to the Pigweed target.
  pw_TARGET_APPLICATIONS = []

  # Gates known broken configurations from building. This is what allows the
  # implicit `all` target to work even though there are known broken targets.
  pw_BUILD_BROKEN_GROUPS = false
}

# This toolchain is used to force some dependencies to not be parsed by the
# default toolchain. This is desirable because the default toolchain generates
# build steps for all parsed targets, not just desired dependencies.
if (current_toolchain == default_toolchain) {
  pw_non_c_toolchain("non_default_toolchain") {
  }
}

# List any optimization levels in pw_C_OPTIMIZATION_LEVELS that are not in
# pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS. This is accomplished by adding
# all supported levels to the selected levels, then removing all supported
# levels. The remaining list contains only the unsupported levels.
_unknown_optimization_levels =
    pw_C_OPTIMIZATION_LEVELS + pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS -
    pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS

assert(_unknown_optimization_levels == [],
       "pw_C_OPTIMIZATION_LEVELS includes unsupported optimization levels: " +
           "$_unknown_optimization_levels")

# Assert that the selected pw_DEFAULT_C_OPTIMIZATION_LEVEL is in the
# pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS list. This is done by adding then
# removing all instances of the selected levels from the supported levels list.
# If the resulting list did not change, then no supported levels were removed,
# indicating that pw_DEFAULT_C_OPTIMIZATION_LEVEL is not a supported value.
assert(pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS +
           [ pw_DEFAULT_C_OPTIMIZATION_LEVEL ] -
           [ pw_DEFAULT_C_OPTIMIZATION_LEVEL ] !=
           pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS,
       "pw_DEFAULT_C_OPTIMIZATION_LEVEL (\"$pw_DEFAULT_C_OPTIMIZATION_LEVEL" +
           "\") must be one of the supported values: " +
           "$pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS")

# Enumerate all of the different targets that upstream Pigweed will build by
# default. Downstream projects should not depend on this target; this target is
# exclusively to facilitate easy upstream development and testing.
group("default") {
  deps = [
    ":docs",
    ":host",
    ":pi_pico",
    ":python.lint",
    ":python.tests",
    ":static_analysis",
    ":stm32f429i",
    ":warn_if_modules_out_of_date",
  ]
}

# This group tries to collect together most build steps in Pigweed's build.
# Some targets in this group are not included in the main build to keep the
# default build time down, while others are excluded from the main build because
# they require additional configuration or don't work on every OS.
#
# To increase coverage, use `pw package` to install these packages:
#   boringssl
#   freertos
#   mbedtls
#   micro-ecc
#   nanopb
#   pico_sdk
#   protobuf
#   stm32cube_f4
#   teensy
group("extended_default") {
  deps = [
    ":cpp20_compatibility",
    ":default",
    ":host_clang_debug_dynamic_allocation",
    ":pw_system_demo",
    ":stm32f429i",
  ]

  if (host_os != "win") {
    deps += [
      ":qemu_clang",
      ":qemu_gcc",
    ]
  }

  if (host_os == "linux") {
    deps += [
      ":integration_tests",
      ":runtime_sanitizers",
    ]
  }

  # Requires setting pw_arduino_build_CORE_PATH.
  if (pw_arduino_build_CORE_PATH != "") {
    deps += [ ":arduino" ]
  }

  # Requires setting pw_third_party_mcuxpresso_SDK.
  if (pw_third_party_mcuxpresso_SDK != "") {
    deps += [ ":mimxrt595" ]
  }
}

# Verify that this BUILD.gn file is only used by Pigweed itself.
assert(get_path_info("//", "abspath") == get_path_info(".", "abspath"),
       "Pigweed's top-level BUILD.gn may only be used when building upstream " +
           "Pigweed. To pull all Pigweed code into your build, import " +
           "\$dir_pigweed/modules.gni and create a top-level pw_test_group " +
           "that depends on the tests in pw_module_tests. See " +
           "https://pigweed.dev/build_system.html for details.")

_update_or_check_modules_lists = {
  script = "$dir_pw_build/py/pw_build/generate_modules_lists.py"
  args = [
    rebase_path(".", root_build_dir),
    rebase_path("PIGWEED_MODULES", root_build_dir),
    rebase_path("$dir_pw_build/generated_pigweed_modules_lists.gni",
                root_build_dir),
  ]
  inputs = [
    "$dir_pw_build/generated_pigweed_modules_lists.gni",
    "PIGWEED_MODULES",
  ]
}

# There are races if the module check and module file update are run at the same
# time. Force them to be serialized to prevent races. As long as the generated
# module file is up to date, they'll pass.
pool("module_check_pool") {
  depth = 1
}

# Warns if PIGWEED_MODULES is not up-to-date and sorted.
action("warn_if_modules_out_of_date") {
  forward_variables_from(_update_or_check_modules_lists, "*")
  outputs = [ "$target_gen_dir/$target_name.passed" ]
  args += [
            "--mode=WARN",
            "--stamp",
          ] + rebase_path(outputs, root_build_dir)
  pool = ":module_check_pool"
}

# Fails if PIGWEED_MODULES is not up-to-date and sorted.
action("check_modules") {
  forward_variables_from(_update_or_check_modules_lists, "*")
  outputs = [ "$target_gen_dir/$target_name.ALWAYS_RERUN" ]  # Never created
  args += [ "--mode=CHECK" ]
  pool = ":module_check_pool"
}

# Run this command after adding an item to PIGWEED_MODULES to update the
# generated .gni with Pigweed modules lists.
action("update_modules") {
  forward_variables_from(_update_or_check_modules_lists, "*")
  outputs = [ "$target_gen_dir/$target_name.ALWAYS_RERUN" ]  # Never created
  args += [ "--mode=UPDATE" ]
  pool = ":module_check_pool"
}

group("pw_system_demo") {
  deps = [ "$dir_pw_system:system_examples(:non_default_toolchain)" ]
}

group("pi_pico") {
  if (PICO_SRC_DIR != "") {
    deps = [ ":pigweed_default(targets/rp2040)" ]
  }
}

_internal_toolchains = "$dir_pigweed/targets/host/pigweed_internal"

# This template generates a group that builds pigweed_default with a particular
# toolchain.
template("_build_pigweed_default_at_all_optimization_levels") {
  _toolchain_prefix = invoker.toolchain_prefix

  group(target_name) {
    deps = [
      ":pigweed_default(${_toolchain_prefix}$pw_DEFAULT_C_OPTIMIZATION_LEVEL)",
    ]
  }

  foreach(optimization, pw_C_OPTIMIZATION_LEVELS) {
    group(target_name + "_$optimization") {
      deps = [ ":pigweed_default($_toolchain_prefix$optimization)" ]
    }
  }
}

# Select a default toolchain based on host OS.
if (host_os == "linux") {
  _default_toolchain_prefix = "$_internal_toolchains:pw_strict_host_clang_"
} else if (host_os == "mac") {
  _default_toolchain_prefix = "$_internal_toolchains:pw_strict_host_clang_"
} else if (host_os == "win") {
  _default_toolchain_prefix = "$_internal_toolchains:pw_strict_host_gcc_"
} else {
  assert(false, "Please define a host config for your system: $host_os")
}

# Below are a list of GN targets you can build to force Pigweed to build for a
# specific Pigweed target.
_build_pigweed_default_at_all_optimization_levels("host") {
  toolchain_prefix = _default_toolchain_prefix
}

_build_pigweed_default_at_all_optimization_levels("host_clang") {
  toolchain_prefix = "$_internal_toolchains:pw_strict_host_clang_"
}

# GCC is only supported for Windows. Pigweed doesn't yet provide a Windows
# clang toolchain, and Pigweed does not provide gcc toolchains for macOS and
# Linux.
if (host_os == "win") {
  _build_pigweed_default_at_all_optimization_levels("host_gcc") {
    toolchain_prefix = "$_internal_toolchains:pw_strict_host_gcc_"
  }
}

if (pw_third_party_mcuxpresso_SDK != "") {
  _build_pigweed_default_at_all_optimization_levels("mimxrt595") {
    toolchain_prefix = "$dir_pigweed/targets/mimxrt595_evk:mimxrt595_evk_"
  }

  _build_pigweed_default_at_all_optimization_levels("mimxrt595_freertos") {
    toolchain_prefix =
        "$dir_pigweed/targets/mimxrt595_evk_freertos:mimxrt595_evk_freertos_"
  }
}

if (dir_pw_third_party_ambiq_SDK != "") {
  _build_pigweed_default_at_all_optimization_levels("apollo4") {
    toolchain_prefix = "$dir_pigweed/targets/apollo4:apollo4_"
  }
}

_build_pigweed_default_at_all_optimization_levels("stm32f429i") {
  toolchain_prefix = "$dir_pigweed/targets/stm32f429i_disc1:stm32f429i_disc1_"
}

if (pw_arduino_build_CORE_PATH != "") {
  _build_pigweed_default_at_all_optimization_levels("arduino") {
    toolchain_prefix = "$dir_pigweed/targets/arduino:arduino_"
  }
}

# TODO: b/244604080 - Inline string tests are too big to fit in the QEMU firmware
# except under a size-optimized build. For now, only build size-optimized.
if (pw_BUILD_BROKEN_GROUPS) {
  _build_pigweed_default_at_all_optimization_levels("qemu_gcc") {
    toolchain_prefix =
        "$dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_gcc_"
  }
  _build_pigweed_default_at_all_optimization_levels("qemu_clang") {
    toolchain_prefix =
        "$dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_"
  }
} else {
  group("qemu_gcc_size_optimized") {
    deps = [ ":pigweed_default($dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_gcc_size_optimized)" ]
  }
  group("qemu_gcc") {
    deps = [ ":qemu_gcc_size_optimized" ]
  }
  group("qemu_clang_size_optimized") {
    deps = [ ":pigweed_default($dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_size_optimized)" ]
  }
  group("qemu_clang") {
    deps = [ ":qemu_clang_size_optimized" ]
  }
}

# Run clang-tidy on pigweed_default with pw_strict_host_clang_debug toolchain options.
# Make sure to invoke gn clean out when any relevant .clang-tidy
# file is updated.
group("static_analysis") {
  # Static analysis is only supported on Linux and macOS using clang-tidy.
  if (host_os != "win") {
    _toolchain = "$_internal_toolchains:pw_strict_host_clang_debug"
    deps = [ ":pigweed_default($_toolchain.static_analysis)" ]
  }
}

if (pw_android_toolchain_NDK_PATH != "") {
  group("android") {
    deps = []
    foreach(_cpu, pw_android_toolchain_cpu_targets) {
      _toolchain_prefix = "$dir_pigweed/targets/android:${_cpu}_android_"
      deps += [
        ":pigweed_default($_toolchain_prefix$pw_DEFAULT_C_OPTIMIZATION_LEVEL)",
      ]
    }
  }

  foreach(_cpu, pw_android_toolchain_cpu_targets) {
    _build_pigweed_default_at_all_optimization_levels("${_cpu}_android") {
      toolchain_prefix = "$dir_pigweed/targets/android:${_cpu}_android_"
    }
  }
}

group("docs") {
  deps = [ "$dir_pigweed/docs($dir_pigweed/targets/docs)" ]
}

# Tests that are run as host actions, such as tests of the build system.
#
# These are distinguished from `integration_tests` in that they are short
# unit tests of specific functionality that should be tested in the default
# build.
group("action_tests") {
  _default_tc = _default_toolchain_prefix + pw_DEFAULT_C_OPTIMIZATION_LEVEL
  deps = [ ":pw_action_tests.run($_default_tc)" ]
}

# Tests larger than unit tests, typically run in a specific configuration.
group("integration_tests") {
  _default_tc = _default_toolchain_prefix + pw_DEFAULT_C_OPTIMIZATION_LEVEL
  deps = [ ":pw_integration_tests.run($_default_tc)" ]
}

group("pip_constraint_update") {
  public_deps = []

  if (current_toolchain == pw_build_PYTHON_TOOLCHAIN) {
    public_deps += [ "$dir_pw_env_setup:pigweed_build_venv._compile_requirements($pw_build_PYTHON_TOOLCHAIN)" ]
  } else {
    public_deps = [ ":${target_name}($pw_build_PYTHON_TOOLCHAIN)" ]
  }
}

group("pip_vendor_wheels") {
  public_deps = []

  if (current_toolchain == pw_build_PYTHON_TOOLCHAIN) {
    public_deps += [ "$dir_pw_env_setup:pigweed_build_venv.vendor_wheels($pw_build_PYTHON_TOOLCHAIN)" ]
  } else {
    public_deps = [ ":${target_name}($pw_build_PYTHON_TOOLCHAIN)" ]
  }
}

group("fuzzers") {
  deps = []

  if (host_os != "win" && dir_pw_third_party_fuzztest != "") {
    # Coverage-guided fuzzing is only supported on Linux and MacOS using clang.
    # Fuzztest-based fuzzers will run in unit test mode. libFuzzer-based fuzzers
    # will only build.
    _clang_fuzz_tc = _default_toolchain_prefix + "fuzz"
    deps += [ ":pw_module_tests.run($_clang_fuzz_tc)" ]
  }

  # Also build (but do not run) bespoke fuzzers.
  if (!pw_toolchain_OSS_FUZZ_ENABLED) {
    _default_tc = _default_toolchain_prefix + pw_DEFAULT_C_OPTIMIZATION_LEVEL
    deps += [ ":pw_custom_fuzzers($_default_tc)" ]
  }
}

# Build-only target for OSS-Fuzz. No-op unless OSS-Fuzz is enabled.
group("oss_fuzz") {
  if (pw_toolchain_OSS_FUZZ_ENABLED) {
    _clang_fuzz_tc = _default_toolchain_prefix + "fuzz"
    deps = [ ":pw_module_tests($_clang_fuzz_tc)" ]
  }
}

group("asan") {
  # TODO: b/302181521 - asan doesn't work on Windows yet.
  if (host_os != "win") {
    deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_asan)" ]
  }
}

# TODO: b/234876100 - msan will not work without false positives until the C++
# standard library included in the sysroot has a variant built with msan.
group("msan") {
  # TODO: b/259695498 - msan doesn't work on macOS yet.
  # TODO: b/302181521 - msan doesn't work on Windows yet.
  if (pw_BUILD_BROKEN_GROUPS) {
    deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_msan)" ]
  }
}

group("tsan") {
  # TODO: b/302181521 - tsan doesn't work on Windows yet.
  if (host_os != "win") {
    deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_tsan)" ]
  }
}

group("ubsan") {
  # TODO: b/259695498 - ubsan doesn't work on macOS yet.
  # TODO: b/302181521 - ubsan doesn't work on Windows yet.
  if ((host_os != "win" && host_os != "mac") || pw_BUILD_BROKEN_GROUPS) {
    deps =
        [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_ubsan)" ]
  }
}

group("ubsan_heuristic") {
  # TODO: b/259695498 - ubsan_heuristic doesn't work on macOS yet.
  # TODO: b/302181521 - ubsan doesn't work on Windows yet.
  if ((host_os != "win" && host_os != "mac") || pw_BUILD_BROKEN_GROUPS) {
    deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_ubsan_heuristic)" ]
  }
}

group("runtime_sanitizers") {
  if (host_os != "win" || pw_BUILD_BROKEN_GROUPS) {
    deps = [
      ":asan",
      ":tsan",
      ":ubsan",
    ]

    if (pw_BUILD_BROKEN_GROUPS) {
      # TODO: b/234876100 - msan will not work until the C++ standard library
      # included in the sysroot has a variant built with msan.
      deps += [ ":msan" ]

      # No ubsan_heuristic, which may have false positives.
      deps += [ ":ubsan_heuristic" ]
    }
  }
}

group("coverage") {
  if (host_os == "linux") {
    deps = [ ":coverage_report($dir_pigweed/targets/host:host_clang_coverage)" ]
  }
}

pw_python_group("python") {
  python_deps = [
    "$dir_pw_env_setup:python($pw_build_PYTHON_TOOLCHAIN)",
    "$dir_pw_env_setup:sample_project_action($pw_build_PYTHON_TOOLCHAIN)",
    "$dir_pw_env_setup:target_support_packages($pw_build_PYTHON_TOOLCHAIN)",
  ]
}

group("pigweed_pypi_distribution") {
  deps = [ "$dir_pw_env_setup:pypi_pigweed_python_source_tree($pw_build_PYTHON_TOOLCHAIN)" ]
}

# Build host-only tooling.
group("host_tools") {
  deps = [
    "$dir_pw_target_runner/go:simple_client(:non_default_toolchain)",
    "$dir_pw_target_runner/go:simple_server(:non_default_toolchain)",
  ]

  if (pw_rust_ENABLE_EXPERIMENTAL_BUILD) {
    deps += [ "$dir_pw_rust/examples/host_executable:host_executable($dir_pigweed/targets/host:host_clang_debug)" ]
  }
}

# By default, Pigweed will build this target when invoking ninja.
group("pigweed_default") {
  deps = []

  # Prevent the default toolchain from parsing any other BUILD.gn files.
  if (current_toolchain != default_toolchain) {
    _is_host_toolchain = defined(pw_toolchain_SCOPE.is_host_toolchain) &&
                         pw_toolchain_SCOPE.is_host_toolchain

    deps = [ ":apps" ]

    # Upstream GoogleTest assumes the presence of a POSIX filesystem. If an
    # external gtest backend has been provided, limit the tests to host-only.
    if (pw_unit_test_GOOGLETEST_BACKEND == "$dir_pw_unit_test:light" ||
        _is_host_toolchain) {
      if (pw_unit_test_AUTOMATIC_RUNNER == "") {
        # Without a test runner defined, build the tests but don't run them.
        deps += [ ":pw_module_tests" ]
      } else {
        # With a test runner, depend on the run targets so they run with the
        # build.
        deps += [ ":pw_module_tests.run" ]
      }

      # Add performance tests to the automatic build
      deps += [ ":pw_perf_tests" ]
    }

    # Add action tests to the automatic build
    if (_is_host_toolchain) {
      deps += [ ":pw_action_tests.run" ]
    }

    # Trace examples currently only support running on non-windows host
    if (_is_host_toolchain && host_os != "win") {
      deps += [ "$dir_pw_trace:trace_example_basic" ]

      if (get_label_info(pw_trace_BACKEND, "label_no_toolchain") ==
          get_label_info(":pw_trace_tokenized", "label_no_toolchain")) {
        deps += [
          "$dir_pw_trace_tokenized:trace_tokenized_example_basic",
          "$dir_pw_trace_tokenized:trace_tokenized_example_filter",
          "$dir_pw_trace_tokenized:trace_tokenized_example_linux_group_by_tid",
          "$dir_pw_trace_tokenized:trace_tokenized_example_rpc",
          "$dir_pw_trace_tokenized:trace_tokenized_example_trigger",
        ]
      }
    }
  }
}

# Build Pigweed with -std=c++20 to ensure compatibility. Compile with
# optimizations since the compiler tends to catch more errors with optimizations
# enabled than without.
group("cpp20_compatibility") {
  _cpp20_tc = "$_internal_toolchains:pw_strict_host_clang_size_optimized_cpp20"
  deps = [ ":pigweed_default($_cpp20_tc)" ]
}

group("build_with_pw_minimal_cpp_stdlib") {
  _toolchain = "$_internal_toolchains:pw_strict_host_clang_size_optimized_minimal_cpp_stdlib"

  # This list of supported modules is incomplete.
  deps = [
    "$dir_pw_base64($_toolchain)",
    "$dir_pw_containers:variable_length_entry_queue($_toolchain)",
    "$dir_pw_status($_toolchain)",
    "$dir_pw_tokenizer:base64($_toolchain)",
    "$dir_pw_tokenizer($_toolchain)",
    "$dir_pw_varint($_toolchain)",
  ]
}

group("host_clang_debug_dynamic_allocation") {
  _toolchain =
      "$_internal_toolchains:pw_strict_host_clang_debug_dynamic_allocation"
  deps = [ ":pigweed_default($_toolchain)" ]
}

# The default toolchain is not used for compiling C/C++ code.
if (current_toolchain != default_toolchain) {
  group("apps") {
    # Application images built for all targets.
    deps = [ "$dir_pw_hdlc/rpc_example" ]

    # Add target-specific images.
    deps += pw_TARGET_APPLICATIONS

    # Add host-only targets to the build.
    if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
        pw_toolchain_SCOPE.is_host_toolchain) {
      deps += [ "$dir_pw_tool" ]

      # TODO: b/240982565 - Build integration tests on Windows and macOS when
      #     SocketStream supports those platforms.
      if (host_os == "linux") {
        # Build the integration test binaries, but don't run them by default.
        deps += [
          "$dir_pw_rpc:client_integration_test",
          "$dir_pw_rpc:test_rpc_server",
          "$dir_pw_unit_test:test_rpc_server",
        ]
      }
    }
  }

  # All Pigweed modules that can be built using gn. Not built by default.
  group("pw_modules") {
    deps = pw_modules
  }

  # Targets for all module unit test groups.
  pw_test_group("pw_module_tests") {
    group_deps = pw_module_tests
    output_metadata = true
  }

  pw_test_group("pw_action_tests") {
    tests = [ "$dir_pw_unit_test:test_group_metadata_test" ]
  }

  pw_test_group("pw_integration_tests") {
    tests = [
      "$dir_pw_build/py/gn_tests:python_package_integration_tests",
      "$dir_pw_cli/py:process_integration_test",
      "$dir_pw_rpc:cpp_client_server_integration_test",
      "$dir_pw_rpc/py:python_client_cpp_server_test",
      "$dir_pw_unit_test/py:rpc_service_test",
    ]

    output_metadata = true
  }

  pw_test_group("pw_perf_tests") {
    tests = [
      "$dir_pw_checksum:perf_tests",
      "$dir_pw_perf_test:examples",
      "$dir_pw_protobuf:perf_tests",
    ]
    output_metadata = true
  }

  # Fuzzers not based on a fuzzing engine. Engine-based fuzzers should be
  # included in `pw_module_tests`.
  pw_test_group("pw_custom_fuzzers") {
    # TODO: b/274437709 - The RPC client_fuzzer encounters build errors on macos.
    # Limit it to Linux hosts for now.
    if (host_os == "linux") {
      tests = [ "$dir_pw_rpc/fuzz:client_fuzzer" ]
    }
    output_metadata = true
  }

  pw_coverage_report("coverage_report") {
    filter_paths = []
    ignore_filename_patterns = [
      "third_party",
      "protocol_buffer/gen",
    ]
    group_deps = [ ":pw_module_tests" ]
  }
}