blob: df37b8ac413972b1cf275b2d587f5bc9a5d2ba7d [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 Heplere04d4682021-07-21 08:52:28 -070047 ":integration_tests",
Armando Montanez6f07fa72020-09-17 17:19:14 -070048 ":stm32f429i",
Rob Mohr0d644f62021-02-24 16:15:51 -080049 "$dir_pw_env_setup:python.install",
50 "$dir_pw_env_setup:python.lint",
51 "$dir_pw_env_setup:python.tests",
52 "$dir_pw_env_setup:target_support_packages.lint",
53 "$dir_pw_env_setup:target_support_packages.tests",
Armando Montanezebe27c62020-06-11 15:23:15 -070054 ]
55}
56
Wyatt Hepler38c398d2020-07-14 11:15:30 -070057# This template generates a group that builds pigweed_default with a particular
58# toolchain.
59template("_build_pigweed_default_at_all_optimization_levels") {
60 _toolchain_prefix = invoker.toolchain_prefix
61
62 group(target_name) {
63 deps = [
64 ":pigweed_default(${_toolchain_prefix}$pw_default_optimization_level)",
65 ]
66 }
67
68 foreach(optimization,
69 [
70 "debug",
71 "size_optimized",
72 "speed_optimized",
73 ]) {
74 group(target_name + "_$optimization") {
75 deps = [ ":pigweed_default($_toolchain_prefix$optimization)" ]
76 }
77 }
78}
79
Wyatt Heplerb16dfd32020-10-12 08:46:38 -070080# Select a default toolchain based on host OS.
81if (host_os == "linux") {
82 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
83} else if (host_os == "mac") {
84 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
85} else if (host_os == "win") {
86 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
87} else {
88 assert(false, "Please define a host config for your system: $host_os")
89}
90
Armando Montanezebe27c62020-06-11 15:23:15 -070091# Below are a list of GN targets you can build to force Pigweed to build for a
92# specific Pigweed target.
Wyatt Hepler38c398d2020-07-14 11:15:30 -070093_build_pigweed_default_at_all_optimization_levels("host") {
Wyatt Heplerb16dfd32020-10-12 08:46:38 -070094 toolchain_prefix = _default_toolchain_prefix
Armando Montanezebe27c62020-06-11 15:23:15 -070095}
96
Wyatt Hepler38c398d2020-07-14 11:15:30 -070097_build_pigweed_default_at_all_optimization_levels("host_clang") {
98 toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
Armando Montanezebe27c62020-06-11 15:23:15 -070099}
100
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700101_build_pigweed_default_at_all_optimization_levels("host_gcc") {
102 toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700103}
104
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700105_build_pigweed_default_at_all_optimization_levels("stm32f429i") {
Rob Mohr3d61b322021-05-17 10:52:24 -0700106 toolchain_prefix = "$dir_pigweed/targets/stm32f429i_disc1:stm32f429i_disc1_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700107}
108
Anthony DiGirolamo383be052020-11-26 12:06:41 -0800109if (pw_arduino_build_CORE_PATH != "") {
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700110 _build_pigweed_default_at_all_optimization_levels("arduino") {
111 toolchain_prefix = "$dir_pigweed/targets/arduino:arduino_"
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -0700112 }
113}
114
Armando Montanez1ee925c2020-06-29 13:15:28 -0700115_build_pigweed_default_at_all_optimization_levels("qemu_gcc") {
116 toolchain_prefix =
Rob Mohr3d61b322021-05-17 10:52:24 -0700117 "$dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_gcc_"
Armando Montanez1ee925c2020-06-29 13:15:28 -0700118}
119
120_build_pigweed_default_at_all_optimization_levels("qemu_clang") {
121 toolchain_prefix =
Rob Mohr3d61b322021-05-17 10:52:24 -0700122 "$dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700123}
124
125group("docs") {
Wyatt Hepler09d84aa2021-02-03 14:25:45 -0800126 deps = [ "$dir_pigweed/docs($dir_pigweed/targets/docs)" ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700127}
128
Wyatt Heplere04d4682021-07-21 08:52:28 -0700129_default_toolchain = _default_toolchain_prefix + pw_default_optimization_level
130
Wyatt Hepler81017fe2021-08-02 17:46:41 -0700131# Tests larger than unit tests, typically run in a specific configuration.
Wyatt Heplere04d4682021-07-21 08:52:28 -0700132group("integration_tests") {
133 deps = []
134
135 if (host_os != "windows") {
Wyatt Hepler22530402021-07-30 23:40:40 -0700136 deps += [
Wyatt Hepler81017fe2021-08-02 17:46:41 -0700137 # Uses port 33000
Wyatt Hepler22530402021-07-30 23:40:40 -0700138 "$dir_pw_rpc/py:python_client_cpp_server_test.action($_default_toolchain)",
Wyatt Hepler81017fe2021-08-02 17:46:41 -0700139
140 # Uses port 33001
Wyatt Hepler22530402021-07-30 23:40:40 -0700141 "$dir_pw_transfer/py:python_cpp_transfer_test.action($_default_toolchain)",
Wyatt Hepler81017fe2021-08-02 17:46:41 -0700142
143 # Uses port 33002
144 "$dir_pw_unit_test/py:rpc_service_test.action($_default_toolchain)",
Wyatt Hepler22530402021-07-30 23:40:40 -0700145 ]
Wyatt Heplere04d4682021-07-21 08:52:28 -0700146 } else {
147 not_needed([ "_default_toolchain" ])
148 }
149}
150
Ali Zhang58765582021-01-29 12:04:06 -0800151# OSS-Fuzz uses this target to build fuzzers alone.
152group("fuzzers") {
153 # Fuzzing is only supported on Linux and MacOS using clang.
154 if (host_os != "win") {
155 deps = [ ":pw_module_tests($dir_pigweed/targets/host:host_clang_fuzz)" ]
156 }
157}
158
Rob Mohr0d644f62021-02-24 16:15:51 -0800159# TODO(pwbug/325) Delete this target.
Wyatt Heplerb16dfd32020-10-12 08:46:38 -0700160pw_python_group("python") {
Rob Mohr0d644f62021-02-24 16:15:51 -0800161 python_deps = [ "$dir_pw_env_setup:python" ]
Wyatt Heplerb16dfd32020-10-12 08:46:38 -0700162}
163
Rob Mohr0d644f62021-02-24 16:15:51 -0800164# TODO(pwbug/325) Delete this target.
Wyatt Hepler96992c72020-10-23 08:05:33 -0700165pw_python_group("target_support_packages") {
Rob Mohr0d644f62021-02-24 16:15:51 -0800166 python_deps = [ "$dir_pw_env_setup:target_support_packages" ]
Wyatt Hepler96992c72020-10-23 08:05:33 -0700167}
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) {
Wyatt Hepler09d84aa2021-02-03 14:25:45 -0800175 deps = [ ":apps" ]
176 if (pw_unit_test_AUTOMATIC_RUNNER == "") {
177 # Without a test runner defined, build the tests but don't run them.
178 deps += [ ":pw_module_tests" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -0800179 } else {
Wyatt Hepler09d84aa2021-02-03 14:25:45 -0800180 # With a test runner, depend on the run targets so they run with the
181 # build.
182 deps += [ ":pw_module_tests.run" ]
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700183 }
Wyatt Hepler09d84aa2021-02-03 14:25:45 -0800184 }
185 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
186 pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) {
187 deps += [ ":host_tools" ]
188 }
Robert Oliver70b92642020-07-13 15:04:10 -0400189
Wyatt Hepler09d84aa2021-02-03 14:25:45 -0800190 # Trace examples currently only support running on non-windows host
191 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
192 pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") {
193 deps += [
194 "$dir_pw_trace:trace_example_basic",
195 "$dir_pw_trace_tokenized:trace_tokenized_example_basic",
196 "$dir_pw_trace_tokenized:trace_tokenized_example_filter",
Rob Oliver9d663372021-02-05 11:02:05 -0500197 "$dir_pw_trace_tokenized:trace_tokenized_example_rpc",
Wyatt Hepler09d84aa2021-02-03 14:25:45 -0800198 "$dir_pw_trace_tokenized:trace_tokenized_example_trigger",
199 ]
Keir Mierlee2f5d0f2019-12-16 11:36:22 -0800200 }
Alexei Frolovca9cf602019-12-26 13:00:03 -0800201}
202
Wyatt Hepler09d84aa2021-02-03 14:25:45 -0800203# The default toolchain is not used for compiling C/C++ code.
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700204if (current_toolchain != default_toolchain) {
Alexei Frolovf6753902020-07-08 11:01:45 -0700205 group("apps") {
206 # Application images built for all targets.
Alexei Frolovd3e5cb72021-01-08 13:08:45 -0800207 deps = [ "$dir_pw_hdlc/rpc_example" ]
Alexei Frolovf6753902020-07-08 11:01:45 -0700208
209 # Add target-specific images.
210 deps += pw_TARGET_APPLICATIONS
Jason Graffius4d13de92021-01-16 20:26:21 -0800211
212 # Add the pw_tool target to be built on host.
213 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
214 pw_toolchain_SCOPE.is_host_toolchain) {
215 deps += [ "$dir_pw_tool" ]
216 }
Alexei Frolovf6753902020-07-08 11:01:45 -0700217 }
218
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700219 group("host_tools") {
220 deps = [
221 "$dir_pw_target_runner/go:simple_client",
222 "$dir_pw_target_runner/go:simple_server",
Rob Mohr2156c0a2020-02-07 10:06:53 -0800223 ]
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800224 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800225
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700226 # All Pigweed modules that can be built using gn. This is not built by default.
227 group("pw_modules") {
228 deps = [
229 "$dir_pigweed/docs",
230 "$dir_pw_allocator",
Kevin Zeng62683b62021-03-18 12:22:08 -0700231 "$dir_pw_analog",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700232 "$dir_pw_base64",
David Rogers2d195022020-07-16 14:07:47 -0700233 "$dir_pw_blob_store",
shaneajg9c19db42020-06-11 15:49:51 -0400234 "$dir_pw_bytes",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700235 "$dir_pw_checksum",
Ewout van Bekkum3c61ae92020-10-30 15:52:25 -0700236 "$dir_pw_chrono",
Anthony DiGirolamo26ed98a2021-06-11 14:50:29 -0700237 "$dir_pw_console",
Alexei Frolovf6753902020-07-08 11:01:45 -0700238 "$dir_pw_cpu_exception",
Alexei Frolovd3e5cb72021-01-08 13:08:45 -0800239 "$dir_pw_hdlc",
Ewout van Bekkumd1669a82020-12-04 16:00:47 -0800240 "$dir_pw_i2c",
Keir Mierle45fa7852020-08-10 21:09:54 -0700241 "$dir_pw_metric",
Ewout van Bekkum32dc5c52021-03-16 11:35:37 -0700242 "$dir_pw_persistent_ram",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700243 "$dir_pw_polyfill",
244 "$dir_pw_preprocessor",
245 "$dir_pw_protobuf",
246 "$dir_pw_result",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700247 "$dir_pw_status",
248 "$dir_pw_stream",
249 "$dir_pw_string",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800250 "$dir_pw_sync",
Alexei Frolovf6753902020-07-08 11:01:45 -0700251 "$dir_pw_sys_io",
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800252 "$dir_pw_thread",
Jason Graffius4d13de92021-01-16 20:26:21 -0800253 "$dir_pw_tool",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700254 "$dir_pw_trace",
255 "$dir_pw_unit_test",
256 "$dir_pw_varint",
257 ]
258
259 if (host_os != "win") {
260 deps += [
261 # TODO(frolv): Remove these two when new KVS is ready.
262 "$dir_pw_kvs",
263 "$dir_pw_minimal_cpp_stdlib",
264
265 # TODO(pwbug/111): Remove this when building successfully on Windows.
266 "$dir_pw_tokenizer",
267 ]
268 }
Armando Montanez870a86b2020-05-26 10:54:38 -0700269 }
270
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700271 # Targets for all module unit test groups.
272 pw_test_group("pw_module_tests") {
273 group_deps = [
Armando Montanez28f82182021-02-05 17:10:43 -0800274 "$dir_pw_allocator:tests",
Kevin Zeng62683b62021-03-18 12:22:08 -0700275 "$dir_pw_analog:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700276 "$dir_pw_assert:tests",
277 "$dir_pw_base64:tests",
David Rogers2d195022020-07-16 14:07:47 -0700278 "$dir_pw_blob_store:tests",
shaneajg9c19db42020-06-11 15:49:51 -0400279 "$dir_pw_bytes:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700280 "$dir_pw_checksum:tests",
Ewout van Bekkum3c61ae92020-10-30 15:52:25 -0700281 "$dir_pw_chrono:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700282 "$dir_pw_containers:tests",
Armando Montaneza9ca9992021-01-26 17:06:10 -0800283 "$dir_pw_cpu_exception_cortex_m:tests",
Ali Zhangef68dc62021-06-25 16:25:44 -0700284 "$dir_pw_crypto:tests",
Alexei Frolov99de52d2021-05-11 19:58:01 -0700285 "$dir_pw_function:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700286 "$dir_pw_fuzzer:tests",
Alexei Frolovd3e5cb72021-01-08 13:08:45 -0800287 "$dir_pw_hdlc:tests",
Armando Montanez593d0d52020-07-08 19:55:01 -0700288 "$dir_pw_hex_dump:tests",
Max Koopman84d599d2021-02-11 09:38:57 -0800289 "$dir_pw_i2c:tests",
Keir Mierle32829d32020-11-25 15:38:40 -0800290 "$dir_pw_libc:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700291 "$dir_pw_log:tests",
Wyatt Hepler24a6e272020-09-01 10:25:28 -0700292 "$dir_pw_log_null:tests",
Prashanth Swaminathanfce26ba2020-09-25 13:36:07 -0700293 "$dir_pw_log_rpc:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700294 "$dir_pw_log_tokenized:tests",
Chenghan Zhoud4f44d22020-06-18 15:42:06 -0400295 "$dir_pw_malloc_freelist:tests",
Keir Mierle45fa7852020-08-10 21:09:54 -0700296 "$dir_pw_metric:tests",
Prashanth Swaminathanf36832a2021-01-27 16:20:32 -0800297 "$dir_pw_multisink:tests",
Ewout van Bekkum32dc5c52021-03-16 11:35:37 -0700298 "$dir_pw_persistent_ram:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700299 "$dir_pw_polyfill:tests",
300 "$dir_pw_preprocessor:tests",
301 "$dir_pw_protobuf:tests",
302 "$dir_pw_protobuf_compiler:tests",
Armando Montanez47008e82020-08-04 11:04:45 -0700303 "$dir_pw_random:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700304 "$dir_pw_result:tests",
305 "$dir_pw_ring_buffer:tests",
Alexei Frolov5af57d12021-01-12 11:38:06 -0800306 "$dir_pw_router:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700307 "$dir_pw_rpc:tests",
Armando Montanez179aa8e2021-03-10 11:46:35 -0800308 "$dir_pw_snapshot:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700309 "$dir_pw_span:tests",
310 "$dir_pw_status:tests",
311 "$dir_pw_stream:tests",
312 "$dir_pw_string:tests",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800313 "$dir_pw_sync:tests",
Ewout van Bekkume3b56032020-12-22 12:00:18 -0800314 "$dir_pw_thread:tests",
Ewout van Bekkum0f3901e2020-12-22 12:00:18 -0800315 "$dir_pw_thread_stl:tests",
Yecheng Zhao79174152021-07-22 12:52:29 -0700316 "$dir_pw_tls_client:tests",
Yecheng Zhaoba9e06d2021-06-29 17:12:57 -0700317 "$dir_pw_tls_client_boringssl:tests",
Yecheng Zhao60465a72021-06-23 21:14:02 -0700318 "$dir_pw_tls_client_mbedtls:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700319 "$dir_pw_tokenizer:tests",
320 "$dir_pw_trace:tests",
Robert Oliver21dcf272020-05-12 15:41:52 -0400321 "$dir_pw_trace_tokenized:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700322 "$dir_pw_unit_test:tests",
323 "$dir_pw_varint:tests",
324 ]
325
Armando Montanez86003202020-06-16 18:00:06 -0700326 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
327 pw_toolchain_SCOPE.is_host_toolchain) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700328 # TODO(pwbug/196): KVS tests are not compatible with device builds as they
329 # use features such as std::map and are computationally expensive. Solving
330 # this requires a more complex capabilities-based build and configuration
331 # system which allowing enabling specific tests for targets that support
332 # them and modifying test parameters for different targets.
333 #
334 # Checking for pw_build_host_tools (which is only set by the host) is a
335 # temporary fix until the problem can be properly solved.
336 group_deps += [ "$dir_pw_kvs:tests" ]
Alexei Frolovf93cb262021-07-14 16:05:15 -0700337
338 if (host_os != "win") {
339 # TODO(pwbug/441): Fix transfer tests on Windows.
340 group_deps += [ "$dir_pw_transfer:tests" ]
341 }
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700342 }
343
344 if (host_os != "win") {
345 # TODO(amontanez): pw_minimal_cpp_stdlib tests do not build on windows.
346 group_deps += [ "$dir_pw_minimal_cpp_stdlib:tests" ]
347 }
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800348 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800349}