xref: /aosp_15_r20/external/pigweed/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pi_pico.gni")
16import("//build_overrides/pigweed.gni")
17
18import("$dir_pw_android_toolchain/android.gni")
19import("$dir_pw_arduino_build/arduino.gni")
20import("$dir_pw_build/coverage_report.gni")
21import("$dir_pw_build/host_tool.gni")
22import("$dir_pw_build/python.gni")
23import("$dir_pw_docgen/docs.gni")
24import("$dir_pw_perf_test/perf_test.gni")
25import("$dir_pw_rpc/config.gni")
26import("$dir_pw_rust/rust.gni")
27import("$dir_pw_third_party/ambiq/ambiq.gni")
28import("$dir_pw_third_party/fuzztest/fuzztest.gni")
29import("$dir_pw_third_party/mcuxpresso/mcuxpresso.gni")
30import("$dir_pw_toolchain/c_optimization.gni")
31import("$dir_pw_toolchain/generate_toolchain.gni")
32import("$dir_pw_toolchain/non_c_toolchain.gni")
33import("$dir_pw_trace/backend.gni")
34import("$dir_pw_unit_test/test.gni")
35
36# Main build file for upstream Pigweed.
37
38declare_args() {
39  # The default C++ optimization level for building upstream Pigweed targets.
40  #
41  # Must be one of "debug", "size_optimized", or "speed_optimized".
42  pw_DEFAULT_C_OPTIMIZATION_LEVEL = "debug"
43
44  # The C++ optimization levels for which to generate targets.
45  #
46  # Supported levels are "debug", "size_optimized", or "speed_optimized".
47  pw_C_OPTIMIZATION_LEVELS = [
48    "debug",
49    "size_optimized",
50  ]
51
52  # List of application image GN targets specific to the Pigweed target.
53  pw_TARGET_APPLICATIONS = []
54
55  # Gates known broken configurations from building. This is what allows the
56  # implicit `all` target to work even though there are known broken targets.
57  pw_BUILD_BROKEN_GROUPS = false
58}
59
60# This toolchain is used to force some dependencies to not be parsed by the
61# default toolchain. This is desirable because the default toolchain generates
62# build steps for all parsed targets, not just desired dependencies.
63if (current_toolchain == default_toolchain) {
64  pw_non_c_toolchain("non_default_toolchain") {
65  }
66}
67
68# List any optimization levels in pw_C_OPTIMIZATION_LEVELS that are not in
69# pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS. This is accomplished by adding
70# all supported levels to the selected levels, then removing all supported
71# levels. The remaining list contains only the unsupported levels.
72_unknown_optimization_levels =
73    pw_C_OPTIMIZATION_LEVELS + pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS -
74    pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS
75
76assert(_unknown_optimization_levels == [],
77       "pw_C_OPTIMIZATION_LEVELS includes unsupported optimization levels: " +
78           "$_unknown_optimization_levels")
79
80# Assert that the selected pw_DEFAULT_C_OPTIMIZATION_LEVEL is in the
81# pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS list. This is done by adding then
82# removing all instances of the selected levels from the supported levels list.
83# If the resulting list did not change, then no supported levels were removed,
84# indicating that pw_DEFAULT_C_OPTIMIZATION_LEVEL is not a supported value.
85assert(pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS +
86           [ pw_DEFAULT_C_OPTIMIZATION_LEVEL ] -
87           [ pw_DEFAULT_C_OPTIMIZATION_LEVEL ] !=
88           pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS,
89       "pw_DEFAULT_C_OPTIMIZATION_LEVEL (\"$pw_DEFAULT_C_OPTIMIZATION_LEVEL" +
90           "\") must be one of the supported values: " +
91           "$pw_toolchain_SUPPORTED_C_OPTIMIZATION_LEVELS")
92
93# Enumerate all of the different targets that upstream Pigweed will build by
94# default. Downstream projects should not depend on this target; this target is
95# exclusively to facilitate easy upstream development and testing.
96group("default") {
97  deps = [
98    ":docs",
99    ":host",
100    ":pi_pico",
101    ":python.install",
102    ":python.lint",
103    ":python.tests",
104    ":static_analysis",
105    ":stm32f429i",
106    ":warn_if_modules_out_of_date",
107  ]
108}
109
110# This group tries to collect together most build steps in Pigweed's build.
111# Some targets in this group are not included in the main build to keep the
112# default build time down, while others are excluded from the main build because
113# they require additional configuration or don't work on every OS.
114#
115# To increase coverage, use `pw package` to install these packages:
116#   boringssl
117#   freertos
118#   mbedtls
119#   micro-ecc
120#   nanopb
121#   pico_sdk
122#   protobuf
123#   stm32cube_f4
124#   teensy
125group("extended_default") {
126  deps = [
127    ":cpp20_compatibility",
128    ":default",
129    ":host_clang_debug_dynamic_allocation",
130    ":pw_system_demo",
131    ":stm32f429i",
132  ]
133
134  if (host_os != "win") {
135    deps += [
136      ":qemu_clang",
137      ":qemu_gcc",
138    ]
139  }
140
141  if (host_os == "linux") {
142    deps += [
143      ":integration_tests",
144      ":runtime_sanitizers",
145    ]
146  }
147
148  # Requires setting pw_arduino_build_CORE_PATH.
149  if (pw_arduino_build_CORE_PATH != "") {
150    deps += [ ":arduino" ]
151  }
152
153  # Requires setting pw_third_party_mcuxpresso_SDK.
154  if (pw_third_party_mcuxpresso_SDK != "") {
155    deps += [ ":mimxrt595" ]
156  }
157}
158
159# Verify that this BUILD.gn file is only used by Pigweed itself.
160assert(get_path_info("//", "abspath") == get_path_info(".", "abspath"),
161       "Pigweed's top-level BUILD.gn may only be used when building upstream " +
162           "Pigweed. To pull all Pigweed code into your build, import " +
163           "\$dir_pigweed/modules.gni and create a top-level pw_test_group " +
164           "that depends on the tests in pw_module_tests. See " +
165           "https://pigweed.dev/build_system.html for details.")
166
167_update_or_check_modules_lists = {
168  script = "$dir_pw_build/py/pw_build/generate_modules_lists.py"
169  args = [
170    rebase_path(".", root_build_dir),
171    rebase_path("PIGWEED_MODULES", root_build_dir),
172    rebase_path("$dir_pw_build/generated_pigweed_modules_lists.gni",
173                root_build_dir),
174  ]
175  inputs = [
176    "$dir_pw_build/generated_pigweed_modules_lists.gni",
177    "PIGWEED_MODULES",
178  ]
179}
180
181# There are races if the module check and module file update are run at the same
182# time. Force them to be serialized to prevent races. As long as the generated
183# module file is up to date, they'll pass.
184pool("module_check_pool") {
185  depth = 1
186}
187
188# Warns if PIGWEED_MODULES is not up-to-date and sorted.
189action("warn_if_modules_out_of_date") {
190  forward_variables_from(_update_or_check_modules_lists, "*")
191  outputs = [ "$target_gen_dir/$target_name.passed" ]
192  args += [
193            "--mode=WARN",
194            "--stamp",
195          ] + rebase_path(outputs, root_build_dir)
196  pool = ":module_check_pool"
197}
198
199# Fails if PIGWEED_MODULES is not up-to-date and sorted.
200action("check_modules") {
201  forward_variables_from(_update_or_check_modules_lists, "*")
202  outputs = [ "$target_gen_dir/$target_name.ALWAYS_RERUN" ]  # Never created
203  args += [ "--mode=CHECK" ]
204  pool = ":module_check_pool"
205}
206
207# Run this command after adding an item to PIGWEED_MODULES to update the
208# generated .gni with Pigweed modules lists.
209action("update_modules") {
210  forward_variables_from(_update_or_check_modules_lists, "*")
211  outputs = [ "$target_gen_dir/$target_name.ALWAYS_RERUN" ]  # Never created
212  args += [ "--mode=UPDATE" ]
213  pool = ":module_check_pool"
214}
215
216group("pw_system_demo") {
217  deps = [ "$dir_pw_system:system_examples(:non_default_toolchain)" ]
218}
219
220group("pi_pico") {
221  if (PICO_SRC_DIR != "") {
222    deps = [ ":pigweed_default(targets/rp2040:rp2040.size_optimized)" ]
223  }
224}
225
226_internal_toolchains = "$dir_pigweed/targets/host/pigweed_internal"
227
228# This template generates a group that builds pigweed_default with a particular
229# toolchain.
230template("_build_pigweed_default_at_all_optimization_levels") {
231  _toolchain_prefix = invoker.toolchain_prefix
232
233  group(target_name) {
234    deps = [
235      ":pigweed_default(${_toolchain_prefix}$pw_DEFAULT_C_OPTIMIZATION_LEVEL)",
236    ]
237  }
238
239  foreach(optimization, pw_C_OPTIMIZATION_LEVELS) {
240    group(target_name + "_$optimization") {
241      deps = [ ":pigweed_default($_toolchain_prefix$optimization)" ]
242    }
243  }
244}
245
246# Select a default toolchain based on host OS.
247if (host_os == "linux") {
248  _default_toolchain_prefix = "$_internal_toolchains:pw_strict_host_clang_"
249} else if (host_os == "mac") {
250  _default_toolchain_prefix = "$_internal_toolchains:pw_strict_host_clang_"
251} else if (host_os == "win") {
252  _default_toolchain_prefix = "$_internal_toolchains:pw_strict_host_gcc_"
253} else {
254  assert(false, "Please define a host config for your system: $host_os")
255}
256
257# Below are a list of GN targets you can build to force Pigweed to build for a
258# specific Pigweed target.
259_build_pigweed_default_at_all_optimization_levels("host") {
260  toolchain_prefix = _default_toolchain_prefix
261}
262
263_build_pigweed_default_at_all_optimization_levels("host_clang") {
264  toolchain_prefix = "$_internal_toolchains:pw_strict_host_clang_"
265}
266
267# GCC is only supported for Windows. Pigweed doesn't yet provide a Windows
268# clang toolchain, and Pigweed does not provide gcc toolchains for macOS and
269# Linux.
270if (host_os == "win") {
271  _build_pigweed_default_at_all_optimization_levels("host_gcc") {
272    toolchain_prefix = "$_internal_toolchains:pw_strict_host_gcc_"
273  }
274}
275
276if (pw_third_party_mcuxpresso_SDK != "") {
277  _build_pigweed_default_at_all_optimization_levels("mimxrt595") {
278    toolchain_prefix = "$dir_pigweed/targets/mimxrt595_evk:mimxrt595_evk_"
279  }
280
281  _build_pigweed_default_at_all_optimization_levels("mimxrt595_freertos") {
282    toolchain_prefix =
283        "$dir_pigweed/targets/mimxrt595_evk_freertos:mimxrt595_evk_freertos_"
284  }
285}
286
287if (dir_pw_third_party_ambiq_SDK != "") {
288  _build_pigweed_default_at_all_optimization_levels("apollo4") {
289    toolchain_prefix = "$dir_pigweed/targets/apollo4:apollo4_"
290  }
291}
292
293_build_pigweed_default_at_all_optimization_levels("stm32f429i") {
294  toolchain_prefix = "$dir_pigweed/targets/stm32f429i_disc1:stm32f429i_disc1_"
295}
296
297if (pw_arduino_build_CORE_PATH != "") {
298  _build_pigweed_default_at_all_optimization_levels("arduino") {
299    toolchain_prefix = "$dir_pigweed/targets/arduino:arduino_"
300  }
301}
302
303# TODO: b/244604080 - Inline string tests are too big to fit in the QEMU firmware
304# except under a size-optimized build. For now, only build size-optimized.
305if (pw_BUILD_BROKEN_GROUPS) {
306  _build_pigweed_default_at_all_optimization_levels("qemu_gcc") {
307    toolchain_prefix =
308        "$dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_gcc_"
309  }
310  _build_pigweed_default_at_all_optimization_levels("qemu_clang") {
311    toolchain_prefix =
312        "$dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_"
313  }
314} else {
315  group("qemu_gcc_size_optimized") {
316    deps = [ ":pigweed_default($dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_gcc_size_optimized)" ]
317  }
318  group("qemu_gcc") {
319    deps = [ ":qemu_gcc_size_optimized" ]
320  }
321  group("qemu_clang_size_optimized") {
322    deps = [ ":pigweed_default($dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_size_optimized)" ]
323
324    if (pw_rust_ENABLE_EXPERIMENTAL_BUILD) {
325      deps += [ "$dir_pw_rust/examples/basic_executable:basic_executable($dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_debug)" ]
326      deps += [ "$dir_pw_rust/examples/basic_executable:basic_executable($dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_size_optimized)" ]
327      deps += [ "$dir_pw_rust/examples/basic_executable:basic_executable($dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_speed_optimized)" ]
328    }
329  }
330  group("qemu_clang") {
331    deps = [ ":qemu_clang_size_optimized" ]
332  }
333}
334
335# Run clang-tidy on pigweed_default with pw_strict_host_clang_debug toolchain options.
336# Make sure to invoke gn clean out when any relevant .clang-tidy
337# file is updated.
338group("static_analysis") {
339  # Static analysis is only supported on Linux and macOS using clang-tidy.
340  if (host_os != "win") {
341    _toolchain = "$_internal_toolchains:pw_strict_host_clang_debug"
342    deps = [ ":pigweed_default($_toolchain.static_analysis)" ]
343  }
344}
345
346if (pw_android_toolchain_NDK_PATH != "") {
347  group("android") {
348    deps = []
349    foreach(_cpu, pw_android_toolchain_cpu_targets) {
350      _toolchain_prefix = "$dir_pigweed/targets/android:${_cpu}_android_"
351      deps += [
352        ":pigweed_default($_toolchain_prefix$pw_DEFAULT_C_OPTIMIZATION_LEVEL)",
353      ]
354    }
355  }
356
357  foreach(_cpu, pw_android_toolchain_cpu_targets) {
358    _build_pigweed_default_at_all_optimization_levels("${_cpu}_android") {
359      toolchain_prefix = "$dir_pigweed/targets/android:${_cpu}_android_"
360    }
361  }
362}
363
364group("docs") {
365  deps = [ "$dir_pigweed/docs($dir_pigweed/targets/docs)" ]
366}
367
368# Tests that are run as host actions, such as tests of the build system.
369#
370# These are distinguished from `integration_tests` in that they are short
371# unit tests of specific functionality that should be tested in the default
372# build.
373group("action_tests") {
374  _default_tc = _default_toolchain_prefix + pw_DEFAULT_C_OPTIMIZATION_LEVEL
375  deps = [ ":pw_action_tests.run($_default_tc)" ]
376}
377
378# Tests larger than unit tests, typically run in a specific configuration.
379group("integration_tests") {
380  _default_tc = _default_toolchain_prefix + pw_DEFAULT_C_OPTIMIZATION_LEVEL
381  deps = [ ":pw_integration_tests.run($_default_tc)" ]
382}
383
384group("pip_constraint_update") {
385  public_deps = []
386
387  if (current_toolchain == pw_build_PYTHON_TOOLCHAIN) {
388    public_deps += [ "$dir_pw_env_setup:pigweed_build_venv._compile_requirements($pw_build_PYTHON_TOOLCHAIN)" ]
389  } else {
390    public_deps = [ ":${target_name}($pw_build_PYTHON_TOOLCHAIN)" ]
391  }
392}
393
394group("pip_vendor_wheels") {
395  public_deps = []
396
397  if (current_toolchain == pw_build_PYTHON_TOOLCHAIN) {
398    public_deps += [ "$dir_pw_env_setup:pigweed_build_venv.vendor_wheels($pw_build_PYTHON_TOOLCHAIN)" ]
399  } else {
400    public_deps = [ ":${target_name}($pw_build_PYTHON_TOOLCHAIN)" ]
401  }
402}
403
404group("fuzzers") {
405  deps = []
406
407  if (host_os != "win" && dir_pw_third_party_fuzztest != "") {
408    # Coverage-guided fuzzing is only supported on Linux and MacOS using clang.
409    # Fuzztest-based fuzzers will run in unit test mode. libFuzzer-based fuzzers
410    # will only build.
411    _clang_fuzz_tc = _default_toolchain_prefix + "fuzz"
412    deps += [ ":pw_module_tests.run($_clang_fuzz_tc)" ]
413  }
414
415  # Also build (but do not run) bespoke fuzzers.
416  if (!pw_toolchain_OSS_FUZZ_ENABLED) {
417    _default_tc = _default_toolchain_prefix + pw_DEFAULT_C_OPTIMIZATION_LEVEL
418    deps += [ ":pw_custom_fuzzers($_default_tc)" ]
419  }
420}
421
422# Build-only target for OSS-Fuzz. No-op unless OSS-Fuzz is enabled.
423group("oss_fuzz") {
424  if (pw_toolchain_OSS_FUZZ_ENABLED) {
425    _clang_fuzz_tc = _default_toolchain_prefix + "fuzz"
426    deps = [ ":pw_module_tests($_clang_fuzz_tc)" ]
427  }
428}
429
430group("asan") {
431  # TODO: b/302181521 - asan doesn't work on Windows yet.
432  if (host_os != "win") {
433    deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_asan)" ]
434  }
435}
436
437# TODO: b/234876100 - msan will not work without false positives until the C++
438# standard library included in the sysroot has a variant built with msan.
439group("msan") {
440  # TODO: b/259695498 - msan doesn't work on macOS yet.
441  # TODO: b/302181521 - msan doesn't work on Windows yet.
442  if (pw_BUILD_BROKEN_GROUPS) {
443    deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_msan)" ]
444  }
445}
446
447group("tsan") {
448  # TODO: b/302181521 - tsan doesn't work on Windows yet.
449  if (host_os != "win") {
450    deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_tsan)" ]
451  }
452}
453
454group("ubsan") {
455  # TODO: b/259695498 - ubsan doesn't work on macOS yet.
456  # TODO: b/302181521 - ubsan doesn't work on Windows yet.
457  if ((host_os != "win" && host_os != "mac") || pw_BUILD_BROKEN_GROUPS) {
458    deps =
459        [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_ubsan)" ]
460  }
461}
462
463group("ubsan_heuristic") {
464  # TODO: b/259695498 - ubsan_heuristic doesn't work on macOS yet.
465  # TODO: b/302181521 - ubsan doesn't work on Windows yet.
466  if ((host_os != "win" && host_os != "mac") || pw_BUILD_BROKEN_GROUPS) {
467    deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_ubsan_heuristic)" ]
468  }
469}
470
471group("runtime_sanitizers") {
472  if (host_os != "win" || pw_BUILD_BROKEN_GROUPS) {
473    deps = [
474      ":asan",
475      ":tsan",
476      ":ubsan",
477    ]
478
479    if (pw_BUILD_BROKEN_GROUPS) {
480      # TODO: b/234876100 - msan will not work until the C++ standard library
481      # included in the sysroot has a variant built with msan.
482      deps += [ ":msan" ]
483
484      # No ubsan_heuristic, which may have false positives.
485      deps += [ ":ubsan_heuristic" ]
486    }
487  }
488}
489
490group("coverage") {
491  if (host_os == "linux") {
492    deps = [ ":coverage_report($dir_pigweed/targets/host:host_clang_coverage)" ]
493  }
494}
495
496pw_python_group("python") {
497  python_deps = [
498    "$dir_pw_env_setup:python($pw_build_PYTHON_TOOLCHAIN)",
499    "$dir_pw_env_setup:sample_project_action($pw_build_PYTHON_TOOLCHAIN)",
500    "$dir_pw_env_setup:target_support_packages($pw_build_PYTHON_TOOLCHAIN)",
501  ]
502}
503
504group("pigweed_pypi_distribution") {
505  deps = [
506    "$dir_pw_env_setup:generate_hdlc_proto_rpc_tokenizer_distribution.wheel($pw_build_PYTHON_TOOLCHAIN)",
507    "$dir_pw_env_setup:pypi_pigweed_python_source_tree.wheel($pw_build_PYTHON_TOOLCHAIN)",
508  ]
509}
510
511# Build host-only tooling.
512group("host_tools") {
513  deps = []
514
515  if (pw_rust_ENABLE_EXPERIMENTAL_BUILD) {
516    deps += [ "$dir_pw_rust/examples/basic_executable:basic_executable($dir_pigweed/targets/host:host_clang_debug)" ]
517    deps += [ "$dir_pw_rust/examples/basic_executable:basic_executable($dir_pigweed/targets/host:host_clang_speed_optimized)" ]
518    deps += [ "$dir_pw_rust/examples/basic_executable:basic_executable($dir_pigweed/targets/host:host_clang_size_optimized)" ]
519    deps += [ "$dir_pw_rust/examples/bindgen:test_add($dir_pigweed/targets/host:host_clang_debug)" ]
520  }
521}
522
523# By default, Pigweed will build this target when invoking ninja.
524group("pigweed_default") {
525  deps = []
526
527  # Prevent the default toolchain from parsing any other BUILD.gn files.
528  if (current_toolchain != default_toolchain) {
529    _is_host_toolchain = defined(pw_toolchain_SCOPE.is_host_toolchain) &&
530                         pw_toolchain_SCOPE.is_host_toolchain
531
532    deps = [ ":apps" ]
533
534    # Upstream GoogleTest assumes the presence of a POSIX filesystem. If an
535    # external gtest backend has been provided, limit the tests to host-only.
536    if (pw_unit_test_BACKEND == "$dir_pw_unit_test:light" ||
537        _is_host_toolchain) {
538      if (pw_unit_test_AUTOMATIC_RUNNER == "") {
539        # Without a test runner defined, build the tests but don't run them.
540        deps += [ ":pw_module_tests" ]
541      } else {
542        # With a test runner, depend on the run targets so they run with the
543        # build.
544        deps += [ ":pw_module_tests.run" ]
545      }
546
547      # Add performance tests to the automatic build
548      deps += [ ":pw_perf_tests" ]
549    }
550
551    # Add action tests to the automatic build
552    if (_is_host_toolchain) {
553      deps += [ ":pw_action_tests.run" ]
554    }
555
556    # Trace examples currently only support running on non-windows host
557    if (_is_host_toolchain && host_os != "win") {
558      deps += [ "$dir_pw_trace:trace_example_basic" ]
559
560      if (get_label_info(pw_trace_BACKEND, "label_no_toolchain") ==
561          get_label_info(":pw_trace_tokenized", "label_no_toolchain")) {
562        deps += [
563          "$dir_pw_trace_tokenized:trace_tokenized_example_basic",
564          "$dir_pw_trace_tokenized:trace_tokenized_example_filter",
565          "$dir_pw_trace_tokenized:trace_tokenized_example_linux_group_by_tid",
566          "$dir_pw_trace_tokenized:trace_tokenized_example_rpc",
567          "$dir_pw_trace_tokenized:trace_tokenized_example_trigger",
568        ]
569      }
570    }
571  }
572}
573
574# Build Pigweed with -std=c++20 to ensure compatibility. Compile with
575# optimizations since the compiler tends to catch more errors with optimizations
576# enabled than without.
577group("cpp20_compatibility") {
578  _cpp20_tc = "$_internal_toolchains:pw_strict_host_clang_size_optimized_cpp20"
579  deps = [ ":pigweed_default($_cpp20_tc)" ]
580}
581
582group("build_with_pw_minimal_cpp_stdlib") {
583  _toolchain = "$_internal_toolchains:pw_strict_host_clang_size_optimized_minimal_cpp_stdlib"
584
585  # This list of supported modules is incomplete.
586  deps = [
587    "$dir_pw_base64($_toolchain)",
588    "$dir_pw_containers:inline_var_len_entry_queue($_toolchain)",
589    "$dir_pw_status($_toolchain)",
590    "$dir_pw_tokenizer:base64($_toolchain)",
591    "$dir_pw_tokenizer($_toolchain)",
592    "$dir_pw_varint($_toolchain)",
593  ]
594}
595
596group("host_clang_debug_dynamic_allocation") {
597  _toolchain =
598      "$_internal_toolchains:pw_strict_host_clang_debug_dynamic_allocation"
599  deps = [ ":pigweed_default($_toolchain)" ]
600}
601
602# The default toolchain is not used for compiling C/C++ code.
603if (current_toolchain != default_toolchain) {
604  group("apps") {
605    # Application images built for all targets.
606    deps = [ "$dir_pw_hdlc/rpc_example" ]
607
608    # Add target-specific images.
609    deps += pw_TARGET_APPLICATIONS
610
611    # Add host-only targets to the build.
612    if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
613        pw_toolchain_SCOPE.is_host_toolchain) {
614      # TODO: b/240982565 - Build integration tests on Windows and macOS when
615      #     SocketStream supports those platforms.
616      if (host_os == "linux") {
617        # Build the integration test binaries, but don't run them by default.
618        deps += [
619          "$dir_pw_rpc:client_integration_test",
620          "$dir_pw_rpc:test_rpc_server",
621          "$dir_pw_unit_test:test_rpc_server",
622        ]
623
624        # Build the benchmarks, but don't run them by default.
625        deps += [ ":pw_benchmarks" ]
626      }
627    }
628
629    if (current_os == "linux") {
630      deps += [
631        "$dir_pw_digital_io_linux:pw_digital_io_linux_cli",
632        "$dir_pw_spi_linux:pw_spi_linux_cli",
633      ]
634    }
635  }
636
637  # All Pigweed modules that can be built using gn. Not built by default.
638  group("pw_modules") {
639    deps = pw_modules
640  }
641
642  # Targets for all module unit test groups.
643  pw_test_group("pw_module_tests") {
644    group_deps = pw_module_tests
645    output_metadata = true
646  }
647
648  pw_test_group("pw_action_tests") {
649    tests = [ "$dir_pw_unit_test:test_group_metadata_test" ]
650  }
651
652  pw_test_group("pw_integration_tests") {
653    tests = [
654      "$dir_pw_build/py/gn_tests:python_package_integration_tests",
655      "$dir_pw_cli/py:process_integration_test",
656      "$dir_pw_rpc:cpp_client_server_integration_test",
657      "$dir_pw_rpc/py:python_client_cpp_server_test",
658      "$dir_pw_unit_test/py:rpc_service_test",
659    ]
660
661    output_metadata = true
662  }
663
664  pw_test_group("pw_perf_tests") {
665    tests = [
666      "$dir_pw_checksum:perf_tests",
667      "$dir_pw_perf_test:examples",
668      "$dir_pw_protobuf:perf_tests",
669    ]
670    output_metadata = true
671  }
672
673  # TODO(b/369853273): Merge benchmarks and perf tests
674  group("pw_benchmarks") {
675    deps = [ "$dir_pw_allocator/benchmarks" ]
676  }
677
678  # Fuzzers not based on a fuzzing engine. Engine-based fuzzers should be
679  # included in `pw_module_tests`.
680  pw_test_group("pw_custom_fuzzers") {
681    # TODO: b/274437709 - The RPC client_fuzzer encounters build errors on macos.
682    # Limit it to Linux hosts for now.
683    if (host_os == "linux") {
684      tests = [ "$dir_pw_rpc/fuzz:client_fuzzer" ]
685    }
686    output_metadata = true
687  }
688
689  pw_coverage_report("coverage_report") {
690    filter_paths = []
691    ignore_filename_patterns = [
692      "third_party",
693      "protocol_buffer/gen",
694    ]
695    group_deps = [ ":pw_module_tests" ]
696  }
697}
698