Wyatt Hepler | 0412a7d | 2020-01-28 16:27:32 -0800 | [diff] [blame] | 1 | # Copyright 2020 The Pigweed Authors |
Alexei Frolov | 1a82c14 | 2019-10-31 17:37:12 -0700 | [diff] [blame] | 2 | # |
| 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 Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 15 | # gn-format disable |
| 16 | import("//build_overrides/pigweed.gni") |
Wyatt Hepler | edf6f29 | 2019-11-25 18:52:21 -0800 | [diff] [blame] | 17 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 18 | import("$dir_pw_build/host_tool.gni") |
Alexei Frolov | 258fc1b | 2020-06-10 16:24:50 -0700 | [diff] [blame] | 19 | import("$dir_pw_docgen/docs.gni") |
Armando Montanez | 8600320 | 2020-06-16 18:00:06 -0700 | [diff] [blame] | 20 | import("$dir_pw_toolchain/generate_toolchain.gni") |
Armando Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 21 | import("$dir_pw_unit_test/test.gni") |
Alexei Frolov | 258fc1b | 2020-06-10 16:24:50 -0700 | [diff] [blame] | 22 | |
| 23 | # Main build file for upstream Pigweed. |
| 24 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 25 | declare_args() { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 26 | # 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 Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 33 | |
| 34 | # List of application image GN targets specific to the Pigweed target. |
| 35 | pw_TARGET_APPLICATIONS = [] |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 38 | # 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 Montanez | 04c56ae | 2019-12-12 14:34:05 -0800 | [diff] [blame] | 41 | group("default") { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 42 | deps = [ |
| 43 | ":docs", |
| 44 | ":host", |
Armando Montanez | 6f07fa7 | 2020-09-17 17:19:14 -0700 | [diff] [blame^] | 45 | ":stm32f429i", |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 46 | ] |
| 47 | } |
| 48 | |
| 49 | # Below are a list of GN targets you can build to force Pigweed to build for a |
| 50 | # specific Pigweed target. |
| 51 | group("host") { |
| 52 | # Auto select a toolchain based on host OS. |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 53 | if (host_os == "linux") { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 54 | _default_host_toolchain = ":host_clang" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 55 | } else if (host_os == "mac") { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 56 | _default_host_toolchain = ":host_clang" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 57 | } else if (host_os == "win") { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 58 | _default_host_toolchain = ":host_gcc" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 59 | } else { |
| 60 | assert(false, "Please define a host config for your system: $host_os") |
| 61 | } |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 62 | |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 63 | deps = [ _default_host_toolchain ] |
| 64 | } |
| 65 | |
| 66 | group("host_clang") { |
| 67 | deps = [ ":pigweed_default($dir_pigweed/targets/host:host_clang_$pw_optimization_level)" ] |
| 68 | } |
| 69 | |
| 70 | group("host_gcc") { |
| 71 | deps = [ ":pigweed_default($dir_pigweed/targets/host:host_gcc_$pw_optimization_level)" ] |
| 72 | } |
| 73 | |
| 74 | group("stm32f429i") { |
| 75 | deps = [ ":pigweed_default($dir_pigweed/targets/stm32f429i-disc1:stm32f429i_disc1_$pw_optimization_level)" ] |
| 76 | } |
| 77 | |
| 78 | group("qemu") { |
| 79 | deps = [ ":pigweed_default($dir_pigweed/targets/lm3s6965evb-qemu:lm3s6965evb_qemu_$pw_optimization_level)" ] |
| 80 | } |
| 81 | |
| 82 | group("docs") { |
| 83 | deps = [ ":pigweed_default($dir_pigweed/targets/docs)" ] |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | # By default, Pigweed will build this target when invoking ninja. |
| 87 | group("pigweed_default") { |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 88 | deps = [] |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 89 | |
| 90 | # Prevent the default toolchain from parsing any other BUILD.gn files. |
| 91 | if (current_toolchain != default_toolchain) { |
Alexei Frolov | 258fc1b | 2020-06-10 16:24:50 -0700 | [diff] [blame] | 92 | if (pw_docgen_BUILD_DOCS) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 93 | deps += [ "$dir_pigweed/docs" ] |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 94 | } else { |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 95 | deps += [ ":apps" ] |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 96 | if (pw_unit_test_AUTOMATIC_RUNNER == "") { |
| 97 | # Without a test runner defined, build the tests but don't run them. |
| 98 | deps += [ ":pw_module_tests" ] |
| 99 | } else { |
| 100 | # With a test runner, depend on the run targets so they run with the |
| 101 | # build. |
| 102 | deps += [ ":pw_module_tests_run" ] |
| 103 | } |
| 104 | } |
Armando Montanez | 8600320 | 2020-06-16 18:00:06 -0700 | [diff] [blame] | 105 | if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| 106 | pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 107 | deps += [ ":host_tools" ] |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 108 | } |
Robert Oliver | 70b9264 | 2020-07-13 15:04:10 -0400 | [diff] [blame] | 109 | |
| 110 | # Trace examples currently only support running on non-windows host |
| 111 | if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| 112 | pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") { |
Robert Oliver | 6d05de1 | 2020-07-13 15:10:42 -0400 | [diff] [blame] | 113 | deps += [ |
| 114 | "$dir_pw_trace:trace_example_basic", |
| 115 | "$dir_pw_trace_tokenized:trace_tokenized_example_basic", |
Robert Oliver | 0cc2075 | 2020-07-14 15:24:22 -0400 | [diff] [blame] | 116 | "$dir_pw_trace_tokenized:trace_tokenized_example_filter", |
Robert Oliver | 1914691 | 2020-07-14 10:49:48 -0400 | [diff] [blame] | 117 | "$dir_pw_trace_tokenized:trace_tokenized_example_trigger", |
Robert Oliver | 6d05de1 | 2020-07-13 15:10:42 -0400 | [diff] [blame] | 118 | ] |
Robert Oliver | 70b9264 | 2020-07-13 15:04:10 -0400 | [diff] [blame] | 119 | } |
Keir Mierle | e2f5d0f | 2019-12-16 11:36:22 -0800 | [diff] [blame] | 120 | } |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 123 | # Prevent the default toolchain from parsing any other BUILD.gn files. |
| 124 | if (current_toolchain != default_toolchain) { |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 125 | group("apps") { |
| 126 | # Application images built for all targets. |
Wyatt Hepler | b8db509 | 2020-09-17 10:36:41 -0700 | [diff] [blame] | 127 | deps = [ "$dir_pw_hdlc_lite/rpc_example" ] |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 128 | |
| 129 | # Add target-specific images. |
| 130 | deps += pw_TARGET_APPLICATIONS |
| 131 | } |
| 132 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 133 | group("host_tools") { |
| 134 | deps = [ |
| 135 | "$dir_pw_target_runner/go:simple_client", |
| 136 | "$dir_pw_target_runner/go:simple_server", |
Rob Mohr | 2156c0a | 2020-02-07 10:06:53 -0800 | [diff] [blame] | 137 | ] |
Alexei Frolov | 8c4b752 | 2020-01-31 11:15:57 -0800 | [diff] [blame] | 138 | } |
Alexei Frolov | 925fb8f | 2019-11-05 16:32:30 -0800 | [diff] [blame] | 139 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 140 | # All Pigweed modules that can be built using gn. This is not built by default. |
| 141 | group("pw_modules") { |
| 142 | deps = [ |
| 143 | "$dir_pigweed/docs", |
| 144 | "$dir_pw_allocator", |
| 145 | "$dir_pw_base64", |
David Rogers | 2d19502 | 2020-07-16 14:07:47 -0700 | [diff] [blame] | 146 | "$dir_pw_blob_store", |
shaneajg | 9c19db4 | 2020-06-11 15:49:51 -0400 | [diff] [blame] | 147 | "$dir_pw_bytes", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 148 | "$dir_pw_checksum", |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 149 | "$dir_pw_cpu_exception", |
shaneajg | 0869f2c | 2020-07-08 10:39:14 -0400 | [diff] [blame] | 150 | "$dir_pw_hdlc_lite", |
Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 151 | "$dir_pw_metric", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 152 | "$dir_pw_polyfill", |
| 153 | "$dir_pw_preprocessor", |
| 154 | "$dir_pw_protobuf", |
| 155 | "$dir_pw_result", |
| 156 | "$dir_pw_span", |
| 157 | "$dir_pw_status", |
| 158 | "$dir_pw_stream", |
| 159 | "$dir_pw_string", |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 160 | "$dir_pw_sys_io", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 161 | "$dir_pw_trace", |
| 162 | "$dir_pw_unit_test", |
| 163 | "$dir_pw_varint", |
| 164 | ] |
| 165 | |
| 166 | if (host_os != "win") { |
| 167 | deps += [ |
| 168 | # TODO(frolv): Remove these two when new KVS is ready. |
| 169 | "$dir_pw_kvs", |
| 170 | "$dir_pw_minimal_cpp_stdlib", |
| 171 | |
| 172 | # TODO(pwbug/111): Remove this when building successfully on Windows. |
| 173 | "$dir_pw_tokenizer", |
| 174 | ] |
| 175 | } |
Armando Montanez | 870a86b | 2020-05-26 10:54:38 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 178 | # Targets for all module unit test groups. |
| 179 | pw_test_group("pw_module_tests") { |
| 180 | group_deps = [ |
| 181 | "$dir_pw_allocator:tests", |
| 182 | "$dir_pw_assert:tests", |
| 183 | "$dir_pw_base64:tests", |
David Rogers | 2d19502 | 2020-07-16 14:07:47 -0700 | [diff] [blame] | 184 | "$dir_pw_blob_store:tests", |
shaneajg | 9c19db4 | 2020-06-11 15:49:51 -0400 | [diff] [blame] | 185 | "$dir_pw_bytes:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 186 | "$dir_pw_checksum:tests", |
| 187 | "$dir_pw_containers:tests", |
| 188 | "$dir_pw_fuzzer:tests", |
shaneajg | e6d3a61 | 2020-07-23 18:40:28 -0400 | [diff] [blame] | 189 | "$dir_pw_hdlc_lite:tests", |
Armando Montanez | 593d0d5 | 2020-07-08 19:55:01 -0700 | [diff] [blame] | 190 | "$dir_pw_hex_dump:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 191 | "$dir_pw_log:tests", |
Wyatt Hepler | 24a6e27 | 2020-09-01 10:25:28 -0700 | [diff] [blame] | 192 | "$dir_pw_log_null:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 193 | "$dir_pw_log_tokenized:tests", |
Chenghan Zhou | d4f44d2 | 2020-06-18 15:42:06 -0400 | [diff] [blame] | 194 | "$dir_pw_malloc_freelist:tests", |
Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 195 | "$dir_pw_metric:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 196 | "$dir_pw_polyfill:tests", |
| 197 | "$dir_pw_preprocessor:tests", |
| 198 | "$dir_pw_protobuf:tests", |
| 199 | "$dir_pw_protobuf_compiler:tests", |
Armando Montanez | 47008e8 | 2020-08-04 11:04:45 -0700 | [diff] [blame] | 200 | "$dir_pw_random:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 201 | "$dir_pw_result:tests", |
| 202 | "$dir_pw_ring_buffer:tests", |
| 203 | "$dir_pw_rpc:tests", |
| 204 | "$dir_pw_span:tests", |
| 205 | "$dir_pw_status:tests", |
| 206 | "$dir_pw_stream:tests", |
| 207 | "$dir_pw_string:tests", |
| 208 | "$dir_pw_tokenizer:tests", |
| 209 | "$dir_pw_trace:tests", |
Robert Oliver | 21dcf27 | 2020-05-12 15:41:52 -0400 | [diff] [blame] | 210 | "$dir_pw_trace_tokenized:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 211 | "$dir_pw_unit_test:tests", |
| 212 | "$dir_pw_varint:tests", |
| 213 | ] |
| 214 | |
| 215 | import("$dir_pw_cpu_exception/backend.gni") |
| 216 | |
| 217 | # TODO(pwbug/17): Re-think when Pigweed config system is added. |
Armando Montanez | 356bf97 | 2020-06-04 10:35:55 -0700 | [diff] [blame] | 218 | if (pw_cpu_exception_ENTRY_BACKEND == dir_pw_cpu_exception_armv7m) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 219 | group_deps += [ "$dir_pw_cpu_exception_armv7m:tests" ] |
| 220 | } |
| 221 | |
Armando Montanez | 8600320 | 2020-06-16 18:00:06 -0700 | [diff] [blame] | 222 | if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| 223 | pw_toolchain_SCOPE.is_host_toolchain) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 224 | # TODO(pwbug/196): KVS tests are not compatible with device builds as they |
| 225 | # use features such as std::map and are computationally expensive. Solving |
| 226 | # this requires a more complex capabilities-based build and configuration |
| 227 | # system which allowing enabling specific tests for targets that support |
| 228 | # them and modifying test parameters for different targets. |
| 229 | # |
| 230 | # Checking for pw_build_host_tools (which is only set by the host) is a |
| 231 | # temporary fix until the problem can be properly solved. |
| 232 | group_deps += [ "$dir_pw_kvs:tests" ] |
| 233 | } |
| 234 | |
| 235 | if (host_os != "win") { |
| 236 | # TODO(amontanez): pw_minimal_cpp_stdlib tests do not build on windows. |
| 237 | group_deps += [ "$dir_pw_minimal_cpp_stdlib:tests" ] |
| 238 | } |
Alexei Frolov | 8c4b752 | 2020-01-31 11:15:57 -0800 | [diff] [blame] | 239 | } |
Alexei Frolov | 925fb8f | 2019-11-05 16:32:30 -0800 | [diff] [blame] | 240 | } |