blob: 0733f923569c35d6d0a1cc0224127d47bce0a129 [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 -070015# gn-format disable
16import("//build_overrides/pigweed.gni")
Wyatt Hepleredf6f292019-11-25 18:52:21 -080017
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -070018import("$dir_pw_arduino_build/arduino.gni")
Alexei Frolov4c0428a2020-06-10 10:46:04 -070019import("$dir_pw_build/host_tool.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
Armando Montanezebe27c62020-06-11 15:23:15 -070073# Below are a list of GN targets you can build to force Pigweed to build for a
74# specific Pigweed target.
Wyatt Hepler38c398d2020-07-14 11:15:30 -070075_build_pigweed_default_at_all_optimization_levels("host") {
76 # Select a toolchain based on host OS.
Armando Montanez164624f2020-06-10 15:00:29 -070077 if (host_os == "linux") {
Wyatt Hepler38c398d2020-07-14 11:15:30 -070078 toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
Armando Montanez164624f2020-06-10 15:00:29 -070079 } else if (host_os == "mac") {
Wyatt Hepler38c398d2020-07-14 11:15:30 -070080 toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
Armando Montanez164624f2020-06-10 15:00:29 -070081 } else if (host_os == "win") {
Wyatt Hepler38c398d2020-07-14 11:15:30 -070082 toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
Armando Montanez164624f2020-06-10 15:00:29 -070083 } else {
84 assert(false, "Please define a host config for your system: $host_os")
85 }
Armando Montanezebe27c62020-06-11 15:23:15 -070086}
87
Wyatt Hepler38c398d2020-07-14 11:15:30 -070088_build_pigweed_default_at_all_optimization_levels("host_clang") {
89 toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
Armando Montanezebe27c62020-06-11 15:23:15 -070090}
91
Wyatt Hepler38c398d2020-07-14 11:15:30 -070092_build_pigweed_default_at_all_optimization_levels("host_gcc") {
93 toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
Armando Montanezebe27c62020-06-11 15:23:15 -070094}
95
Wyatt Hepler38c398d2020-07-14 11:15:30 -070096_build_pigweed_default_at_all_optimization_levels("stm32f429i") {
97 toolchain_prefix = "$dir_pigweed/targets/stm32f429i-disc1:stm32f429i_disc1_"
Armando Montanezebe27c62020-06-11 15:23:15 -070098}
99
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -0700100if (dir_pw_third_party_arduino != "") {
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700101 _build_pigweed_default_at_all_optimization_levels("arduino") {
102 toolchain_prefix = "$dir_pigweed/targets/arduino:arduino_"
Anthony DiGirolamoeea0d772020-08-06 12:00:36 -0700103 }
104}
105
Wyatt Hepler38c398d2020-07-14 11:15:30 -0700106_build_pigweed_default_at_all_optimization_levels("qemu") {
107 toolchain_prefix = "$dir_pigweed/targets/lm3s6965evb-qemu:lm3s6965evb_qemu_"
Armando Montanezebe27c62020-06-11 15:23:15 -0700108}
109
110group("docs") {
111 deps = [ ":pigweed_default($dir_pigweed/targets/docs)" ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -0700112}
113
114# By default, Pigweed will build this target when invoking ninja.
115group("pigweed_default") {
Alexei Frolov799be5d2020-01-09 15:54:39 -0800116 deps = []
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700117
118 # Prevent the default toolchain from parsing any other BUILD.gn files.
119 if (current_toolchain != default_toolchain) {
Alexei Frolov258fc1b2020-06-10 16:24:50 -0700120 if (pw_docgen_BUILD_DOCS) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700121 deps += [ "$dir_pigweed/docs" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -0800122 } else {
Alexei Frolovf6753902020-07-08 11:01:45 -0700123 deps += [ ":apps" ]
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700124 if (pw_unit_test_AUTOMATIC_RUNNER == "") {
125 # Without a test runner defined, build the tests but don't run them.
126 deps += [ ":pw_module_tests" ]
127 } else {
128 # With a test runner, depend on the run targets so they run with the
129 # build.
130 deps += [ ":pw_module_tests_run" ]
131 }
132 }
Armando Montanez86003202020-06-16 18:00:06 -0700133 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
134 pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700135 deps += [ ":host_tools" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -0800136 }
Robert Oliver70b92642020-07-13 15:04:10 -0400137
138 # Trace examples currently only support running on non-windows host
139 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
140 pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") {
Robert Oliver6d05de12020-07-13 15:10:42 -0400141 deps += [
142 "$dir_pw_trace:trace_example_basic",
143 "$dir_pw_trace_tokenized:trace_tokenized_example_basic",
Robert Oliver0cc20752020-07-14 15:24:22 -0400144 "$dir_pw_trace_tokenized:trace_tokenized_example_filter",
Robert Oliver19146912020-07-14 10:49:48 -0400145 "$dir_pw_trace_tokenized:trace_tokenized_example_trigger",
Robert Oliver6d05de12020-07-13 15:10:42 -0400146 ]
Robert Oliver70b92642020-07-13 15:04:10 -0400147 }
Keir Mierlee2f5d0f2019-12-16 11:36:22 -0800148 }
Alexei Frolovca9cf602019-12-26 13:00:03 -0800149}
150
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700151# Prevent the default toolchain from parsing any other BUILD.gn files.
152if (current_toolchain != default_toolchain) {
Alexei Frolovf6753902020-07-08 11:01:45 -0700153 group("apps") {
154 # Application images built for all targets.
Wyatt Heplerb8db5092020-09-17 10:36:41 -0700155 deps = [ "$dir_pw_hdlc_lite/rpc_example" ]
Alexei Frolovf6753902020-07-08 11:01:45 -0700156
157 # Add target-specific images.
158 deps += pw_TARGET_APPLICATIONS
159 }
160
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700161 group("host_tools") {
162 deps = [
163 "$dir_pw_target_runner/go:simple_client",
164 "$dir_pw_target_runner/go:simple_server",
Rob Mohr2156c0a2020-02-07 10:06:53 -0800165 ]
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800166 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800167
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700168 # All Pigweed modules that can be built using gn. This is not built by default.
169 group("pw_modules") {
170 deps = [
171 "$dir_pigweed/docs",
172 "$dir_pw_allocator",
173 "$dir_pw_base64",
David Rogers2d195022020-07-16 14:07:47 -0700174 "$dir_pw_blob_store",
shaneajg9c19db42020-06-11 15:49:51 -0400175 "$dir_pw_bytes",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700176 "$dir_pw_checksum",
Alexei Frolovf6753902020-07-08 11:01:45 -0700177 "$dir_pw_cpu_exception",
shaneajg0869f2c2020-07-08 10:39:14 -0400178 "$dir_pw_hdlc_lite",
Keir Mierle45fa7852020-08-10 21:09:54 -0700179 "$dir_pw_metric",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700180 "$dir_pw_polyfill",
181 "$dir_pw_preprocessor",
182 "$dir_pw_protobuf",
183 "$dir_pw_result",
184 "$dir_pw_span",
185 "$dir_pw_status",
186 "$dir_pw_stream",
187 "$dir_pw_string",
Alexei Frolovf6753902020-07-08 11:01:45 -0700188 "$dir_pw_sys_io",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700189 "$dir_pw_trace",
190 "$dir_pw_unit_test",
191 "$dir_pw_varint",
192 ]
193
194 if (host_os != "win") {
195 deps += [
196 # TODO(frolv): Remove these two when new KVS is ready.
197 "$dir_pw_kvs",
198 "$dir_pw_minimal_cpp_stdlib",
199
200 # TODO(pwbug/111): Remove this when building successfully on Windows.
201 "$dir_pw_tokenizer",
202 ]
203 }
Armando Montanez870a86b2020-05-26 10:54:38 -0700204 }
205
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700206 # Targets for all module unit test groups.
207 pw_test_group("pw_module_tests") {
208 group_deps = [
209 "$dir_pw_allocator:tests",
210 "$dir_pw_assert:tests",
211 "$dir_pw_base64:tests",
David Rogers2d195022020-07-16 14:07:47 -0700212 "$dir_pw_blob_store:tests",
shaneajg9c19db42020-06-11 15:49:51 -0400213 "$dir_pw_bytes:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700214 "$dir_pw_checksum:tests",
215 "$dir_pw_containers:tests",
216 "$dir_pw_fuzzer:tests",
shaneajge6d3a612020-07-23 18:40:28 -0400217 "$dir_pw_hdlc_lite:tests",
Armando Montanez593d0d52020-07-08 19:55:01 -0700218 "$dir_pw_hex_dump:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700219 "$dir_pw_log:tests",
Wyatt Hepler24a6e272020-09-01 10:25:28 -0700220 "$dir_pw_log_null:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700221 "$dir_pw_log_tokenized:tests",
Chenghan Zhoud4f44d22020-06-18 15:42:06 -0400222 "$dir_pw_malloc_freelist:tests",
Keir Mierle45fa7852020-08-10 21:09:54 -0700223 "$dir_pw_metric:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700224 "$dir_pw_polyfill:tests",
225 "$dir_pw_preprocessor:tests",
226 "$dir_pw_protobuf:tests",
227 "$dir_pw_protobuf_compiler:tests",
Armando Montanez47008e82020-08-04 11:04:45 -0700228 "$dir_pw_random:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700229 "$dir_pw_result:tests",
230 "$dir_pw_ring_buffer:tests",
231 "$dir_pw_rpc:tests",
232 "$dir_pw_span:tests",
233 "$dir_pw_status:tests",
234 "$dir_pw_stream:tests",
235 "$dir_pw_string:tests",
236 "$dir_pw_tokenizer:tests",
237 "$dir_pw_trace:tests",
Robert Oliver21dcf272020-05-12 15:41:52 -0400238 "$dir_pw_trace_tokenized:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700239 "$dir_pw_unit_test:tests",
240 "$dir_pw_varint:tests",
241 ]
242
243 import("$dir_pw_cpu_exception/backend.gni")
244
245 # TODO(pwbug/17): Re-think when Pigweed config system is added.
Armando Montanez356bf972020-06-04 10:35:55 -0700246 if (pw_cpu_exception_ENTRY_BACKEND == dir_pw_cpu_exception_armv7m) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700247 group_deps += [ "$dir_pw_cpu_exception_armv7m:tests" ]
248 }
249
Armando Montanez86003202020-06-16 18:00:06 -0700250 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
251 pw_toolchain_SCOPE.is_host_toolchain) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700252 # TODO(pwbug/196): KVS tests are not compatible with device builds as they
253 # use features such as std::map and are computationally expensive. Solving
254 # this requires a more complex capabilities-based build and configuration
255 # system which allowing enabling specific tests for targets that support
256 # them and modifying test parameters for different targets.
257 #
258 # Checking for pw_build_host_tools (which is only set by the host) is a
259 # temporary fix until the problem can be properly solved.
260 group_deps += [ "$dir_pw_kvs:tests" ]
261 }
262
263 if (host_os != "win") {
264 # TODO(amontanez): pw_minimal_cpp_stdlib tests do not build on windows.
265 group_deps += [ "$dir_pw_minimal_cpp_stdlib:tests" ]
266 }
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800267 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800268}