blob: 0c6414f838babf4f949404d717de3e49dac36f3a [file] [log] [blame]
Wyatt Hepler0412a7d2020-01-28 16:27:32 -08001# Copyright 2020 The Pigweed Authors
Alexei Frolov1a82c142019-10-31 17:37:12 -07002#
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
Armando Montanezfb3d3fb2020-06-09 18:12:12 -070015import("//build_overrides/pigweed.gni")
Wyatt Hepleredf6f292019-11-25 18:52:21 -080016
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -070017import("$dir_pw_arduino_build/arduino.gni")
Alexei Frolov4c0428a2020-06-10 10:46:04 -070018import("$dir_pw_build/host_tool.gni")
Wyatt Heplerb16dfd32020-10-12 08:46:38 -070019import("$dir_pw_build/python.gni")
Alexei Frolov258fc1b2020-06-10 16:24:50 -070020import("$dir_pw_docgen/docs.gni")
Armando Montanez86003202020-06-16 18:00:06 -070021import("$dir_pw_toolchain/generate_toolchain.gni")
Armando Montanezfb3d3fb2020-06-09 18:12:12 -070022import("$dir_pw_unit_test/test.gni")
Alexei Frolov258fc1b2020-06-10 16:24:50 -070023
24# Main build file for upstream Pigweed.
25
Alexei Frolov4c0428a2020-06-10 10:46:04 -070026declare_args() {
Wyatt Hepler38c398d2020-07-14 11:15:30 -070027 # The default optimization level for building upstream Pigweed targets.
Armando Montanezebe27c62020-06-11 15:23:15 -070028 #
29 # Choices:
30 # debug
31 # size_optimized
32 # speed_optimized
Wyatt Hepler38c398d2020-07-14 11:15:30 -070033 pw_default_optimization_level = "debug"
Alexei Frolovf6753902020-07-08 11:01:45 -070034
35 # List of application image GN targets specific to the Pigweed target.
36 pw_TARGET_APPLICATIONS = []
Alexei Frolov4c0428a2020-06-10 10:46:04 -070037}
38
Armando Montanezebe27c62020-06-11 15:23:15 -070039# Enumerate all of the different targets that upstream Pigweed will build by
40# default. Downstream projects should not depend on this target; this target is
41# exclusively to facilitate easy upstream development and testing.
Armando Montanez04c56ae2019-12-12 14:34:05 -080042group("default") {
Armando Montanezebe27c62020-06-11 15:23:15 -070043 deps = [
44 ":docs",
Ali Zhang58765582021-01-29 12:04:06 -080045 ":fuzzers",
Armando Montanezebe27c62020-06-11 15:23:15 -070046 ":host",
Wyatt Heplerdcd72302021-01-13 14:04:53 -080047 ":python.install",
Armando Montanezec4aebb2020-11-11 18:43:26 -080048 ":python.lint",
49 ":python.tests",
Armando Montanez6f07fa72020-09-17 17:19:14 -070050 ":stm32f429i",
Armando Montanezec4aebb2020-11-11 18:43:26 -080051 ":target_support_packages.lint",
52 ":target_support_packages.tests",
Armando Montanezebe27c62020-06-11 15:23:15 -070053 ]
54}
55
Wyatt Hepler38c398d2020-07-14 11:15:30 -070056# This template generates a group that builds pigweed_default with a particular
57# toolchain.
58template("_build_pigweed_default_at_all_optimization_levels") {
59 _toolchain_prefix = invoker.toolchain_prefix
60
61 group(target_name) {
62 deps = [
63 ":pigweed_default(${_toolchain_prefix}$pw_default_optimization_level)",
64 ]
65 }
66
67 foreach(optimization,
68 [
69 "debug",
70 "size_optimized",
71 "speed_optimized",
72 ]) {
73 group(target_name + "_$optimization") {
74 deps = [ ":pigweed_default($_toolchain_prefix$optimization)" ]
75 }
76 }
77}
78
Wyatt Heplerb16dfd32020-10-12 08:46:38 -070079# Select a default toolchain based on host OS.
80if (host_os == "linux") {
81 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
82} else if (host_os == "mac") {
83 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
84} else if (host_os == "win") {
85 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
86} else {
87 assert(false, "Please define a host config for your system: $host_os")
88}
89
Armando Montanezebe27c62020-06-11 15:23:15 -070090# Below are a list of GN targets you can build to force Pigweed to build for a
91# specific Pigweed target.
Wyatt Hepler38c398d2020-07-14 11:15:30 -070092_build_pigweed_default_at_all_optimization_levels("host") {
Wyatt Heplerb16dfd32020-10-12 08:46:38 -070093 toolchain_prefix = _default_toolchain_prefix
Armando Montanezebe27c62020-06-11 15:23:15 -070094}
95
Wyatt Hepler38c398d2020-07-14 11:15:30 -070096_build_pigweed_default_at_all_optimization_levels("host_clang") {
97 toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
Armando Montanezebe27c62020-06-11 15:23:15 -070098}
99
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700100_build_pigweed_default_at_all_optimization_levels("host_gcc") {
101 toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700102}
103
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700104_build_pigweed_default_at_all_optimization_levels("stm32f429i") {
105 toolchain_prefix = "$dir_pigweed/targets/stm32f429i-disc1:stm32f429i_disc1_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700106}
107
Anthony DiGirolamo383be052020-11-26 12:06:41 -0800108if (pw_arduino_build_CORE_PATH != "") {
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700109 _build_pigweed_default_at_all_optimization_levels("arduino") {
110 toolchain_prefix = "$dir_pigweed/targets/arduino:arduino_"
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -0700111 }
112}
113
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700114_build_pigweed_default_at_all_optimization_levels("qemu") {
115 toolchain_prefix = "$dir_pigweed/targets/lm3s6965evb-qemu:lm3s6965evb_qemu_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700116}
117
118group("docs") {
119 deps = [ ":pigweed_default($dir_pigweed/targets/docs)" ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700120}
121
Ali Zhang58765582021-01-29 12:04:06 -0800122# OSS-Fuzz uses this target to build fuzzers alone.
123group("fuzzers") {
124 # Fuzzing is only supported on Linux and MacOS using clang.
125 if (host_os != "win") {
126 deps = [ ":pw_module_tests($dir_pigweed/targets/host:host_clang_fuzz)" ]
127 }
128}
129
Wyatt Heplerb16dfd32020-10-12 08:46:38 -0700130pw_python_group("python") {
Armando Montanezec4aebb2020-11-11 18:43:26 -0800131 python_deps = [
Wyatt Hepler45af57b2020-10-23 08:05:28 -0700132 # Python packages
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700133 "$dir_pw_allocator/py",
134 "$dir_pw_arduino_build/py",
Wyatt Hepler96992c72020-10-23 08:05:33 -0700135 "$dir_pw_bloat/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700136 "$dir_pw_build/py",
137 "$dir_pw_cli/py",
Armando Montanez40740792020-10-20 17:32:20 -0700138 "$dir_pw_cpu_exception_cortex_m/py",
Wyatt Hepler96992c72020-10-23 08:05:33 -0700139 "$dir_pw_docgen/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700140 "$dir_pw_doctor/py",
141 "$dir_pw_env_setup/py",
Alexei Frolovd3e5cb72021-01-08 13:08:45 -0800142 "$dir_pw_hdlc/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700143 "$dir_pw_module/py",
Wyatt Hepler96992c72020-10-23 08:05:33 -0700144 "$dir_pw_package/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700145 "$dir_pw_presubmit/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700146 "$dir_pw_protobuf/py",
Armando Montanezec4aebb2020-11-11 18:43:26 -0800147 "$dir_pw_protobuf_compiler/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700148 "$dir_pw_rpc/py",
149 "$dir_pw_status/py",
150 "$dir_pw_tokenizer/py",
151 "$dir_pw_trace/py",
152 "$dir_pw_trace_tokenized/py",
153 "$dir_pw_unit_test/py",
154 "$dir_pw_watch/py",
155
Wyatt Hepler45af57b2020-10-23 08:05:28 -0700156 # Standalone scripts
Alexei Frolovd3e5cb72021-01-08 13:08:45 -0800157 "$dir_pw_hdlc/rpc_example:example_script",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700158 ]
Wyatt Heplerb16dfd32020-10-12 08:46:38 -0700159}
160
Wyatt Hepler96992c72020-10-23 08:05:33 -0700161# Python packages for supporting specific targets.
162pw_python_group("target_support_packages") {
163 python_deps = [
Armando Montanezec4aebb2020-11-11 18:43:26 -0800164 "$dir_pigweed/targets/lm3s6965evb-qemu/py",
165 "$dir_pigweed/targets/stm32f429i-disc1/py",
Wyatt Hepler96992c72020-10-23 08:05:33 -0700166 ]
167}
168
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700169# By default, Pigweed will build this target when invoking ninja.
170group("pigweed_default") {
Alexei Frolov799be5d2020-01-09 15:54:39 -0800171 deps = []
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700172
173 # Prevent the default toolchain from parsing any other BUILD.gn files.
174 if (current_toolchain != default_toolchain) {
Alexei Frolov258fc1b2020-06-10 16:24:50 -0700175 if (pw_docgen_BUILD_DOCS) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700176 deps += [ "$dir_pigweed/docs" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -0800177 } else {
Armando Montanezec4aebb2020-11-11 18:43:26 -0800178 deps += [ ":apps" ]
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700179 if (pw_unit_test_AUTOMATIC_RUNNER == "") {
180 # Without a test runner defined, build the tests but don't run them.
181 deps += [ ":pw_module_tests" ]
182 } else {
183 # With a test runner, depend on the run targets so they run with the
184 # build.
Alexei Frolov69dccfd2020-11-13 12:10:24 -0800185 deps += [ ":pw_module_tests.run" ]
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700186 }
187 }
Armando Montanez86003202020-06-16 18:00:06 -0700188 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
189 pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700190 deps += [ ":host_tools" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -0800191 }
Robert Oliver70b92642020-07-13 15:04:10 -0400192
193 # Trace examples currently only support running on non-windows host
194 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
195 pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") {
Robert Oliver6d05de12020-07-13 15:10:42 -0400196 deps += [
197 "$dir_pw_trace:trace_example_basic",
198 "$dir_pw_trace_tokenized:trace_tokenized_example_basic",
Robert Oliver0cc20752020-07-14 15:24:22 -0400199 "$dir_pw_trace_tokenized:trace_tokenized_example_filter",
Robert Oliver19146912020-07-14 10:49:48 -0400200 "$dir_pw_trace_tokenized:trace_tokenized_example_trigger",
Robert Oliver6d05de12020-07-13 15:10:42 -0400201 ]
Robert Oliver70b92642020-07-13 15:04:10 -0400202 }
Keir Mierlee2f5d0f2019-12-16 11:36:22 -0800203 }
Alexei Frolovca9cf602019-12-26 13:00:03 -0800204}
205
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700206# Prevent the default toolchain from parsing any other BUILD.gn files.
207if (current_toolchain != default_toolchain) {
Alexei Frolovf6753902020-07-08 11:01:45 -0700208 group("apps") {
209 # Application images built for all targets.
Alexei Frolovd3e5cb72021-01-08 13:08:45 -0800210 deps = [ "$dir_pw_hdlc/rpc_example" ]
Alexei Frolovf6753902020-07-08 11:01:45 -0700211
212 # Add target-specific images.
213 deps += pw_TARGET_APPLICATIONS
214 }
215
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700216 group("host_tools") {
217 deps = [
218 "$dir_pw_target_runner/go:simple_client",
219 "$dir_pw_target_runner/go:simple_server",
Rob Mohr2156c0a2020-02-07 10:06:53 -0800220 ]
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800221 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800222
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700223 # All Pigweed modules that can be built using gn. This is not built by default.
224 group("pw_modules") {
225 deps = [
226 "$dir_pigweed/docs",
227 "$dir_pw_allocator",
228 "$dir_pw_base64",
David Rogers2d195022020-07-16 14:07:47 -0700229 "$dir_pw_blob_store",
shaneajg9c19db42020-06-11 15:49:51 -0400230 "$dir_pw_bytes",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700231 "$dir_pw_checksum",
Ewout van Bekkum3c61ae92020-10-30 15:52:25 -0700232 "$dir_pw_chrono",
Alexei Frolovf6753902020-07-08 11:01:45 -0700233 "$dir_pw_cpu_exception",
Alexei Frolovd3e5cb72021-01-08 13:08:45 -0800234 "$dir_pw_hdlc",
Ewout van Bekkumd1669a82020-12-04 16:00:47 -0800235 "$dir_pw_i2c",
Keir Mierle45fa7852020-08-10 21:09:54 -0700236 "$dir_pw_metric",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700237 "$dir_pw_polyfill",
238 "$dir_pw_preprocessor",
239 "$dir_pw_protobuf",
240 "$dir_pw_result",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700241 "$dir_pw_status",
242 "$dir_pw_stream",
243 "$dir_pw_string",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800244 "$dir_pw_sync",
Alexei Frolovf6753902020-07-08 11:01:45 -0700245 "$dir_pw_sys_io",
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800246 "$dir_pw_thread",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700247 "$dir_pw_trace",
248 "$dir_pw_unit_test",
249 "$dir_pw_varint",
250 ]
251
252 if (host_os != "win") {
253 deps += [
254 # TODO(frolv): Remove these two when new KVS is ready.
255 "$dir_pw_kvs",
256 "$dir_pw_minimal_cpp_stdlib",
257
258 # TODO(pwbug/111): Remove this when building successfully on Windows.
259 "$dir_pw_tokenizer",
260 ]
261 }
Armando Montanez870a86b2020-05-26 10:54:38 -0700262 }
263
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700264 # Targets for all module unit test groups.
265 pw_test_group("pw_module_tests") {
266 group_deps = [
267 "$dir_pw_allocator:tests",
268 "$dir_pw_assert:tests",
269 "$dir_pw_base64:tests",
David Rogers2d195022020-07-16 14:07:47 -0700270 "$dir_pw_blob_store:tests",
shaneajg9c19db42020-06-11 15:49:51 -0400271 "$dir_pw_bytes:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700272 "$dir_pw_checksum:tests",
Ewout van Bekkum3c61ae92020-10-30 15:52:25 -0700273 "$dir_pw_chrono:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700274 "$dir_pw_containers:tests",
Armando Montaneza9ca9992021-01-26 17:06:10 -0800275 "$dir_pw_cpu_exception_cortex_m:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700276 "$dir_pw_fuzzer:tests",
Alexei Frolovd3e5cb72021-01-08 13:08:45 -0800277 "$dir_pw_hdlc:tests",
Armando Montanez593d0d52020-07-08 19:55:01 -0700278 "$dir_pw_hex_dump:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700279 "$dir_pw_log:tests",
Prashanth Swaminathan5ef2aa22020-11-10 09:57:46 -0800280 "$dir_pw_log_multisink:tests",
Wyatt Hepler24a6e272020-09-01 10:25:28 -0700281 "$dir_pw_log_null:tests",
Prashanth Swaminathanfce26ba2020-09-25 13:36:07 -0700282 "$dir_pw_log_rpc:tests",
Prashanth Swaminathan49a4a822021-01-12 18:41:52 -0800283 "$dir_pw_log_sink:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700284 "$dir_pw_log_tokenized:tests",
Chenghan Zhoud4f44d22020-06-18 15:42:06 -0400285 "$dir_pw_malloc_freelist:tests",
Keir Mierle45fa7852020-08-10 21:09:54 -0700286 "$dir_pw_metric:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700287 "$dir_pw_polyfill:tests",
288 "$dir_pw_preprocessor:tests",
289 "$dir_pw_protobuf:tests",
290 "$dir_pw_protobuf_compiler:tests",
Armando Montanez47008e82020-08-04 11:04:45 -0700291 "$dir_pw_random:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700292 "$dir_pw_result:tests",
293 "$dir_pw_ring_buffer:tests",
Alexei Frolov5af57d12021-01-12 11:38:06 -0800294 "$dir_pw_router:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700295 "$dir_pw_rpc:tests",
296 "$dir_pw_span:tests",
297 "$dir_pw_status:tests",
298 "$dir_pw_stream:tests",
299 "$dir_pw_string:tests",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800300 "$dir_pw_sync:tests",
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800301 "$dir_pw_thread:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700302 "$dir_pw_tokenizer:tests",
303 "$dir_pw_trace:tests",
Robert Oliver21dcf272020-05-12 15:41:52 -0400304 "$dir_pw_trace_tokenized:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700305 "$dir_pw_unit_test:tests",
306 "$dir_pw_varint:tests",
307 ]
308
Armando Montanez86003202020-06-16 18:00:06 -0700309 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
310 pw_toolchain_SCOPE.is_host_toolchain) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700311 # TODO(pwbug/196): KVS tests are not compatible with device builds as they
312 # use features such as std::map and are computationally expensive. Solving
313 # this requires a more complex capabilities-based build and configuration
314 # system which allowing enabling specific tests for targets that support
315 # them and modifying test parameters for different targets.
316 #
317 # Checking for pw_build_host_tools (which is only set by the host) is a
318 # temporary fix until the problem can be properly solved.
319 group_deps += [ "$dir_pw_kvs:tests" ]
320 }
321
322 if (host_os != "win") {
323 # TODO(amontanez): pw_minimal_cpp_stdlib tests do not build on windows.
324 group_deps += [ "$dir_pw_minimal_cpp_stdlib:tests" ]
325 }
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800326 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800327}