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