Carlos Chinchilla | 7b463a6 | 2020-08-20 14:26:35 -0700 | [diff] [blame] | 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 | |
Carlos Chinchilla | 7b463a6 | 2020-08-20 14:26:35 -0700 | [diff] [blame] | 15 | import("//build_overrides/pigweed.gni") |
Wyatt Hepler | de52a81 | 2020-11-05 21:29:41 -0800 | [diff] [blame] | 16 | |
Carlos Chinchilla | c6fa1cc | 2020-10-05 17:24:03 -0700 | [diff] [blame] | 17 | import("$dir_pw_arduino_build/arduino.gni") |
Rob Mohr | bf5b125 | 2020-11-05 09:53:29 -0800 | [diff] [blame] | 18 | import("$dir_pw_build/python.gni") |
Anthony DiGirolamo | b3f23f1 | 2022-03-17 14:57:35 -0700 | [diff] [blame] | 19 | import("$dir_pw_build/python_dist.gni") |
Anthony DiGirolamo | 0f2b29a | 2022-08-24 19:48:17 +0000 | [diff] [blame] | 20 | import("$dir_pw_build/python_venv.gni") |
Carlos Chinchilla | 917bff0 | 2020-09-10 14:15:58 -0700 | [diff] [blame] | 21 | import("$dir_pw_tokenizer/database.gni") |
Carlos Chinchilla | b6ab585 | 2020-08-20 15:49:39 -0700 | [diff] [blame] | 22 | import("$dir_pw_unit_test/test.gni") |
Carlos Chinchilla | 641439b | 2020-08-20 15:46:40 -0700 | [diff] [blame] | 23 | |
| 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 DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 30 | # Lists all the targets build by default with e.g. `ninja -C out`. |
| 31 | group("default") { |
| 32 | deps = [ |
| 33 | ":arduino", |
Anthony DiGirolamo | 701489b | 2023-08-24 01:01:42 +0000 | [diff] [blame] | 34 | ":docs", |
| 35 | ":examples", |
Anthony DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 36 | ":host", |
Wyatt Hepler | fe31864 | 2020-11-05 23:15:17 -0800 | [diff] [blame] | 37 | ":python.lint", |
| 38 | ":python.tests", |
Anthony DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 39 | ] |
Carlos Chinchilla | b6ab585 | 2020-08-20 15:49:39 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Anthony DiGirolamo | 701489b | 2023-08-24 01:01:42 +0000 | [diff] [blame] | 42 | group("docs") { |
| 43 | deps = [ "//docs($dir_pigweed/targets/docs)" ] |
| 44 | } |
| 45 | |
Anthony DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 46 | # Group all targets that run on host only, e.g. tests, utils. |
Carlos Chinchilla | 641439b | 2020-08-20 15:46:40 -0700 | [diff] [blame] | 47 | group("host") { |
Anthony DiGirolamo | 0bbadb5 | 2023-09-12 03:37:50 +0000 | [diff] [blame] | 48 | deps = [ ":run_tests(//targets/host:host_debug_tests)" ] |
Carlos Chinchilla | 641439b | 2020-08-20 15:46:40 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Anthony DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 51 | # Arduino specific targets. |
Carlos Chinchilla | 038a188 | 2020-09-23 11:19:24 -0700 | [diff] [blame] | 52 | group("arduino") { |
Anthony DiGirolamo | 6c3f365 | 2021-01-14 12:37:01 -0800 | [diff] [blame] | 53 | # If the 'pw_arduino_build_CORE_PATH' build arg is defined assume an arduino |
Anthony DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 54 | # core is available for building. |
| 55 | # |
| 56 | # For example: |
Anthony DiGirolamo | c70918b | 2021-01-26 11:41:47 -0800 | [diff] [blame] | 57 | # pw_arduino_build_CORE_PATH="//third_party/pigweed/third_party/arduino/cores" |
Anthony DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 58 | |
Anthony DiGirolamo | 6c3f365 | 2021-01-14 12:37:01 -0800 | [diff] [blame] | 59 | if (pw_arduino_build_CORE_PATH != "") { |
Anthony DiGirolamo | 0bbadb5 | 2023-09-12 03:37:50 +0000 | [diff] [blame] | 60 | deps = [ ":run_tests(//targets/arduino:arduino_debug_tests)" ] |
Carlos Chinchilla | c6fa1cc | 2020-10-05 17:24:03 -0700 | [diff] [blame] | 61 | } |
Carlos Chinchilla | 038a188 | 2020-09-23 11:19:24 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Anthony DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 64 | # stm32f429i_disc1 specific targets |
Armando Montanez | 1c00958 | 2020-11-03 18:29:15 -0800 | [diff] [blame] | 65 | group("stm32f429i_disc1") { |
Anthony DiGirolamo | e8a1edc | 2023-09-12 21:28:26 +0000 | [diff] [blame] | 66 | _default_toolchain = |
| 67 | "//targets/stm32f429i_disc1_stm32cube:stm32f429i_disc1_debug" |
Armando Montanez | 1c00958 | 2020-11-03 18:29:15 -0800 | [diff] [blame] | 68 | _testing_toolchain = "${_default_toolchain}_tests" |
Anthony DiGirolamo | 0bbadb5 | 2023-09-12 03:37:50 +0000 | [diff] [blame] | 69 | deps = [ ":run_tests(${_testing_toolchain})" ] |
Armando Montanez | 1c00958 | 2020-11-03 18:29:15 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Anthony DiGirolamo | 0f2b29a | 2022-08-24 19:48:17 +0000 | [diff] [blame] | 72 | # In-tree Python packages |
| 73 | _sample_project_python_packages = [ "//tools:tools" ] |
| 74 | |
Armando Montanez | 8378dca | 2024-01-03 20:58:50 +0000 | [diff] [blame] | 75 | # This group contains all the python packages that should be tested and linted. |
| 76 | pw_python_group("python") { |
| 77 | python_deps = _sample_project_python_packages |
| 78 | } |
| 79 | |
Anthony DiGirolamo | 0f2b29a | 2022-08-24 19:48:17 +0000 | [diff] [blame] | 80 | # 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 | # |
| 96 | pw_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 DiGirolamo | 0bbadb5 | 2023-09-12 03:37:50 +0000 | [diff] [blame] | 110 | pw_python_distribution("sample_project_python_distribution") { |
Anthony DiGirolamo | 0f2b29a | 2022-08-24 19:48:17 +0000 | [diff] [blame] | 111 | 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 DiGirolamo | 0bbadb5 | 2023-09-12 03:37:50 +0000 | [diff] [blame] | 122 | pw_python_pip_install("pip_install_sample_project_tools") { |
| 123 | packages = [ ":sample_project_python_distribution" ] |
Carlos Chinchilla | 917bff0 | 2020-09-10 14:15:58 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Anthony DiGirolamo | 701489b | 2023-08-24 01:01:42 +0000 | [diff] [blame] | 126 | group("examples") { |
Armando Montanez | 1c00958 | 2020-11-03 18:29:15 -0800 | [diff] [blame] | 127 | deps = [] |
Armando Montanez | 196b0cd | 2020-11-06 11:43:27 -0800 | [diff] [blame] | 128 | |
Armando Montanez | 7babcfc | 2023-09-11 23:12:29 +0000 | [diff] [blame] | 129 | # STMicroelectronics STM32F429I-DISC1 examples. |
Armando Montanez | 92920ef | 2023-09-11 23:21:56 +0000 | [diff] [blame] | 130 | deps += [ |
Ted Pudlik | b74d9b5 | 2024-03-11 16:57:41 +0000 | [diff] [blame] | 131 | "//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 Montanez | 92920ef | 2023-09-11 23:21:56 +0000 | [diff] [blame] | 134 | ] |
Armando Montanez | 7babcfc | 2023-09-11 23:12:29 +0000 | [diff] [blame] | 135 | |
Anthony DiGirolamo | 1682d53 | 2024-05-14 17:45:29 +0000 | [diff] [blame] | 136 | # 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 DiGirolamo | a3fa049 | 2023-09-13 16:41:15 +0000 | [diff] [blame] | 142 | |
Armando Montanez | cbd4a75 | 2023-09-22 21:49:00 +0000 | [diff] [blame] | 143 | # Host examples. |
| 144 | deps += [ |
Ted Pudlik | b74d9b5 | 2024-03-11 16:57:41 +0000 | [diff] [blame] | 145 | "//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 Montanez | cbd4a75 | 2023-09-22 21:49:00 +0000 | [diff] [blame] | 148 | ] |
Armando Montanez | 7babcfc | 2023-09-11 23:12:29 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Armando Montanez | b3f543c | 2023-09-20 21:39:38 +0000 | [diff] [blame] | 151 | # 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. |
| 154 | if (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 Pudlik | b74d9b5 | 2024-03-11 16:57:41 +0000 | [diff] [blame] | 159 | # "//examples/02_unit_testing:tests", |
Armando Montanez | b3f543c | 2023-09-20 21:39:38 +0000 | [diff] [blame] | 160 | ] |
| 161 | } |
Anthony DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 162 | |
Armando Montanez | b3f543c | 2023-09-20 21:39:38 +0000 | [diff] [blame] | 163 | 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 DiGirolamo | e47c4d6 | 2020-11-06 16:08:24 -0800 | [diff] [blame] | 171 | } |
| 172 | } |