blob: 86481bc153d8d77975cdc6fd6f530f4532461e64 [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
Alexei Frolov4c0428a2020-06-10 10:46:04 -070018import("$dir_pw_build/host_tool.gni")
Alexei Frolov258fc1b2020-06-10 16:24:50 -070019import("$dir_pw_docgen/docs.gni")
Armando Montanez86003202020-06-16 18:00:06 -070020import("$dir_pw_toolchain/generate_toolchain.gni")
Armando Montanezfb3d3fb2020-06-09 18:12:12 -070021import("$dir_pw_unit_test/test.gni")
Alexei Frolov258fc1b2020-06-10 16:24:50 -070022
23# Main build file for upstream Pigweed.
24
Alexei Frolov4c0428a2020-06-10 10:46:04 -070025declare_args() {
Armando Montanezebe27c62020-06-11 15:23:15 -070026 # The optimization level to use when building upstream Pigweed targets.
27 #
28 # Choices:
29 # debug
30 # size_optimized
31 # speed_optimized
32 pw_optimization_level = "debug"
Alexei Frolovf6753902020-07-08 11:01:45 -070033
34 # List of application image GN targets specific to the Pigweed target.
35 pw_TARGET_APPLICATIONS = []
Alexei Frolov4c0428a2020-06-10 10:46:04 -070036}
37
Armando Montanezebe27c62020-06-11 15:23:15 -070038# Enumerate all of the different targets that upstream Pigweed will build by
39# default. Downstream projects should not depend on this target; this target is
40# exclusively to facilitate easy upstream development and testing.
Armando Montanez04c56ae2019-12-12 14:34:05 -080041group("default") {
Armando Montanezebe27c62020-06-11 15:23:15 -070042 deps = [
43 ":docs",
44 ":host",
45 ]
46}
47
48# Below are a list of GN targets you can build to force Pigweed to build for a
49# specific Pigweed target.
50group("host") {
51 # Auto select a toolchain based on host OS.
Armando Montanez164624f2020-06-10 15:00:29 -070052 if (host_os == "linux") {
Armando Montanezebe27c62020-06-11 15:23:15 -070053 _default_host_toolchain = ":host_clang"
Armando Montanez164624f2020-06-10 15:00:29 -070054 } else if (host_os == "mac") {
Armando Montanezebe27c62020-06-11 15:23:15 -070055 _default_host_toolchain = ":host_clang"
Armando Montanez164624f2020-06-10 15:00:29 -070056 } else if (host_os == "win") {
Armando Montanezebe27c62020-06-11 15:23:15 -070057 _default_host_toolchain = ":host_gcc"
Armando Montanez164624f2020-06-10 15:00:29 -070058 } else {
59 assert(false, "Please define a host config for your system: $host_os")
60 }
Alexei Frolov4c0428a2020-06-10 10:46:04 -070061
Armando Montanezebe27c62020-06-11 15:23:15 -070062 deps = [ _default_host_toolchain ]
63}
64
65group("host_clang") {
66 deps = [ ":pigweed_default($dir_pigweed/targets/host:host_clang_$pw_optimization_level)" ]
67}
68
69group("host_gcc") {
70 deps = [ ":pigweed_default($dir_pigweed/targets/host:host_gcc_$pw_optimization_level)" ]
71}
72
73group("stm32f429i") {
74 deps = [ ":pigweed_default($dir_pigweed/targets/stm32f429i-disc1:stm32f429i_disc1_$pw_optimization_level)" ]
75}
76
77group("qemu") {
78 deps = [ ":pigweed_default($dir_pigweed/targets/lm3s6965evb-qemu:lm3s6965evb_qemu_$pw_optimization_level)" ]
79}
80
81group("docs") {
82 deps = [ ":pigweed_default($dir_pigweed/targets/docs)" ]
Alexei Frolov844ff0f2020-05-06 12:15:29 -070083}
84
85# By default, Pigweed will build this target when invoking ninja.
86group("pigweed_default") {
Alexei Frolov799be5d2020-01-09 15:54:39 -080087 deps = []
Alexei Frolov4c0428a2020-06-10 10:46:04 -070088
89 # Prevent the default toolchain from parsing any other BUILD.gn files.
90 if (current_toolchain != default_toolchain) {
Alexei Frolov258fc1b2020-06-10 16:24:50 -070091 if (pw_docgen_BUILD_DOCS) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -070092 deps += [ "$dir_pigweed/docs" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -080093 } else {
Alexei Frolovf6753902020-07-08 11:01:45 -070094 deps += [ ":apps" ]
Alexei Frolov4c0428a2020-06-10 10:46:04 -070095 if (pw_unit_test_AUTOMATIC_RUNNER == "") {
96 # Without a test runner defined, build the tests but don't run them.
97 deps += [ ":pw_module_tests" ]
98 } else {
99 # With a test runner, depend on the run targets so they run with the
100 # build.
101 deps += [ ":pw_module_tests_run" ]
102 }
103 }
Armando Montanez86003202020-06-16 18:00:06 -0700104 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
105 pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700106 deps += [ ":host_tools" ]
Alexei Frolov799be5d2020-01-09 15:54:39 -0800107 }
Robert Oliver70b92642020-07-13 15:04:10 -0400108
109 # Trace examples currently only support running on non-windows host
110 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
111 pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") {
Robert Oliver6d05de12020-07-13 15:10:42 -0400112 deps += [
113 "$dir_pw_trace:trace_example_basic",
114 "$dir_pw_trace_tokenized:trace_tokenized_example_basic",
Robert Oliver0cc20752020-07-14 15:24:22 -0400115 "$dir_pw_trace_tokenized:trace_tokenized_example_filter",
Robert Oliver19146912020-07-14 10:49:48 -0400116 "$dir_pw_trace_tokenized:trace_tokenized_example_trigger",
Robert Oliver6d05de12020-07-13 15:10:42 -0400117 ]
Robert Oliver70b92642020-07-13 15:04:10 -0400118 }
Keir Mierlee2f5d0f2019-12-16 11:36:22 -0800119 }
Alexei Frolovca9cf602019-12-26 13:00:03 -0800120}
121
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700122# Prevent the default toolchain from parsing any other BUILD.gn files.
123if (current_toolchain != default_toolchain) {
Alexei Frolovf6753902020-07-08 11:01:45 -0700124 group("apps") {
125 # Application images built for all targets.
126 deps = []
127
128 # Add target-specific images.
129 deps += pw_TARGET_APPLICATIONS
130 }
131
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700132 group("host_tools") {
133 deps = [
134 "$dir_pw_target_runner/go:simple_client",
135 "$dir_pw_target_runner/go:simple_server",
Rob Mohr2156c0a2020-02-07 10:06:53 -0800136 ]
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800137 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800138
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700139 # All Pigweed modules that can be built using gn. This is not built by default.
140 group("pw_modules") {
141 deps = [
142 "$dir_pigweed/docs",
143 "$dir_pw_allocator",
144 "$dir_pw_base64",
David Rogers2d195022020-07-16 14:07:47 -0700145 "$dir_pw_blob_store",
shaneajg9c19db42020-06-11 15:49:51 -0400146 "$dir_pw_bytes",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700147 "$dir_pw_checksum",
Alexei Frolovf6753902020-07-08 11:01:45 -0700148 "$dir_pw_cpu_exception",
shaneajg0869f2c2020-07-08 10:39:14 -0400149 "$dir_pw_hdlc_lite",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700150 "$dir_pw_polyfill",
151 "$dir_pw_preprocessor",
152 "$dir_pw_protobuf",
153 "$dir_pw_result",
154 "$dir_pw_span",
155 "$dir_pw_status",
156 "$dir_pw_stream",
157 "$dir_pw_string",
Alexei Frolovf6753902020-07-08 11:01:45 -0700158 "$dir_pw_sys_io",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700159 "$dir_pw_trace",
160 "$dir_pw_unit_test",
161 "$dir_pw_varint",
162 ]
163
164 if (host_os != "win") {
165 deps += [
166 # TODO(frolv): Remove these two when new KVS is ready.
167 "$dir_pw_kvs",
168 "$dir_pw_minimal_cpp_stdlib",
169
170 # TODO(pwbug/111): Remove this when building successfully on Windows.
171 "$dir_pw_tokenizer",
172 ]
173 }
Armando Montanez870a86b2020-05-26 10:54:38 -0700174 }
175
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700176 # Targets for all module unit test groups.
177 pw_test_group("pw_module_tests") {
178 group_deps = [
179 "$dir_pw_allocator:tests",
180 "$dir_pw_assert:tests",
181 "$dir_pw_base64:tests",
David Rogers2d195022020-07-16 14:07:47 -0700182 "$dir_pw_blob_store:tests",
shaneajg9c19db42020-06-11 15:49:51 -0400183 "$dir_pw_bytes:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700184 "$dir_pw_checksum:tests",
185 "$dir_pw_containers:tests",
186 "$dir_pw_fuzzer:tests",
Armando Montanez593d0d52020-07-08 19:55:01 -0700187 "$dir_pw_hex_dump:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700188 "$dir_pw_log:tests",
189 "$dir_pw_log_tokenized:tests",
Chenghan Zhoud4f44d22020-06-18 15:42:06 -0400190 "$dir_pw_malloc_freelist:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700191 "$dir_pw_polyfill:tests",
192 "$dir_pw_preprocessor:tests",
193 "$dir_pw_protobuf:tests",
194 "$dir_pw_protobuf_compiler:tests",
195 "$dir_pw_result:tests",
196 "$dir_pw_ring_buffer:tests",
197 "$dir_pw_rpc:tests",
198 "$dir_pw_span:tests",
199 "$dir_pw_status:tests",
200 "$dir_pw_stream:tests",
201 "$dir_pw_string:tests",
202 "$dir_pw_tokenizer:tests",
203 "$dir_pw_trace:tests",
Robert Oliver21dcf272020-05-12 15:41:52 -0400204 "$dir_pw_trace_tokenized:tests",
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700205 "$dir_pw_unit_test:tests",
206 "$dir_pw_varint:tests",
207 ]
208
209 import("$dir_pw_cpu_exception/backend.gni")
210
211 # TODO(pwbug/17): Re-think when Pigweed config system is added.
Armando Montanez356bf972020-06-04 10:35:55 -0700212 if (pw_cpu_exception_ENTRY_BACKEND == dir_pw_cpu_exception_armv7m) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700213 group_deps += [ "$dir_pw_cpu_exception_armv7m:tests" ]
214 }
215
Armando Montanez86003202020-06-16 18:00:06 -0700216 if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
217 pw_toolchain_SCOPE.is_host_toolchain) {
Alexei Frolov4c0428a2020-06-10 10:46:04 -0700218 # TODO(pwbug/196): KVS tests are not compatible with device builds as they
219 # use features such as std::map and are computationally expensive. Solving
220 # this requires a more complex capabilities-based build and configuration
221 # system which allowing enabling specific tests for targets that support
222 # them and modifying test parameters for different targets.
223 #
224 # Checking for pw_build_host_tools (which is only set by the host) is a
225 # temporary fix until the problem can be properly solved.
226 group_deps += [ "$dir_pw_kvs:tests" ]
227 }
228
229 if (host_os != "win") {
230 # TODO(amontanez): pw_minimal_cpp_stdlib tests do not build on windows.
231 group_deps += [ "$dir_pw_minimal_cpp_stdlib:tests" ]
232 }
Alexei Frolov8c4b7522020-01-31 11:15:57 -0800233 }
Alexei Frolov925fb8f2019-11-05 16:32:30 -0800234}