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 | |
Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 18 | import("$dir_pw_arduino_build/arduino.gni") |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 19 | import("$dir_pw_build/host_tool.gni") |
Alexei Frolov | 258fc1b | 2020-06-10 16:24:50 -0700 | [diff] [blame] | 20 | import("$dir_pw_docgen/docs.gni") |
Armando Montanez | 8600320 | 2020-06-16 18:00:06 -0700 | [diff] [blame] | 21 | import("$dir_pw_toolchain/generate_toolchain.gni") |
Armando Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 22 | import("$dir_pw_unit_test/test.gni") |
Alexei Frolov | 258fc1b | 2020-06-10 16:24:50 -0700 | [diff] [blame] | 23 | |
| 24 | # Main build file for upstream Pigweed. |
| 25 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 26 | declare_args() { |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 27 | # The default optimization level for building upstream Pigweed targets. |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 28 | # |
| 29 | # Choices: |
| 30 | # debug |
| 31 | # size_optimized |
| 32 | # speed_optimized |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 33 | pw_default_optimization_level = "debug" |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 34 | |
| 35 | # List of application image GN targets specific to the Pigweed target. |
| 36 | pw_TARGET_APPLICATIONS = [] |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 39 | # 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 Montanez | 04c56ae | 2019-12-12 14:34:05 -0800 | [diff] [blame] | 42 | group("default") { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 43 | deps = [ |
| 44 | ":docs", |
| 45 | ":host", |
Armando Montanez | 6f07fa7 | 2020-09-17 17:19:14 -0700 | [diff] [blame] | 46 | ":stm32f429i", |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 47 | ] |
| 48 | } |
| 49 | |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 50 | # This template generates a group that builds pigweed_default with a particular |
| 51 | # toolchain. |
| 52 | template("_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 Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 73 | # Below are a list of GN targets you can build to force Pigweed to build for a |
| 74 | # specific Pigweed target. |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 75 | _build_pigweed_default_at_all_optimization_levels("host") { |
| 76 | # Select a toolchain based on host OS. |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 77 | if (host_os == "linux") { |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 78 | toolchain_prefix = "$dir_pigweed/targets/host:host_clang_" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 79 | } else if (host_os == "mac") { |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 80 | toolchain_prefix = "$dir_pigweed/targets/host:host_clang_" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 81 | } else if (host_os == "win") { |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 82 | toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 83 | } else { |
| 84 | assert(false, "Please define a host config for your system: $host_os") |
| 85 | } |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 88 | _build_pigweed_default_at_all_optimization_levels("host_clang") { |
| 89 | toolchain_prefix = "$dir_pigweed/targets/host:host_clang_" |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 92 | _build_pigweed_default_at_all_optimization_levels("host_gcc") { |
| 93 | toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_" |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 96 | _build_pigweed_default_at_all_optimization_levels("stm32f429i") { |
| 97 | toolchain_prefix = "$dir_pigweed/targets/stm32f429i-disc1:stm32f429i_disc1_" |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 100 | if (dir_pw_third_party_arduino != "") { |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 101 | _build_pigweed_default_at_all_optimization_levels("arduino") { |
| 102 | toolchain_prefix = "$dir_pigweed/targets/arduino:arduino_" |
Anthony DiGirolamo | eea0d77 | 2020-08-06 12:00:36 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Wyatt Hepler | 38c398d | 2020-07-14 11:15:30 -0700 | [diff] [blame] | 106 | _build_pigweed_default_at_all_optimization_levels("qemu") { |
| 107 | toolchain_prefix = "$dir_pigweed/targets/lm3s6965evb-qemu:lm3s6965evb_qemu_" |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | group("docs") { |
| 111 | deps = [ ":pigweed_default($dir_pigweed/targets/docs)" ] |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | # By default, Pigweed will build this target when invoking ninja. |
| 115 | group("pigweed_default") { |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 116 | deps = [] |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 117 | |
| 118 | # Prevent the default toolchain from parsing any other BUILD.gn files. |
| 119 | if (current_toolchain != default_toolchain) { |
Alexei Frolov | 258fc1b | 2020-06-10 16:24:50 -0700 | [diff] [blame] | 120 | if (pw_docgen_BUILD_DOCS) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 121 | deps += [ "$dir_pigweed/docs" ] |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 122 | } else { |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 123 | deps += [ ":apps" ] |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 124 | 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 Montanez | 8600320 | 2020-06-16 18:00:06 -0700 | [diff] [blame] | 133 | if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| 134 | pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 135 | deps += [ ":host_tools" ] |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 136 | } |
Robert Oliver | 70b9264 | 2020-07-13 15:04:10 -0400 | [diff] [blame] | 137 | |
| 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 Oliver | 6d05de1 | 2020-07-13 15:10:42 -0400 | [diff] [blame] | 141 | deps += [ |
| 142 | "$dir_pw_trace:trace_example_basic", |
| 143 | "$dir_pw_trace_tokenized:trace_tokenized_example_basic", |
Robert Oliver | 0cc2075 | 2020-07-14 15:24:22 -0400 | [diff] [blame] | 144 | "$dir_pw_trace_tokenized:trace_tokenized_example_filter", |
Robert Oliver | 1914691 | 2020-07-14 10:49:48 -0400 | [diff] [blame] | 145 | "$dir_pw_trace_tokenized:trace_tokenized_example_trigger", |
Robert Oliver | 6d05de1 | 2020-07-13 15:10:42 -0400 | [diff] [blame] | 146 | ] |
Robert Oliver | 70b9264 | 2020-07-13 15:04:10 -0400 | [diff] [blame] | 147 | } |
Keir Mierle | e2f5d0f | 2019-12-16 11:36:22 -0800 | [diff] [blame] | 148 | } |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 151 | # Prevent the default toolchain from parsing any other BUILD.gn files. |
| 152 | if (current_toolchain != default_toolchain) { |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 153 | group("apps") { |
| 154 | # Application images built for all targets. |
Wyatt Hepler | b8db509 | 2020-09-17 10:36:41 -0700 | [diff] [blame] | 155 | deps = [ "$dir_pw_hdlc_lite/rpc_example" ] |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 156 | |
| 157 | # Add target-specific images. |
| 158 | deps += pw_TARGET_APPLICATIONS |
| 159 | } |
| 160 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 161 | group("host_tools") { |
| 162 | deps = [ |
| 163 | "$dir_pw_target_runner/go:simple_client", |
| 164 | "$dir_pw_target_runner/go:simple_server", |
Rob Mohr | 2156c0a | 2020-02-07 10:06:53 -0800 | [diff] [blame] | 165 | ] |
Alexei Frolov | 8c4b752 | 2020-01-31 11:15:57 -0800 | [diff] [blame] | 166 | } |
Alexei Frolov | 925fb8f | 2019-11-05 16:32:30 -0800 | [diff] [blame] | 167 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 168 | # 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 Rogers | 2d19502 | 2020-07-16 14:07:47 -0700 | [diff] [blame] | 174 | "$dir_pw_blob_store", |
shaneajg | 9c19db4 | 2020-06-11 15:49:51 -0400 | [diff] [blame] | 175 | "$dir_pw_bytes", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 176 | "$dir_pw_checksum", |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 177 | "$dir_pw_cpu_exception", |
shaneajg | 0869f2c | 2020-07-08 10:39:14 -0400 | [diff] [blame] | 178 | "$dir_pw_hdlc_lite", |
Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 179 | "$dir_pw_metric", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 180 | "$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 Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 188 | "$dir_pw_sys_io", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 189 | "$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 Montanez | 870a86b | 2020-05-26 10:54:38 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 206 | # 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 Rogers | 2d19502 | 2020-07-16 14:07:47 -0700 | [diff] [blame] | 212 | "$dir_pw_blob_store:tests", |
shaneajg | 9c19db4 | 2020-06-11 15:49:51 -0400 | [diff] [blame] | 213 | "$dir_pw_bytes:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 214 | "$dir_pw_checksum:tests", |
| 215 | "$dir_pw_containers:tests", |
| 216 | "$dir_pw_fuzzer:tests", |
shaneajg | e6d3a61 | 2020-07-23 18:40:28 -0400 | [diff] [blame] | 217 | "$dir_pw_hdlc_lite:tests", |
Armando Montanez | 593d0d5 | 2020-07-08 19:55:01 -0700 | [diff] [blame] | 218 | "$dir_pw_hex_dump:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 219 | "$dir_pw_log:tests", |
Wyatt Hepler | 24a6e27 | 2020-09-01 10:25:28 -0700 | [diff] [blame] | 220 | "$dir_pw_log_null:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 221 | "$dir_pw_log_tokenized:tests", |
Chenghan Zhou | d4f44d2 | 2020-06-18 15:42:06 -0400 | [diff] [blame] | 222 | "$dir_pw_malloc_freelist:tests", |
Keir Mierle | 45fa785 | 2020-08-10 21:09:54 -0700 | [diff] [blame] | 223 | "$dir_pw_metric:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 224 | "$dir_pw_polyfill:tests", |
| 225 | "$dir_pw_preprocessor:tests", |
| 226 | "$dir_pw_protobuf:tests", |
| 227 | "$dir_pw_protobuf_compiler:tests", |
Armando Montanez | 47008e8 | 2020-08-04 11:04:45 -0700 | [diff] [blame] | 228 | "$dir_pw_random:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 229 | "$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 Oliver | 21dcf27 | 2020-05-12 15:41:52 -0400 | [diff] [blame] | 238 | "$dir_pw_trace_tokenized:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 239 | "$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 Montanez | 356bf97 | 2020-06-04 10:35:55 -0700 | [diff] [blame] | 246 | if (pw_cpu_exception_ENTRY_BACKEND == dir_pw_cpu_exception_armv7m) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 247 | group_deps += [ "$dir_pw_cpu_exception_armv7m:tests" ] |
| 248 | } |
| 249 | |
Armando Montanez | 8600320 | 2020-06-16 18:00:06 -0700 | [diff] [blame] | 250 | if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| 251 | pw_toolchain_SCOPE.is_host_toolchain) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 252 | # 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 Frolov | 8c4b752 | 2020-01-31 11:15:57 -0800 | [diff] [blame] | 267 | } |
Alexei Frolov | 925fb8f | 2019-11-05 16:32:30 -0800 | [diff] [blame] | 268 | } |