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", |
| 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. |
| 50 | group("host") { |
| 51 | # Auto select a toolchain based on host OS. |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 52 | if (host_os == "linux") { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 53 | _default_host_toolchain = ":host_clang" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 54 | } else if (host_os == "mac") { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 55 | _default_host_toolchain = ":host_clang" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 56 | } else if (host_os == "win") { |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 57 | _default_host_toolchain = ":host_gcc" |
Armando Montanez | 164624f | 2020-06-10 15:00:29 -0700 | [diff] [blame] | 58 | } else { |
| 59 | assert(false, "Please define a host config for your system: $host_os") |
| 60 | } |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 61 | |
Armando Montanez | ebe27c6 | 2020-06-11 15:23:15 -0700 | [diff] [blame] | 62 | deps = [ _default_host_toolchain ] |
| 63 | } |
| 64 | |
| 65 | group("host_clang") { |
| 66 | deps = [ ":pigweed_default($dir_pigweed/targets/host:host_clang_$pw_optimization_level)" ] |
| 67 | } |
| 68 | |
| 69 | group("host_gcc") { |
| 70 | deps = [ ":pigweed_default($dir_pigweed/targets/host:host_gcc_$pw_optimization_level)" ] |
| 71 | } |
| 72 | |
| 73 | group("stm32f429i") { |
| 74 | deps = [ ":pigweed_default($dir_pigweed/targets/stm32f429i-disc1:stm32f429i_disc1_$pw_optimization_level)" ] |
| 75 | } |
| 76 | |
| 77 | group("qemu") { |
| 78 | deps = [ ":pigweed_default($dir_pigweed/targets/lm3s6965evb-qemu:lm3s6965evb_qemu_$pw_optimization_level)" ] |
| 79 | } |
| 80 | |
| 81 | group("docs") { |
| 82 | deps = [ ":pigweed_default($dir_pigweed/targets/docs)" ] |
Alexei Frolov | 844ff0f | 2020-05-06 12:15:29 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | # By default, Pigweed will build this target when invoking ninja. |
| 86 | group("pigweed_default") { |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 87 | deps = [] |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 88 | |
| 89 | # Prevent the default toolchain from parsing any other BUILD.gn files. |
| 90 | if (current_toolchain != default_toolchain) { |
Alexei Frolov | 258fc1b | 2020-06-10 16:24:50 -0700 | [diff] [blame] | 91 | if (pw_docgen_BUILD_DOCS) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 92 | deps += [ "$dir_pigweed/docs" ] |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 93 | } else { |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 94 | deps += [ ":apps" ] |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 95 | 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 Montanez | 8600320 | 2020-06-16 18:00:06 -0700 | [diff] [blame] | 104 | if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| 105 | pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 106 | deps += [ ":host_tools" ] |
Alexei Frolov | 799be5d | 2020-01-09 15:54:39 -0800 | [diff] [blame] | 107 | } |
Keir Mierle | e2f5d0f | 2019-12-16 11:36:22 -0800 | [diff] [blame] | 108 | } |
Alexei Frolov | ca9cf60 | 2019-12-26 13:00:03 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 111 | # Prevent the default toolchain from parsing any other BUILD.gn files. |
| 112 | if (current_toolchain != default_toolchain) { |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 113 | group("apps") { |
| 114 | # Application images built for all targets. |
| 115 | deps = [] |
| 116 | |
| 117 | # Add target-specific images. |
| 118 | deps += pw_TARGET_APPLICATIONS |
| 119 | } |
| 120 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 121 | group("host_tools") { |
| 122 | deps = [ |
| 123 | "$dir_pw_target_runner/go:simple_client", |
| 124 | "$dir_pw_target_runner/go:simple_server", |
Rob Mohr | 2156c0a | 2020-02-07 10:06:53 -0800 | [diff] [blame] | 125 | ] |
Alexei Frolov | 8c4b752 | 2020-01-31 11:15:57 -0800 | [diff] [blame] | 126 | } |
Alexei Frolov | 925fb8f | 2019-11-05 16:32:30 -0800 | [diff] [blame] | 127 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 128 | # All Pigweed modules that can be built using gn. This is not built by default. |
| 129 | group("pw_modules") { |
| 130 | deps = [ |
| 131 | "$dir_pigweed/docs", |
| 132 | "$dir_pw_allocator", |
| 133 | "$dir_pw_base64", |
shaneajg | 9c19db4 | 2020-06-11 15:49:51 -0400 | [diff] [blame] | 134 | "$dir_pw_bytes", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 135 | "$dir_pw_checksum", |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 136 | "$dir_pw_cpu_exception", |
shaneajg | 0869f2c | 2020-07-08 10:39:14 -0400 | [diff] [blame] | 137 | "$dir_pw_hdlc_lite", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 138 | "$dir_pw_polyfill", |
| 139 | "$dir_pw_preprocessor", |
| 140 | "$dir_pw_protobuf", |
| 141 | "$dir_pw_result", |
| 142 | "$dir_pw_span", |
| 143 | "$dir_pw_status", |
| 144 | "$dir_pw_stream", |
| 145 | "$dir_pw_string", |
Alexei Frolov | f675390 | 2020-07-08 11:01:45 -0700 | [diff] [blame] | 146 | "$dir_pw_sys_io", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 147 | "$dir_pw_trace", |
| 148 | "$dir_pw_unit_test", |
| 149 | "$dir_pw_varint", |
| 150 | ] |
| 151 | |
| 152 | if (host_os != "win") { |
| 153 | deps += [ |
| 154 | # TODO(frolv): Remove these two when new KVS is ready. |
| 155 | "$dir_pw_kvs", |
| 156 | "$dir_pw_minimal_cpp_stdlib", |
| 157 | |
| 158 | # TODO(pwbug/111): Remove this when building successfully on Windows. |
| 159 | "$dir_pw_tokenizer", |
| 160 | ] |
| 161 | } |
Armando Montanez | 870a86b | 2020-05-26 10:54:38 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 164 | # Targets for all module unit test groups. |
| 165 | pw_test_group("pw_module_tests") { |
| 166 | group_deps = [ |
| 167 | "$dir_pw_allocator:tests", |
| 168 | "$dir_pw_assert:tests", |
| 169 | "$dir_pw_base64:tests", |
shaneajg | 9c19db4 | 2020-06-11 15:49:51 -0400 | [diff] [blame] | 170 | "$dir_pw_bytes:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 171 | "$dir_pw_checksum:tests", |
| 172 | "$dir_pw_containers:tests", |
| 173 | "$dir_pw_fuzzer:tests", |
Armando Montanez | 593d0d5 | 2020-07-08 19:55:01 -0700 | [diff] [blame] | 174 | "$dir_pw_hex_dump:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 175 | "$dir_pw_log:tests", |
| 176 | "$dir_pw_log_tokenized:tests", |
Chenghan Zhou | d4f44d2 | 2020-06-18 15:42:06 -0400 | [diff] [blame] | 177 | "$dir_pw_malloc_freelist:tests", |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 178 | "$dir_pw_polyfill:tests", |
| 179 | "$dir_pw_preprocessor:tests", |
| 180 | "$dir_pw_protobuf:tests", |
| 181 | "$dir_pw_protobuf_compiler:tests", |
| 182 | "$dir_pw_result:tests", |
| 183 | "$dir_pw_ring_buffer:tests", |
| 184 | "$dir_pw_rpc:tests", |
| 185 | "$dir_pw_span:tests", |
| 186 | "$dir_pw_status:tests", |
| 187 | "$dir_pw_stream:tests", |
| 188 | "$dir_pw_string:tests", |
| 189 | "$dir_pw_tokenizer:tests", |
| 190 | "$dir_pw_trace:tests", |
| 191 | "$dir_pw_unit_test:tests", |
| 192 | "$dir_pw_varint:tests", |
| 193 | ] |
| 194 | |
| 195 | import("$dir_pw_cpu_exception/backend.gni") |
| 196 | |
| 197 | # TODO(pwbug/17): Re-think when Pigweed config system is added. |
Armando Montanez | 356bf97 | 2020-06-04 10:35:55 -0700 | [diff] [blame] | 198 | if (pw_cpu_exception_ENTRY_BACKEND == dir_pw_cpu_exception_armv7m) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 199 | group_deps += [ "$dir_pw_cpu_exception_armv7m:tests" ] |
| 200 | } |
| 201 | |
Armando Montanez | 8600320 | 2020-06-16 18:00:06 -0700 | [diff] [blame] | 202 | if (defined(pw_toolchain_SCOPE.is_host_toolchain) && |
| 203 | pw_toolchain_SCOPE.is_host_toolchain) { |
Alexei Frolov | 4c0428a | 2020-06-10 10:46:04 -0700 | [diff] [blame] | 204 | # TODO(pwbug/196): KVS tests are not compatible with device builds as they |
| 205 | # use features such as std::map and are computationally expensive. Solving |
| 206 | # this requires a more complex capabilities-based build and configuration |
| 207 | # system which allowing enabling specific tests for targets that support |
| 208 | # them and modifying test parameters for different targets. |
| 209 | # |
| 210 | # Checking for pw_build_host_tools (which is only set by the host) is a |
| 211 | # temporary fix until the problem can be properly solved. |
| 212 | group_deps += [ "$dir_pw_kvs:tests" ] |
| 213 | } |
| 214 | |
| 215 | if (host_os != "win") { |
| 216 | # TODO(amontanez): pw_minimal_cpp_stdlib tests do not build on windows. |
| 217 | group_deps += [ "$dir_pw_minimal_cpp_stdlib:tests" ] |
| 218 | } |
Alexei Frolov | 8c4b752 | 2020-01-31 11:15:57 -0800 | [diff] [blame] | 219 | } |
Alexei Frolov | 925fb8f | 2019-11-05 16:32:30 -0800 | [diff] [blame] | 220 | } |