xref: /aosp_15_r20/external/cronet/ipc/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2012 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/buildflag_header.gni")
6import("//build/config/features.gni")
7import("//build/config/nacl/config.gni")
8import("//ipc/features.gni")
9import("//mojo/public/tools/bindings/mojom.gni")
10import("//testing/test.gni")
11import("//third_party/protobuf/proto_library.gni")
12import("//tools/ipc_fuzzer/ipc_fuzzer.gni")
13
14buildflag_header("ipc_buildflags") {
15  header = "ipc_buildflags.h"
16
17  flags = [ "IPC_MESSAGE_LOG_ENABLED=$enable_ipc_logging" ]
18}
19
20component("ipc") {
21  sources = [
22    # These are the param_traits sources needed by all platforms,
23    # including ios. The rest are added in a conditional block below.
24    "ipc_message_utils.cc",
25    "ipc_message_utils.h",
26    "ipc_mojo_param_traits.cc",
27    "ipc_mojo_param_traits.h",
28    "param_traits_log_macros.h",
29    "param_traits_macros.h",
30    "param_traits_read_macros.h",
31    "param_traits_write_macros.h",
32    "struct_constructor_macros.h",
33  ]
34
35  if (use_blink) {
36    sources += [
37      # Most sources go here since ios only needs the param_traits
38      # code.
39      "ipc_channel.h",
40      "ipc_channel_common.cc",
41      "ipc_channel_factory.cc",
42      "ipc_channel_factory.h",
43      "ipc_channel_handle.h",
44      "ipc_channel_mojo.cc",
45      "ipc_channel_mojo.h",
46      "ipc_channel_proxy.cc",
47      "ipc_channel_proxy.h",
48      "ipc_channel_reader.cc",
49      "ipc_channel_reader.h",
50      "ipc_listener.cc",
51      "ipc_listener.h",
52      "ipc_logging.cc",
53      "ipc_logging.h",
54      "ipc_message_macros.h",
55      "ipc_message_pipe_reader.cc",
56      "ipc_message_pipe_reader.h",
57      "ipc_message_start.h",
58      "ipc_message_templates.h",
59      "ipc_message_templates_impl.h",
60      "ipc_mojo_bootstrap.cc",
61      "ipc_mojo_bootstrap.h",
62      "ipc_sender.h",
63      "ipc_sync_channel.cc",
64      "ipc_sync_channel.h",
65      "ipc_sync_message_filter.cc",
66      "ipc_sync_message_filter.h",
67      "message_filter.cc",
68      "message_filter.h",
69      "message_filter_router.cc",
70      "message_filter_router.h",
71      "message_router.cc",
72      "message_router.h",
73      "trace_ipc_message.cc",
74      "trace_ipc_message.h",
75      "urgent_message_observer.h",
76    ]
77  }
78
79  if (is_nacl) {
80    sources += [
81      "ipc_channel_nacl.cc",
82      "ipc_channel_nacl.h",
83    ]
84  } else {
85    sources += [ "ipc_channel.cc" ]
86  }
87
88  defines = [ "IS_IPC_IMPL" ]
89
90  public_deps = [
91    ":ipc_buildflags",
92    ":message_support",
93    ":mojom",
94    ":native_handle_type_converters",
95    ":param_traits",
96    "//base",
97    "//mojo/public/cpp/base",
98    "//mojo/public/cpp/bindings",
99    "//mojo/public/cpp/system",
100    "//services/tracing/public/cpp",
101  ]
102
103  deps = [ "//base" ]
104
105  if (enable_ipc_fuzzer) {
106    public_configs = [ "//tools/ipc_fuzzer:ipc_fuzzer_config" ]
107  }
108}
109
110component("message_support") {
111  sources = [
112    "ipc_message.cc",
113    "ipc_message.h",
114    "ipc_message_attachment.cc",
115    "ipc_message_attachment.h",
116    "ipc_message_attachment_set.cc",
117    "ipc_message_attachment_set.h",
118    "ipc_message_support_export.h",
119    "ipc_mojo_handle_attachment.cc",
120    "ipc_mojo_handle_attachment.h",
121    "ipc_mojo_message_helper.cc",
122    "ipc_mojo_message_helper.h",
123    "ipc_platform_file.cc",
124    "ipc_platform_file.h",
125    "ipc_sync_message.cc",
126    "ipc_sync_message.h",
127  ]
128
129  if (is_win) {
130    sources += [
131      "handle_attachment_win.cc",
132      "handle_attachment_win.h",
133      "handle_win.cc",
134      "handle_win.h",
135    ]
136  }
137
138  if (is_posix || is_fuchsia) {
139    sources += [
140      "ipc_platform_file_attachment_posix.cc",
141      "ipc_platform_file_attachment_posix.h",
142    ]
143  }
144
145  if (is_apple) {
146    sources += [
147      "mach_port_attachment_mac.cc",
148      "mach_port_attachment_mac.h",
149      "mach_port_mac.cc",
150      "mach_port_mac.h",
151    ]
152  }
153
154  if (is_fuchsia) {
155    sources += [
156      "handle_attachment_fuchsia.cc",
157      "handle_attachment_fuchsia.h",
158    ]
159  }
160
161  defines = [ "IPC_MESSAGE_SUPPORT_IMPL" ]
162
163  public_deps = [
164    ":ipc_buildflags",
165    ":param_traits",
166    "//base",
167    "//mojo/public/cpp/system",
168  ]
169
170  if (is_win || is_mac) {
171    # On Windows HandleAttachmentWin needs to generate random IDs.
172    # On Mac MachPortAttachmentMac needs to generate random IDs.
173    deps = [ "//crypto" ]
174  }
175}
176
177source_set("native_handle_type_converters") {
178  sources = [
179    "native_handle_type_converters.cc",
180    "native_handle_type_converters.h",
181  ]
182  public_deps = [
183    ":message_support",
184    "//mojo/public/interfaces/bindings:bindings_headers",
185  ]
186}
187
188mojom("test_mojom") {
189  testonly = true
190  sources = [ "ipc_channel_mojo_unittest.test-mojom" ]
191  public_deps = [ "//mojo/public/mojom/base" ]
192}
193
194mojom_component("mojom") {
195  output_prefix = "ipc_mojom"
196  macro_prefix = "IPC_MOJOM"
197  sources = [ "ipc.mojom" ]
198  public_deps = [
199    "//mojo/public/interfaces/bindings",
200    "//mojo/public/mojom/base",
201  ]
202
203  cpp_typemaps = [
204    {
205      types = [
206        {
207          mojom = "IPC.mojom.Message"
208          cpp = "::IPC::MessageView"
209          move_only = true
210        },
211      ]
212      traits_headers = [ "//ipc/message_mojom_traits.h" ]
213      traits_sources = [
214        "//ipc/message_mojom_traits.cc",
215        "//ipc/message_view.cc",
216        "//ipc/message_view.h",
217      ]
218      traits_public_deps = [ "//ipc:message_support" ]
219    },
220  ]
221
222  # Don't generate a variant sources since we depend on generated internal
223  # bindings types and we don't generate or build variants of those.
224  disable_variants = true
225}
226
227mojom("mojom_constants") {
228  sources = [ "constants.mojom" ]
229}
230
231mojom("test_interfaces") {
232  testonly = true
233  sources = [ "ipc_test.mojom" ]
234}
235
236# This is provided as a separate target so other targets can provide param
237# traits implementations without necessarily linking to all of IPC.
238source_set("param_traits") {
239  public = [ "ipc_param_traits.h" ]
240}
241
242# This is provided as a separate target so other targets can use IPC without
243# necessarily linking to protobuf.
244source_set("protobuf_support") {
245  public = [ "ipc_message_protobuf_utils.h" ]
246  public_deps = [
247    ":ipc",
248    "//third_party/protobuf:protobuf_lite",
249  ]
250}
251
252static_library("test_sink") {
253  testonly = true
254  sources = [
255    "ipc_security_test_util.cc",
256    "ipc_security_test_util.h",
257    "ipc_test_sink.cc",
258    "ipc_test_sink.h",
259  ]
260  public_deps = [ ":ipc" ]
261  deps = [
262    "//base",
263    "//base/test:test_support",
264    "//mojo/core/test:test_support",
265  ]
266}
267
268if (use_blink) {
269  source_set("run_all_unittests") {
270    testonly = true
271
272    sources = [ "run_all_unittests.cc" ]
273
274    deps = [
275      "//base",
276      "//base/test:test_support",
277      "//mojo/core/embedder",
278      "//mojo/core/test:test_support",
279      "//third_party/ipcz/src:ipcz_test_support_chromium",
280      "//third_party/ipcz/src:test_buildflags",
281    ]
282  }
283
284  proto_library("test_proto") {
285    sources = [ "test_proto.proto" ]
286  }
287
288  test("ipc_tests") {
289    sources = [
290      "ipc_channel_mojo_unittest.cc",
291      "ipc_channel_proxy_unittest.cc",
292      "ipc_channel_reader_unittest.cc",
293      "ipc_fuzzing_tests.cc",
294      "ipc_message_protobuf_utils_unittest.cc",
295      "ipc_message_unittest.cc",
296      "ipc_message_utils_unittest.cc",
297      "ipc_mojo_bootstrap_unittest.cc",
298      "ipc_sync_channel_unittest.cc",
299      "ipc_sync_message_unittest.cc",
300      "ipc_sync_message_unittest.h",
301      "sync_socket_unittest.cc",
302    ]
303
304    if (is_posix || is_fuchsia) {
305      sources += [ "ipc_message_attachment_set_posix_unittest.cc" ]
306      if (!is_ios) {
307        sources += [ "ipc_send_fds_test.cc" ]
308      }
309    }
310
311    deps = [
312      ":ipc",
313      ":protobuf_support",
314      ":run_all_unittests",
315      ":test_interfaces",
316      ":test_mojom",
317      ":test_proto",
318      ":test_support",
319      "//base",
320      "//base:i18n",
321      "//base/test:test_support",
322      "//crypto",
323      "//mojo/core:driver_for_ipcz_tests",
324      "//mojo/core/test:test_support",
325      "//testing/gtest",
326      "//third_party/ipcz/src:ipcz_tests_sources_chromium",
327    ]
328
329    if (is_mac) {
330      deps += [ "//sandbox/mac:seatbelt" ]
331    }
332  }
333
334  test("ipc_perftests") {
335    sources = [
336      "ipc_cpu_perftest.cc",
337      "ipc_mojo_perftest.cc",
338      "ipc_perftest_messages.cc",
339      "ipc_perftest_messages.h",
340      "ipc_perftest_util.cc",
341      "ipc_perftest_util.h",
342      "run_all_perftests.cc",
343    ]
344
345    deps = [
346      ":ipc",
347      ":test_interfaces",
348      ":test_support",
349      "//base",
350      "//base:i18n",
351      "//base/test:test_support",
352      "//mojo/core/embedder",
353      "//mojo/core/test:test_support",
354      "//mojo/core/test:test_support_impl",
355      "//testing/gtest",
356    ]
357  }
358
359  static_library("test_support") {
360    testonly = true
361    sources = [
362      "ipc_test_base.cc",
363      "ipc_test_base.h",
364      "ipc_test_channel_listener.cc",
365      "ipc_test_channel_listener.h",
366    ]
367    public_deps = [
368      ":ipc",
369      ":test_sink",
370    ]
371    deps = [
372      "//base",
373      "//base/test:test_support",
374      "//mojo/core/test:test_support",
375      "//testing/gtest",
376    ]
377  }
378}
379