blob: c72a3863ba849970fe2811205011a69d78d89c93 [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",
45 ":host",
Armando Montanez6f07fa72020-09-17 17:19:14 -070046 ":stm32f429i",
Armando Montanezebe27c62020-06-11 15:23:15 -070047 ]
48}
49
Wyatt Hepler38c398d2020-07-14 11:15:30 -070050# This template generates a group that builds pigweed_default with a particular
51# toolchain.
52template("_build_pigweed_default_at_all_optimization_levels") {
53 _toolchain_prefix = invoker.toolchain_prefix
54
55 group(target_name) {
56 deps = [
57 ":pigweed_default(${_toolchain_prefix}$pw_default_optimization_level)",
58 ]
59 }
60
61 foreach(optimization,
62 [
63 "debug",
64 "size_optimized",
65 "speed_optimized",
66 ]) {
67 group(target_name + "_$optimization") {
68 deps = [ ":pigweed_default($_toolchain_prefix$optimization)" ]
69 }
70 }
71}
72
Wyatt Heplerb16dfd32020-10-12 08:46:38 -070073# Select a default toolchain based on host OS.
74if (host_os == "linux") {
75 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
76} else if (host_os == "mac") {
77 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
78} else if (host_os == "win") {
79 _default_toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
80} else {
81 assert(false, "Please define a host config for your system: $host_os")
82}
83
Armando Montanezebe27c62020-06-11 15:23:15 -070084# Below are a list of GN targets you can build to force Pigweed to build for a
85# specific Pigweed target.
Wyatt Hepler38c398d2020-07-14 11:15:30 -070086_build_pigweed_default_at_all_optimization_levels("host") {
Wyatt Heplerb16dfd32020-10-12 08:46:38 -070087 toolchain_prefix = _default_toolchain_prefix
Armando Montanezebe27c62020-06-11 15:23:15 -070088}
89
Wyatt Hepler38c398d2020-07-14 11:15:30 -070090_build_pigweed_default_at_all_optimization_levels("host_clang") {
91 toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
Armando Montanezebe27c62020-06-11 15:23:15 -070092}
93
Wyatt Hepler38c398d2020-07-14 11:15:30 -070094_build_pigweed_default_at_all_optimization_levels("host_gcc") {
95 toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
Armando Montanezebe27c62020-06-11 15:23:15 -070096}
97
Wyatt Hepler38c398d2020-07-14 11:15:30 -070098_build_pigweed_default_at_all_optimization_levels("stm32f429i") {
99 toolchain_prefix = "$dir_pigweed/targets/stm32f429i-disc1:stm32f429i_disc1_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700100}
101
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -0700102if (dir_pw_third_party_arduino != "") {
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700103 _build_pigweed_default_at_all_optimization_levels("arduino") {
104 toolchain_prefix = "$dir_pigweed/targets/arduino:arduino_"
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -0700105 }
106}
107
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700108_build_pigweed_default_at_all_optimization_levels("qemu") {
109 toolchain_prefix = "$dir_pigweed/targets/lm3s6965evb-qemu:lm3s6965evb_qemu_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700110}
111
112group("docs") {
113 deps = [ ":pigweed_default($dir_pigweed/targets/docs)" ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700114}
115
Wyatt Heplerb16dfd32020-10-12 08:46:38 -0700116pw_python_group("python") {
Wyatt Hepler45af57b2020-10-23 08:05:28 -0700117 _python_gn_targets = [
118 # Python packages
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700119 "$dir_pw_allocator/py",
120 "$dir_pw_arduino_build/py",
Wyatt Hepler96992c72020-10-23 08:05:33 -0700121 "$dir_pw_bloat/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700122 "$dir_pw_build/py",
123 "$dir_pw_cli/py",
Wyatt Hepler96992c72020-10-23 08:05:33 -0700124 "$dir_pw_docgen/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700125 "$dir_pw_doctor/py",
126 "$dir_pw_env_setup/py",
127 "$dir_pw_hdlc_lite/py",
128 "$dir_pw_module/py",
Wyatt Hepler96992c72020-10-23 08:05:33 -0700129 "$dir_pw_package/py",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700130 "$dir_pw_presubmit/py",
131 "$dir_pw_protobuf_compiler/py",
132 "$dir_pw_protobuf/py",
133 "$dir_pw_rpc/py",
134 "$dir_pw_status/py",
135 "$dir_pw_tokenizer/py",
136 "$dir_pw_trace/py",
137 "$dir_pw_trace_tokenized/py",
138 "$dir_pw_unit_test/py",
139 "$dir_pw_watch/py",
140
Wyatt Hepler45af57b2020-10-23 08:05:28 -0700141 # Standalone scripts
142 "$dir_pw_hdlc_lite/rpc_example:example_script",
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700143 ]
144
Wyatt Hepler96992c72020-10-23 08:05:33 -0700145 _py_toolchain = "$_default_toolchain_prefix$pw_default_optimization_level"
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700146
147 python_deps = []
Wyatt Hepler45af57b2020-10-23 08:05:28 -0700148 foreach(dep, _python_gn_targets) {
Wyatt Hepler96992c72020-10-23 08:05:33 -0700149 python_deps += [ "$dep($_py_toolchain)" ]
Wyatt Hepler01a85d62020-10-22 08:32:13 -0700150 }
Wyatt Heplerb16dfd32020-10-12 08:46:38 -0700151}
152
Wyatt Hepler96992c72020-10-23 08:05:33 -0700153# Python packages for supporting specific targets.
154pw_python_group("target_support_packages") {
155 python_deps = [
156 "$dir_pigweed/targets/lm3s6965evb-qemu/py($dir_pigweed/targets/lm3s6965evb-qemu:lm3s6965evb_qemu_$pw_default_optimization_level)",
157 "$dir_pigweed/targets/stm32f429i-disc1/py($dir_pigweed/targets/stm32f429i-disc1:stm32f429i_disc1_$pw_default_optimization_level)",
158 ]
159}
160
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700161# By default, Pigweed will build this target when invoking ninja.
162group("pigweed_default") {
Alexei Frolov799be5d2020-01-09 15:54:39 -0800163 deps = []
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700164
165 # Prevent the default toolchain from parsing any other BUILD.gn files.
166 if (current_toolchain != default_toolchain) {
Alexei Frolov258fc1b2020-06-10 16:24:50 -0700167 if (pw_docgen_BUILD_DOCS) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700168 deps += [ "$dir_pigweed/docs" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -0800169 } else {
Wyatt Heplerb16dfd32020-10-12 08:46:38 -0700170 deps += [
171 ":apps",
172 ":python.lint",
173 ":python.tests",
Wyatt Hepler96992c72020-10-23 08:05:33 -0700174 ":target_support_packages.lint",
175 ":target_support_packages.tests",
Wyatt Heplerb16dfd32020-10-12 08:46:38 -0700176 ]
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700177 if (pw_unit_test_AUTOMATIC_RUNNER == "") {
178 # Without a test runner defined, build the tests but don't run them.
179 deps += [ ":pw_module_tests" ]
180 } else {
181 # With a test runner, depend on the run targets so they run with the
182 # build.
183 deps += [ ":pw_module_tests_run" ]
184 }
185 }
Armando Montanez86003202020-06-16 18:00:06 -0700186 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
187 pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700188 deps += [ ":host_tools" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -0800189 }
Robert Oliver70b92642020-07-13 15:04:10 -0400190
191 # Trace examples currently only support running on non-windows host
192 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
193 pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") {
Robert Oliver6d05de12020-07-13 15:10:42 -0400194 deps += [
195 "$dir_pw_trace:trace_example_basic",
196 "$dir_pw_trace_tokenized:trace_tokenized_example_basic",
Robert Oliver0cc20752020-07-14 15:24:22 -0400197 "$dir_pw_trace_tokenized:trace_tokenized_example_filter",
Robert Oliver19146912020-07-14 10:49:48 -0400198 "$dir_pw_trace_tokenized:trace_tokenized_example_trigger",
Robert Oliver6d05de12020-07-13 15:10:42 -0400199 ]
Robert Oliver70b92642020-07-13 15:04:10 -0400200 }
Keir Mierlee2f5d0f2019-12-16 11:36:22 -0800201 }
Alexei Frolovca9cf602019-12-26 13:00:03 -0800202}
203
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700204# Prevent the default toolchain from parsing any other BUILD.gn files.
205if (current_toolchain != default_toolchain) {
Alexei Frolovf6753902020-07-08 11:01:45 -0700206 group("apps") {
207 # Application images built for all targets.
Wyatt Heplerb8db5092020-09-17 10:36:41 -0700208 deps = [ "$dir_pw_hdlc_lite/rpc_example" ]
Alexei Frolovf6753902020-07-08 11:01:45 -0700209
210 # Add target-specific images.
211 deps += pw_TARGET_APPLICATIONS
212 }
213
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700214 group("host_tools") {
215 deps = [
216 "$dir_pw_target_runner/go:simple_client",
217 "$dir_pw_target_runner/go:simple_server",
Rob Mohr2156c0a2020-02-07 10:06:53 -0800218 ]
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800219 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800220
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700221 # All Pigweed modules that can be built using gn. This is not built by default.
222 group("pw_modules") {
223 deps = [
224 "$dir_pigweed/docs",
225 "$dir_pw_allocator",
226 "$dir_pw_base64",
David Rogers2d195022020-07-16 14:07:47 -0700227 "$dir_pw_blob_store",
shaneajg9c19db42020-06-11 15:49:51 -0400228 "$dir_pw_bytes",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700229 "$dir_pw_checksum",
Alexei Frolovf6753902020-07-08 11:01:45 -0700230 "$dir_pw_cpu_exception",
shaneajg0869f2c2020-07-08 10:39:14 -0400231 "$dir_pw_hdlc_lite",
Keir Mierle45fa7852020-08-10 21:09:54 -0700232 "$dir_pw_metric",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700233 "$dir_pw_polyfill",
234 "$dir_pw_preprocessor",
235 "$dir_pw_protobuf",
236 "$dir_pw_result",
237 "$dir_pw_span",
238 "$dir_pw_status",
239 "$dir_pw_stream",
240 "$dir_pw_string",
Alexei Frolovf6753902020-07-08 11:01:45 -0700241 "$dir_pw_sys_io",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700242 "$dir_pw_trace",
243 "$dir_pw_unit_test",
244 "$dir_pw_varint",
245 ]
246
247 if (host_os != "win") {
248 deps += [
249 # TODO(frolv): Remove these two when new KVS is ready.
250 "$dir_pw_kvs",
251 "$dir_pw_minimal_cpp_stdlib",
252
253 # TODO(pwbug/111): Remove this when building successfully on Windows.
254 "$dir_pw_tokenizer",
255 ]
256 }
Armando Montanez870a86b2020-05-26 10:54:38 -0700257 }
258
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700259 # Targets for all module unit test groups.
260 pw_test_group("pw_module_tests") {
261 group_deps = [
262 "$dir_pw_allocator:tests",
263 "$dir_pw_assert:tests",
264 "$dir_pw_base64:tests",
David Rogers2d195022020-07-16 14:07:47 -0700265 "$dir_pw_blob_store:tests",
shaneajg9c19db42020-06-11 15:49:51 -0400266 "$dir_pw_bytes:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700267 "$dir_pw_checksum:tests",
268 "$dir_pw_containers:tests",
269 "$dir_pw_fuzzer:tests",
shaneajge6d3a612020-07-23 18:40:28 -0400270 "$dir_pw_hdlc_lite:tests",
Armando Montanez593d0d52020-07-08 19:55:01 -0700271 "$dir_pw_hex_dump:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700272 "$dir_pw_log:tests",
Wyatt Hepler24a6e272020-09-01 10:25:28 -0700273 "$dir_pw_log_null:tests",
Prashanth Swaminathanfce26ba2020-09-25 13:36:07 -0700274 "$dir_pw_log_rpc:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700275 "$dir_pw_log_tokenized:tests",
Chenghan Zhoud4f44d22020-06-18 15:42:06 -0400276 "$dir_pw_malloc_freelist:tests",
Keir Mierle45fa7852020-08-10 21:09:54 -0700277 "$dir_pw_metric:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700278 "$dir_pw_polyfill:tests",
279 "$dir_pw_preprocessor:tests",
280 "$dir_pw_protobuf:tests",
281 "$dir_pw_protobuf_compiler:tests",
Armando Montanez47008e82020-08-04 11:04:45 -0700282 "$dir_pw_random:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700283 "$dir_pw_result:tests",
284 "$dir_pw_ring_buffer:tests",
285 "$dir_pw_rpc:tests",
286 "$dir_pw_span:tests",
287 "$dir_pw_status:tests",
288 "$dir_pw_stream:tests",
289 "$dir_pw_string:tests",
290 "$dir_pw_tokenizer:tests",
291 "$dir_pw_trace:tests",
Robert Oliver21dcf272020-05-12 15:41:52 -0400292 "$dir_pw_trace_tokenized:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700293 "$dir_pw_unit_test:tests",
294 "$dir_pw_varint:tests",
295 ]
296
297 import("$dir_pw_cpu_exception/backend.gni")
298
299 # TODO(pwbug/17): Re-think when Pigweed config system is added.
Armando Montanez356bf972020-06-04 10:35:55 -0700300 if (pw_cpu_exception_ENTRY_BACKEND == dir_pw_cpu_exception_armv7m) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700301 group_deps += [ "$dir_pw_cpu_exception_armv7m:tests" ]
302 }
303
Armando Montanez86003202020-06-16 18:00:06 -0700304 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
305 pw_toolchain_SCOPE.is_host_toolchain) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700306 # TODO(pwbug/196): KVS tests are not compatible with device builds as they
307 # use features such as std::map and are computationally expensive. Solving
308 # this requires a more complex capabilities-based build and configuration
309 # system which allowing enabling specific tests for targets that support
310 # them and modifying test parameters for different targets.
311 #
312 # Checking for pw_build_host_tools (which is only set by the host) is a
313 # temporary fix until the problem can be properly solved.
314 group_deps += [ "$dir_pw_kvs:tests" ]
315 }
316
317 if (host_os != "win") {
318 # TODO(amontanez): pw_minimal_cpp_stdlib tests do not build on windows.
319 group_deps += [ "$dir_pw_minimal_cpp_stdlib:tests" ]
320 }
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800321 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800322}