| # 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_arduino_build/arduino.gni") |
| import("$dir_pw_build/host_tool.gni") |
| import("$dir_pw_build/python.gni") |
| import("$dir_pw_docgen/docs.gni") |
| import("$dir_pw_rpc/config.gni") |
| import("$dir_pw_third_party/mcuxpresso/mcuxpresso.gni") |
| import("$dir_pw_toolchain/generate_toolchain.gni") |
| import("$dir_pw_unit_test/test.gni") |
| |
| # Main build file for upstream Pigweed. |
| |
| declare_args() { |
| # The default optimization level for building upstream Pigweed targets. |
| # |
| # Choices: |
| # debug |
| # size_optimized |
| # speed_optimized |
| pw_default_optimization_level = "debug" |
| |
| # List of application image GN targets specific to the Pigweed target. |
| pw_TARGET_APPLICATIONS = [] |
| |
| # Whether to run integration tests, which may involve multiple processes |
| # communicating over a socket. Integration tests require RPC synchronization. |
| pw_RUN_INTEGRATION_TESTS = host_os == "linux" |
| } |
| |
| # 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 = [ |
| ":check_modules", |
| ":docs", |
| ":host", |
| ":pi_pico", |
| ":python.lint", |
| ":python.tests", |
| ":static_analysis", |
| ":stm32f429i", |
| "pw_rpc:test_protos.python.install", |
| ] |
| |
| if (pw_RUN_INTEGRATION_TESTS) { |
| deps += [ ":integration_tests" ] |
| } |
| } |
| |
| # 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_modules_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", |
| ] |
| } |
| |
| # Check that PIGWEED_MODULES is up-to-date and sorted. |
| action("check_modules") { |
| forward_variables_from(_update_or_check_modules_lists, "*") |
| outputs = [ "$target_gen_dir/$target_name.passed" ] |
| args += [ "--warn-only" ] + rebase_path(outputs, root_build_dir) |
| } |
| |
| # 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 |
| } |
| |
| group("pw_system_demo") { |
| deps = [ "$dir_pw_system:system_examples" ] |
| } |
| |
| group("pi_pico") { |
| if (PICO_SRC_DIR != "") { |
| deps = [ ":pw_module_tests(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_optimization_level)", |
| ] |
| } |
| |
| foreach(optimization, |
| [ |
| "debug", |
| "size_optimized", |
| "speed_optimized", |
| ]) { |
| 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_" |
| } |
| |
| _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("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_" |
| } |
| } |
| |
| _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_" |
| } |
| |
| # 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") { |
| _toolchain = "$_internal_toolchains:pw_strict_host_clang_debug" |
| deps = [ ":pigweed_default($_toolchain.static_analysis)" ] |
| } |
| |
| group("docs") { |
| deps = [ "$dir_pigweed/docs($dir_pigweed/targets/docs)" ] |
| } |
| |
| # Tests larger than unit tests, typically run in a specific configuration. Only |
| # added if pw_RUN_INTEGRATION_TESTS is true. |
| group("integration_tests") { |
| _default_tc = _default_toolchain_prefix + pw_default_optimization_level |
| deps = [ |
| "$dir_pw_rpc:cpp_client_server_integration_test($_default_tc)", |
| "$dir_pw_rpc/py:python_client_cpp_server_test.action($_default_tc)", |
| "$dir_pw_unit_test/py:rpc_service_test.action($_default_tc)", |
| |
| # TODO(b/228463549): Re-enable these when they're not flaky on linux. |
| # "$dir_pw_transfer:cpp_client_integration_test($_default_tc)", |
| # "$dir_pw_transfer/py:python_cpp_transfer_test.action($_default_tc)", |
| ] |
| } |
| |
| # OSS-Fuzz uses this target to build fuzzers alone. |
| group("fuzzers") { |
| # Fuzzing is only supported on Linux and MacOS using clang. |
| if (host_os != "win") { |
| deps = [ ":pw_module_tests($dir_pigweed/targets/host:host_clang_fuzz)" ] |
| } |
| } |
| |
| group("asan") { |
| if (host_os != "win") { |
| deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_asan)" ] |
| } |
| } |
| |
| group("msan") { |
| if (host_os != "win") { |
| deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_msan)" ] |
| } |
| } |
| |
| group("tsan") { |
| if (host_os != "win") { |
| deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_tsan)" ] |
| } |
| } |
| |
| group("ubsan") { |
| if (host_os != "win") { |
| deps = |
| [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_ubsan)" ] |
| } |
| } |
| |
| group("ubsan_heuristic") { |
| if (host_os != "win") { |
| deps = [ ":pw_module_tests.run($dir_pigweed/targets/host:host_clang_ubsan_heuristic)" ] |
| } |
| } |
| |
| group("runtime_sanitizers") { |
| if (host_os != "win") { |
| deps = [ |
| ":asan", |
| ":msan", |
| ":tsan", |
| ":ubsan", |
| |
| # No ubsan_heuristic, which may have false positives. |
| ] |
| } |
| } |
| |
| pw_python_group("python") { |
| python_deps = [ |
| "$dir_pigweed/docs:sphinx_themes", |
| "$dir_pw_env_setup:python", |
| "$dir_pw_env_setup:target_support_packages", |
| ] |
| } |
| |
| # Build host-only tooling. |
| group("host_tools") { |
| deps = [ |
| "$dir_pw_target_runner/go:simple_client", |
| "$dir_pw_target_runner/go:simple_server", |
| ] |
| } |
| |
| # 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) { |
| deps = [ ":apps" ] |
| 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" ] |
| } |
| } |
| |
| # Trace examples currently only support running on non-windows host |
| if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") { |
| deps += [ |
| "$dir_pw_trace:trace_example_basic", |
| "$dir_pw_trace_tokenized:trace_tokenized_example_basic", |
| "$dir_pw_trace_tokenized:trace_tokenized_example_filter", |
| "$dir_pw_trace_tokenized:trace_tokenized_example_rpc", |
| "$dir_pw_trace_tokenized:trace_tokenized_example_trigger", |
| ] |
| } |
| } |
| |
| # 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 the pw_tool target to be built on host. |
| if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| pw_toolchain_SCOPE.is_host_toolchain) { |
| deps += [ "$dir_pw_tool" ] |
| } |
| } |
| |
| # All Pigweed modules that can be built using gn. This is 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 |
| } |
| } |