aboutsummaryrefslogtreecommitdiff
path: root/BUILD.gn
blob: 87df100d214af0b526be00cc74e7bfb8532d5fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

import("//build_overrides/pigweed.gni")

import("$dir_pw_arduino_build/arduino.gni")
import("$dir_pw_build/host_tool.gni")
import("$dir_pw_build/python.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_toolchain/generate_toolchain.gni")
import("$dir_pw_unit_test/test.gni")

# Main build file for upstream Pigweed.

declare_args() {
  # The default optimization level for building upstream Pigweed targets.
  #
  # Choices:
  #   debug
  #   size_optimized
  #   speed_optimized
  pw_default_optimization_level = "debug"

  # List of application image GN targets specific to the Pigweed target.
  pw_TARGET_APPLICATIONS = []

  # Whether to run integration tests, which may involve multiple processes
  # communicating over a socket.
  pw_RUN_INTEGRATION_TESTS = host_os == "linux"
}

# Enumerate all of the different targets that upstream Pigweed will build by
# default. Downstream projects should not depend on this target; this target is
# exclusively to facilitate easy upstream development and testing.
group("default") {
  deps = [
    ":docs",
    ":host",
    ":integration_tests",
    ":static_analysis",
    ":stm32f429i",
    "$dir_pw_env_setup:python.lint",
    "$dir_pw_env_setup:python.tests",
  ]
}

# This template generates a group that builds pigweed_default with a particular
# toolchain.
template("_build_pigweed_default_at_all_optimization_levels") {
  _toolchain_prefix = invoker.toolchain_prefix

  group(target_name) {
    deps = [
      ":pigweed_default(${_toolchain_prefix}$pw_default_optimization_level)",
    ]
  }

  foreach(optimization,
          [
            "debug",
            "size_optimized",
            "speed_optimized",
          ]) {
    group(target_name + "_$optimization") {
      deps = [ ":pigweed_default($_toolchain_prefix$optimization)" ]
    }
  }
}

# Select a default toolchain based on host OS.
if (host_os == "linux") {
  _default_toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
} else if (host_os == "mac") {
  _default_toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
} else if (host_os == "win") {
  _default_toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
} else {
  assert(false, "Please define a host config for your system: $host_os")
}

# Below are a list of GN targets you can build to force Pigweed to build for a
# specific Pigweed target.
_build_pigweed_default_at_all_optimization_levels("host") {
  toolchain_prefix = _default_toolchain_prefix
}

_build_pigweed_default_at_all_optimization_levels("host_clang") {
  toolchain_prefix = "$dir_pigweed/targets/host:host_clang_"
}

_build_pigweed_default_at_all_optimization_levels("host_gcc") {
  toolchain_prefix = "$dir_pigweed/targets/host:host_gcc_"
}

_build_pigweed_default_at_all_optimization_levels("stm32f429i") {
  toolchain_prefix = "$dir_pigweed/targets/stm32f429i_disc1:stm32f429i_disc1_"
}

if (pw_arduino_build_CORE_PATH != "") {
  _build_pigweed_default_at_all_optimization_levels("arduino") {
    toolchain_prefix = "$dir_pigweed/targets/arduino:arduino_"
  }
}

_build_pigweed_default_at_all_optimization_levels("qemu_gcc") {
  toolchain_prefix =
      "$dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_gcc_"
}

_build_pigweed_default_at_all_optimization_levels("qemu_clang") {
  toolchain_prefix =
      "$dir_pigweed/targets/lm3s6965evb_qemu:lm3s6965evb_qemu_clang_"
}

# Run clang-tidy on pigweed_default with host_clang_debug toolchain options.
# Make sure to invoke gn clean out when any relevant .clang-tidy
# file is updated.
group("static_analysis") {
  _toolchain = "$dir_pigweed/targets/host:host_clang_debug"
  deps = [ ":pigweed_default($_toolchain.static_analysis)" ]
}

group("docs") {
  deps = [ "$dir_pigweed/docs($dir_pigweed/targets/docs)" ]
}

# Tests larger than unit tests, typically run in a specific configuration. Only
# added if pw_RUN_INTEGRATION_TESTS is true.
group("integration_tests") {
  if (pw_RUN_INTEGRATION_TESTS) {
    _default_tc = _default_toolchain_prefix + pw_default_optimization_level
    deps = [
      "$dir_pw_rpc:cpp_client_server_integration_test($_default_tc)",
      "$dir_pw_rpc/py:python_client_cpp_server_test.action($_default_tc)",
      "$dir_pw_transfer/py:python_cpp_transfer_test.action($_default_tc)",
      "$dir_pw_unit_test/py:rpc_service_test.action($_default_tc)",
    ]
  }
}

# OSS-Fuzz uses this target to build fuzzers alone.
group("fuzzers") {
  # Fuzzing is only supported on Linux and MacOS using clang.
  if (host_os != "win") {
    deps = [ ":pw_module_tests($dir_pigweed/targets/host:host_clang_fuzz)" ]
  }
}

pw_python_group("python") {
  python_deps = [
    "$dir_pigweed/docs:sphinx_themes",
    "$dir_pw_env_setup:python",
    "$dir_pw_env_setup:target_support_packages",
  ]
}

# By default, Pigweed will build this target when invoking ninja.
group("pigweed_default") {
  deps = []

  # Prevent the default toolchain from parsing any other BUILD.gn files.
  if (current_toolchain != default_toolchain) {
    deps = [ ":apps" ]
    if (pw_unit_test_AUTOMATIC_RUNNER == "") {
      # Without a test runner defined, build the tests but don't run them.
      deps += [ ":pw_module_tests" ]
    } else {
      # With a test runner, depend on the run targets so they run with the
      # build.
      deps += [ ":pw_module_tests.run" ]
    }
  }
  if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
      pw_toolchain_SCOPE.is_host_toolchain && pw_build_HOST_TOOLS) {
    deps += [ ":host_tools" ]
  }

  # Trace examples currently only support running on non-windows host
  if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
      pw_toolchain_SCOPE.is_host_toolchain && host_os != "win") {
    deps += [
      "$dir_pw_trace:trace_example_basic",
      "$dir_pw_trace_tokenized:trace_tokenized_example_basic",
      "$dir_pw_trace_tokenized:trace_tokenized_example_filter",
      "$dir_pw_trace_tokenized:trace_tokenized_example_rpc",
      "$dir_pw_trace_tokenized:trace_tokenized_example_trigger",
    ]
  }
}

# The default toolchain is not used for compiling C/C++ code.
if (current_toolchain != default_toolchain) {
  group("apps") {
    # Application images built for all targets.
    deps = [ "$dir_pw_hdlc/rpc_example" ]

    # Add target-specific images.
    deps += pw_TARGET_APPLICATIONS

    # Add the pw_tool target to be built on host.
    if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
        pw_toolchain_SCOPE.is_host_toolchain) {
      deps += [ "$dir_pw_tool" ]
    }
  }

  group("host_tools") {
    deps = [
      "$dir_pw_target_runner/go:simple_client",
      "$dir_pw_target_runner/go:simple_server",
    ]
  }

  # All Pigweed modules that can be built using gn. This is not built by default.
  group("pw_modules") {
    deps = [
      "$dir_pigweed/docs",
      "$dir_pw_allocator",
      "$dir_pw_analog",
      "$dir_pw_base64",
      "$dir_pw_blob_store",
      "$dir_pw_bytes",
      "$dir_pw_checksum",
      "$dir_pw_chrono",
      "$dir_pw_console",
      "$dir_pw_cpu_exception",
      "$dir_pw_hdlc",
      "$dir_pw_i2c",
      "$dir_pw_metric",
      "$dir_pw_persistent_ram",
      "$dir_pw_polyfill",
      "$dir_pw_preprocessor",
      "$dir_pw_protobuf",
      "$dir_pw_result",
      "$dir_pw_status",
      "$dir_pw_stream",
      "$dir_pw_string",
      "$dir_pw_sync",
      "$dir_pw_sys_io",
      "$dir_pw_thread",
      "$dir_pw_tool",
      "$dir_pw_trace",
      "$dir_pw_unit_test",
      "$dir_pw_varint",
    ]

    if (host_os != "win") {
      deps += [
        # TODO(frolv): Remove these two when new KVS is ready.
        "$dir_pw_kvs",
        "$dir_pw_minimal_cpp_stdlib",

        # TODO(pwbug/111): Remove this when building successfully on Windows.
        "$dir_pw_tokenizer",
      ]
    }
  }

  # Targets for all module unit test groups.
  pw_test_group("pw_module_tests") {
    group_deps = [
      "$dir_pw_allocator:tests",
      "$dir_pw_analog:tests",
      "$dir_pw_assert:tests",
      "$dir_pw_base64:tests",
      "$dir_pw_blob_store:tests",
      "$dir_pw_bluetooth_hci:tests",
      "$dir_pw_bytes:tests",
      "$dir_pw_checksum:tests",
      "$dir_pw_chrono:tests",
      "$dir_pw_containers:tests",
      "$dir_pw_cpu_exception_cortex_m:tests",
      "$dir_pw_crypto:tests",
      "$dir_pw_file:tests",
      "$dir_pw_function:tests",
      "$dir_pw_fuzzer:tests",
      "$dir_pw_hdlc:tests",
      "$dir_pw_hex_dump:tests",
      "$dir_pw_i2c:tests",
      "$dir_pw_libc:tests",
      "$dir_pw_log:tests",
      "$dir_pw_log_null:tests",
      "$dir_pw_log_rpc:tests",
      "$dir_pw_log_tokenized:tests",
      "$dir_pw_malloc_freelist:tests",
      "$dir_pw_metric:tests",
      "$dir_pw_multisink:tests",
      "$dir_pw_persistent_ram:tests",
      "$dir_pw_polyfill:tests",
      "$dir_pw_preprocessor:tests",
      "$dir_pw_protobuf:tests",
      "$dir_pw_protobuf_compiler:tests",
      "$dir_pw_random:tests",
      "$dir_pw_result:tests",
      "$dir_pw_ring_buffer:tests",
      "$dir_pw_router:tests",
      "$dir_pw_rpc:tests",
      "$dir_pw_snapshot:tests",
      "$dir_pw_software_update:tests",
      "$dir_pw_span:tests",
      "$dir_pw_status:tests",
      "$dir_pw_stream:tests",
      "$dir_pw_string:tests",
      "$dir_pw_sync:tests",
      "$dir_pw_thread:tests",
      "$dir_pw_thread_stl:tests",
      "$dir_pw_tls_client:tests",
      "$dir_pw_tls_client_boringssl:tests",
      "$dir_pw_tls_client_mbedtls:tests",
      "$dir_pw_tokenizer:tests",
      "$dir_pw_trace:tests",
      "$dir_pw_trace_tokenized:tests",
      "$dir_pw_unit_test:tests",
      "$dir_pw_varint:tests",
      "$dir_pw_work_queue:tests",
    ]

    if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
        pw_toolchain_SCOPE.is_host_toolchain) {
      # TODO(pwbug/196): KVS tests are not compatible with device builds as they
      # use features such as std::map and are computationally expensive. Solving
      # this requires a more complex capabilities-based build and configuration
      # system which allowing enabling specific tests for targets that support
      # them and modifying test parameters for different targets.
      #
      # Checking for pw_build_host_tools (which is only set by the host) is a
      # temporary fix until the problem can be properly solved.
      group_deps += [ "$dir_pw_kvs:tests" ]

      if (host_os != "win") {
        # TODO(pwbug/441): Fix transfer tests on Windows.
        group_deps += [ "$dir_pw_transfer:tests" ]
      }
    }

    if (host_os != "win") {
      # TODO(amontanez): pw_minimal_cpp_stdlib tests do not build on windows.
      group_deps += [ "$dir_pw_minimal_cpp_stdlib:tests" ]
    }
  }
}