blob: d6a427e5c8fcf3da53d56aff4f46f73343106a32 [file] [log] [blame]
Carlos Chinchilla7b463a62020-08-20 14:26:35 -07001# 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
Carlos Chinchilla7b463a62020-08-20 14:26:35 -070015import("//build_overrides/pigweed.gni")
Wyatt Heplerde52a812020-11-05 21:29:41 -080016
Carlos Chinchillac6fa1cc2020-10-05 17:24:03 -070017import("$dir_pw_arduino_build/arduino.gni")
Rob Mohrbf5b1252020-11-05 09:53:29 -080018import("$dir_pw_build/python.gni")
Anthony DiGirolamob3f23f12022-03-17 14:57:35 -070019import("$dir_pw_build/python_dist.gni")
Anthony DiGirolamo0f2b29a2022-08-24 19:48:17 +000020import("$dir_pw_build/python_venv.gni")
Carlos Chinchilla917bff02020-09-10 14:15:58 -070021import("$dir_pw_tokenizer/database.gni")
Carlos Chinchillab6ab5852020-08-20 15:49:39 -070022import("$dir_pw_unit_test/test.gni")
Carlos Chinchilla641439b2020-08-20 15:46:40 -070023
24# NOTE: All the `deps` listed in `//BUILD.gn` must either be instantiated with a
25# toolchain, e.g. `":my_host_target(//path/to/host:toolchain)"`, or listed
26# within an `if (current_toolchain != default_toolchain)` statement.
27# It also prevents the default toolchain from parsing any unnecessary BUILD.gn
28# files.
29
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -080030# Lists all the targets build by default with e.g. `ninja -C out`.
31group("default") {
32 deps = [
33 ":arduino",
Anthony DiGirolamo701489b2023-08-24 01:01:42 +000034 ":docs",
35 ":examples",
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -080036 ":host",
Wyatt Heplerfe318642020-11-05 23:15:17 -080037 ":python.lint",
38 ":python.tests",
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -080039 ]
Carlos Chinchillab6ab5852020-08-20 15:49:39 -070040}
41
Anthony DiGirolamo701489b2023-08-24 01:01:42 +000042group("docs") {
43 deps = [ "//docs($dir_pigweed/targets/docs)" ]
44}
45
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -080046# Group all targets that run on host only, e.g. tests, utils.
Carlos Chinchilla641439b2020-08-20 15:46:40 -070047group("host") {
Anthony DiGirolamo0bbadb52023-09-12 03:37:50 +000048 deps = [ ":run_tests(//targets/host:host_debug_tests)" ]
Carlos Chinchilla641439b2020-08-20 15:46:40 -070049}
50
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -080051# Arduino specific targets.
Carlos Chinchilla038a1882020-09-23 11:19:24 -070052group("arduino") {
Anthony DiGirolamo6c3f3652021-01-14 12:37:01 -080053 # If the 'pw_arduino_build_CORE_PATH' build arg is defined assume an arduino
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -080054 # core is available for building.
55 #
56 # For example:
Anthony DiGirolamoc70918b2021-01-26 11:41:47 -080057 # pw_arduino_build_CORE_PATH="//third_party/pigweed/third_party/arduino/cores"
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -080058
Anthony DiGirolamo6c3f3652021-01-14 12:37:01 -080059 if (pw_arduino_build_CORE_PATH != "") {
Anthony DiGirolamo0bbadb52023-09-12 03:37:50 +000060 deps = [ ":run_tests(//targets/arduino:arduino_debug_tests)" ]
Carlos Chinchillac6fa1cc2020-10-05 17:24:03 -070061 }
Carlos Chinchilla038a1882020-09-23 11:19:24 -070062}
63
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -080064# stm32f429i_disc1 specific targets
Armando Montanez1c009582020-11-03 18:29:15 -080065group("stm32f429i_disc1") {
Anthony DiGirolamoe8a1edc2023-09-12 21:28:26 +000066 _default_toolchain =
67 "//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_debug"
Armando Montanez1c009582020-11-03 18:29:15 -080068 _testing_toolchain = "${_default_toolchain}_tests"
Anthony DiGirolamo0bbadb52023-09-12 03:37:50 +000069 deps = [ ":run_tests(${_testing_toolchain})" ]
Armando Montanez1c009582020-11-03 18:29:15 -080070}
71
Anthony DiGirolamo0f2b29a2022-08-24 19:48:17 +000072# In-tree Python packages
73_sample_project_python_packages = [ "//tools:tools" ]
74
Armando Montanez8378dca2024-01-03 20:58:50 +000075# This group contains all the python packages that should be tested and linted.
76pw_python_group("python") {
77 python_deps = _sample_project_python_packages
78}
79
Anthony DiGirolamo0f2b29a2022-08-24 19:48:17 +000080# Pigweed Python packages to include
81_pigweed_python_packages = [
82 "$dir_pw_env_setup:core_pigweed_python_packages",
83 "$dir_pigweed/targets/lm3s6965evb_qemu/py",
84 "$dir_pigweed/targets/stm32f429i_disc1/py",
85]
86
87_all_python_packages =
88 _sample_project_python_packages + _pigweed_python_packages
89
90# The default venv for Python actions in GN
91# Set this gn arg in a declare_args block in this file 'BUILD.gn' or in '.gn' to
92# use this venv.
93#
94# pw_build_PYTHON_BUILD_VENV = "//:sample_project_build_venv"
95#
96pw_python_venv("sample_project_build_venv") {
97 path = "$root_build_dir/python-venv"
98 constraints = pw_build_PIP_CONSTRAINTS
99 requirements = pw_build_PIP_REQUIREMENTS
100
101 # Ensure all third party Python dependencies are installed into this venv.
102 # This works by checking the setup.cfg files for all packages listed here and
103 # installing the packages listed in the [options].install_requires field.
104 source_packages = _all_python_packages
105}
106
107# This template collects all python packages and their dependencies into a
108# single super Python package for installation into the bootstrapped virtual
109# environment.
Anthony DiGirolamo0bbadb52023-09-12 03:37:50 +0000110pw_python_distribution("sample_project_python_distribution") {
Anthony DiGirolamo0f2b29a2022-08-24 19:48:17 +0000111 packages = _all_python_packages
112 generate_setup_cfg = {
113 name = "sample-project-tools"
114 version = "0.0.1"
115 append_date_to_version = true
116 include_default_pyproject_file = true
117 }
118}
119
120# Install the sample-project-tools super Python package into the bootstrapped
121# Python venv.
Anthony DiGirolamo0bbadb52023-09-12 03:37:50 +0000122pw_python_pip_install("pip_install_sample_project_tools") {
123 packages = [ ":sample_project_python_distribution" ]
Carlos Chinchilla917bff02020-09-10 14:15:58 -0700124}
125
Anthony DiGirolamo701489b2023-08-24 01:01:42 +0000126group("examples") {
Armando Montanez1c009582020-11-03 18:29:15 -0800127 deps = []
Armando Montanez196b0cd2020-11-06 11:43:27 -0800128
Armando Montanez7babcfc2023-09-11 23:12:29 +0000129 # STMicroelectronics STM32F429I-DISC1 examples.
Armando Montanez92920ef2023-09-11 23:21:56 +0000130 deps += [
Ted Pudlikb74d9b52024-03-11 16:57:41 +0000131 "//examples/01_blinky:blinky(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
132 "//examples/02_unit_testing:test_runner_app(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
133 "//examples/03_rpc:rpc_main(//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_stm32cube.size_optimized)",
Armando Montanez92920ef2023-09-11 23:21:56 +0000134 ]
Armando Montanez7babcfc2023-09-11 23:12:29 +0000135
Anthony DiGirolamo1682d532024-05-14 17:45:29 +0000136 # Raspberry Pi Pico RP2040 examples.
137 deps += [
138 "//examples/01_blinky:blinky(//targets/rp2040:rp2040.size_optimized)",
139 "//examples/02_unit_testing:test_runner_app(//targets/rp2040:rp2040.size_optimized)",
140 "//examples/03_rpc:rpc_main(//targets/rp2040:rp2040.size_optimized)",
141 ]
Anthony DiGirolamoa3fa0492023-09-13 16:41:15 +0000142
Armando Montanezcbd4a752023-09-22 21:49:00 +0000143 # Host examples.
144 deps += [
Ted Pudlikb74d9b52024-03-11 16:57:41 +0000145 "//examples/01_blinky:blinky(//targets/host:host_device_simulator.speed_optimized)",
146 "//examples/02_unit_testing:test_runner_app(//targets/host:host_device_simulator.speed_optimized)",
147 "//examples/03_rpc:rpc_main(//targets/host:host_device_simulator.speed_optimized)",
Armando Montanezcbd4a752023-09-22 21:49:00 +0000148 ]
Armando Montanez7babcfc2023-09-11 23:12:29 +0000149}
150
Armando Montanezb3f543c2023-09-20 21:39:38 +0000151# TODO: b/301306292 - Removing this causes a duplicate toolchain to be
152# generated if any tests are present in the test group. Figure out why, and set
153# up a more scalable solution.
154if (current_toolchain != default_toolchain) {
155 # All the tests that should run as part of the build.
156 pw_test_group("tests") {
157 group_deps = [
158 # Uncomment this to automatically run the example unit test.
Ted Pudlikb74d9b52024-03-11 16:57:41 +0000159 # "//examples/02_unit_testing:tests",
Armando Montanezb3f543c2023-09-20 21:39:38 +0000160 ]
161 }
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -0800162
Armando Montanezb3f543c2023-09-20 21:39:38 +0000163 group("run_tests") {
164 if (pw_unit_test_AUTOMATIC_RUNNER == "") {
165 # Without a test runner defined, build the tests but don't run them.
166 deps = [ ":tests" ]
167 } else {
168 # With a test runner, build and run tests.
169 deps = [ ":tests.run" ]
170 }
Anthony DiGirolamoe47c4d62020-11-06 16:08:24 -0800171 }
172}