BUILD.gn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. # Copyright 2018 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("//build/config/chromeos/ui_mode.gni")
  5. import("//build/config/compiler/compiler.gni")
  6. import("//build/config/nacl/config.gni")
  7. import("//chrome/process_version_rc_template.gni")
  8. import("//testing/libfuzzer/fuzzer_test.gni")
  9. import("//testing/test.gni")
  10. if (is_mac) {
  11. import("//third_party/protobuf/proto_library.gni")
  12. }
  13. component("embedder_internal") {
  14. output_name = "mojo_core_embedder_internal"
  15. public_deps = [ ":impl_for_embedder" ]
  16. visibility = [
  17. ":test_sources",
  18. "//mojo:*",
  19. "//mojo/core/embedder",
  20. "//mojo/core/test:test_support",
  21. ]
  22. }
  23. # Bits of the EDK library which do not depend on public API linkage. It is
  24. # not allowed for this target or any of its transitive dependencies to depend
  25. # on anything under //mojo/public beyond strict C type definitions.
  26. #
  27. # This is templated because it's consumed by both the ":embedder_internal"
  28. # component library as well as the ":mojo_core" shared library. In the former
  29. # case we want to export symbols, but in the latter case we don't. The template
  30. # stamps out two nearly identical targets which differ only in what symbols they
  31. # export.
  32. template("core_impl_source_set") {
  33. source_set(target_name) {
  34. if (invoker.for_shared_library) {
  35. visibility = [ ":shared_library" ]
  36. } else {
  37. visibility = [
  38. ":core_impl_for_fuzzers",
  39. ":embedder_internal",
  40. ]
  41. }
  42. public = [
  43. "channel.h",
  44. "configuration.h",
  45. "connection_params.h",
  46. "core.h",
  47. "core_ipcz.h",
  48. "data_pipe_consumer_dispatcher.h",
  49. "data_pipe_control_message.h",
  50. "data_pipe_producer_dispatcher.h",
  51. "dispatcher.h",
  52. "embedder/configuration.h",
  53. "embedder/process_error_callback.h",
  54. "entrypoints.h",
  55. "handle_signals_state.h",
  56. "handle_table.h",
  57. "invitation_dispatcher.h",
  58. "ipcz_api.h",
  59. "ipcz_driver/driver.h",
  60. "ipcz_driver/transmissible_platform_handle.h",
  61. "ipcz_driver/transport.h",
  62. "ipcz_driver/wrapped_platform_handle.h",
  63. "message_pipe_dispatcher.h",
  64. "node_channel.h",
  65. "node_controller.h",
  66. "options_validation.h",
  67. "platform_handle_dispatcher.h",
  68. "platform_handle_utils.h",
  69. "platform_shared_memory_mapping.h",
  70. "request_context.h",
  71. "shared_buffer_dispatcher.h",
  72. "user_message_impl.h",
  73. ]
  74. sources = [
  75. "atomic_flag.cc",
  76. "atomic_flag.h",
  77. "broker.h",
  78. "channel.cc",
  79. "configuration.cc",
  80. "connection_params.cc",
  81. "core.cc",
  82. "core_ipcz.cc",
  83. "data_pipe_consumer_dispatcher.cc",
  84. "data_pipe_control_message.cc",
  85. "data_pipe_producer_dispatcher.cc",
  86. "dispatcher.cc",
  87. "entrypoints.cc",
  88. "handle_table.cc",
  89. "invitation_dispatcher.cc",
  90. "ipcz_api.cc",
  91. "ipcz_driver/driver.cc",
  92. "ipcz_driver/mojo_trap.cc",
  93. "ipcz_driver/mojo_trap.h",
  94. "ipcz_driver/object.cc",
  95. "ipcz_driver/object.h",
  96. "ipcz_driver/transmissible_platform_handle.cc",
  97. "ipcz_driver/transport.cc",
  98. "ipcz_driver/wrapped_platform_handle.cc",
  99. "message_pipe_dispatcher.cc",
  100. "node_channel.cc",
  101. "node_controller.cc",
  102. "platform_handle_dispatcher.cc",
  103. "platform_handle_in_transit.cc",
  104. "platform_handle_in_transit.h",
  105. "platform_handle_utils.cc",
  106. "platform_shared_memory_mapping.cc",
  107. "request_context.cc",
  108. "shared_buffer_dispatcher.cc",
  109. "user_message_impl.cc",
  110. "watch.cc",
  111. "watch.h",
  112. "watcher_dispatcher.cc",
  113. "watcher_dispatcher.h",
  114. "watcher_set.cc",
  115. "watcher_set.h",
  116. ]
  117. public_deps = [
  118. "//base",
  119. "//mojo/core/embedder:features",
  120. "//mojo/core/ports",
  121. "//mojo/public/c/system:headers",
  122. "//mojo/public/cpp/bindings:mojo_buildflags",
  123. "//mojo/public/cpp/platform",
  124. "//third_party/ipcz/src:ipcz_chromium",
  125. ]
  126. if (is_fuchsia) {
  127. sources += [ "channel_fuchsia.cc" ]
  128. public_deps += [ "//third_party/fuchsia-sdk/sdk/pkg/fdio" ]
  129. }
  130. if (is_posix && !is_mac) {
  131. if (!is_nacl) {
  132. sources += [
  133. "broker_posix.cc",
  134. "channel_posix.cc",
  135. "channel_posix.h",
  136. ]
  137. }
  138. if ((is_linux || is_chromeos || is_android) && !is_nacl) {
  139. sources += [
  140. "channel_linux.cc",
  141. "channel_linux.h",
  142. ]
  143. public += [ "channel_linux.h" ]
  144. }
  145. }
  146. if (is_mac) {
  147. sources += [ "channel_mac.cc" ]
  148. }
  149. if (!is_nacl) {
  150. sources += [
  151. "broker_host.cc",
  152. "broker_host.h",
  153. ]
  154. }
  155. defines = []
  156. if (invoker.for_shared_library) {
  157. defines += [ "MOJO_CORE_SHARED_LIBRARY" ]
  158. } else {
  159. defines += [ "MOJO_SYSTEM_IMPL_IMPLEMENTATION" ]
  160. }
  161. deps = []
  162. if (is_android) {
  163. deps += [ "//third_party/ashmem" ]
  164. }
  165. if (!is_nacl) {
  166. deps += [ "//crypto" ]
  167. }
  168. if (is_win) {
  169. sources += [
  170. "broker_win.cc",
  171. "channel_win.cc",
  172. ]
  173. }
  174. # Use target_os == "chromeos" instead of is_chromeos because we need to
  175. # build NaCl targets (i.e. IRT) for ChromeOS the same as the rest of ChromeOS.
  176. if (is_android || target_os == "chromeos" ||
  177. (target_os == "linux" && chromeos_is_browser_only)) {
  178. defines += [ "MOJO_CORE_LEGACY_PROTOCOL" ]
  179. }
  180. if (!is_debug && !optimize_for_size) {
  181. configs -= [ "//build/config/compiler:default_optimization" ]
  182. configs += [ "//build/config/compiler:optimize_max" ]
  183. }
  184. }
  185. }
  186. core_impl_source_set("impl_for_embedder") {
  187. for_shared_library = false
  188. }
  189. if (is_win) {
  190. process_version_rc_template("mojo_core_version") {
  191. sources = [ "mojo_core.ver" ]
  192. output = "$target_gen_dir/mojo_core_version.rc"
  193. }
  194. }
  195. if (is_chromeos || is_linux || is_android || is_win || is_fuchsia) {
  196. core_impl_source_set("impl_for_shared_library") {
  197. for_shared_library = true
  198. }
  199. shared_library("shared_library") {
  200. output_name = "mojo_core"
  201. sources = [ "mojo_core.cc" ]
  202. defines = [ "MOJO_CORE_SHARED_LIBRARY" ]
  203. deps = [
  204. ":impl_for_shared_library",
  205. "//base:base_static",
  206. "//mojo/public/c/system:headers",
  207. ]
  208. if (is_win) {
  209. sources += [ "mojo_core.def" ]
  210. deps += [ ":mojo_core_version" ]
  211. } else {
  212. configs += [ ":export_only_thunks_api" ]
  213. }
  214. }
  215. if (is_chromeos_ash) {
  216. if (target_cpu == "arm" || target_cpu == "arm64") {
  217. android32_toolchain = "android_clang_arm"
  218. android64_toolchain = "android_clang_arm64"
  219. } else {
  220. android32_toolchain = "android_clang_x86"
  221. android64_toolchain = "android_clang_x64"
  222. }
  223. group("shared_libraries_for_arc") {
  224. deps = [
  225. ":shared_library_arc32",
  226. ":shared_library_arc64",
  227. ]
  228. }
  229. copy("shared_library_arc32") {
  230. sources = [ "${root_build_dir}/${android32_toolchain}/libmojo_core.so" ]
  231. outputs = [ "${root_build_dir}/libmojo_core_arc32.so" ]
  232. deps = [
  233. ":shared_library(//build/toolchain/android:${android32_toolchain})",
  234. ]
  235. }
  236. copy("shared_library_arc64") {
  237. sources = [ "${root_build_dir}/${android64_toolchain}/libmojo_core.so" ]
  238. outputs = [ "${root_build_dir}/libmojo_core_arc64.so" ]
  239. deps = [
  240. ":shared_library(//build/toolchain/android:${android64_toolchain})",
  241. ]
  242. }
  243. }
  244. config("export_only_thunks_api") {
  245. inputs = [ "export_only_thunks_api.lst" ]
  246. ldflags = [ "-Wl,--version-script=" +
  247. rebase_path("//mojo/core/export_only_thunks_api.lst",
  248. root_build_dir) ]
  249. }
  250. if (is_chromeos || is_linux || is_win || is_fuchsia) {
  251. test("mojo_core_unittests") {
  252. sources = [
  253. "mojo_core_unittest.cc",
  254. "mojo_core_unittest.h",
  255. "run_all_core_unittests.cc",
  256. ]
  257. deps = [
  258. "//base",
  259. "//base/test:test_support",
  260. "//mojo/public/c/system",
  261. "//mojo/public/cpp/platform",
  262. "//mojo/public/cpp/system",
  263. "//testing/gtest",
  264. ]
  265. data_deps = [ ":shared_library" ]
  266. }
  267. }
  268. }
  269. source_set("test_sources") {
  270. testonly = true
  271. sources = [
  272. "channel_unittest.cc",
  273. "core_ipcz_test.cc",
  274. "core_test_base.cc",
  275. "core_test_base.h",
  276. "core_unittest.cc",
  277. "embedder_unittest.cc",
  278. "handle_table_unittest.cc",
  279. "message_pipe_unittest.cc",
  280. "message_unittest.cc",
  281. "node_channel_unittest.cc",
  282. "options_validation_unittest.cc",
  283. "platform_handle_dispatcher_unittest.cc",
  284. "quota_unittest.cc",
  285. "shared_buffer_dispatcher_unittest.cc",
  286. "shared_buffer_unittest.cc",
  287. "signals_unittest.cc",
  288. "trap_unittest.cc",
  289. ]
  290. if (!is_ios) {
  291. sources += [
  292. "data_pipe_unittest.cc",
  293. "invitation_unittest.cc",
  294. "ipcz_driver/transport_test.cc",
  295. "multiprocess_message_pipe_unittest.cc",
  296. "node_controller_unittest.cc",
  297. "platform_wrapper_unittest.cc",
  298. ]
  299. }
  300. deps = [
  301. "//base",
  302. "//base/test:test_support",
  303. "//mojo/core:embedder_internal",
  304. "//mojo/core/embedder",
  305. "//mojo/core/ports:tests",
  306. "//mojo/core/test:run_all_unittests",
  307. "//mojo/core/test:test_support",
  308. "//mojo/public/cpp/system",
  309. "//testing/gmock",
  310. "//testing/gtest",
  311. "//third_party/ipcz/src:ipcz_chromium",
  312. ]
  313. }
  314. group("core_impl_for_fuzzers") {
  315. public_deps = [ ":impl_for_embedder" ]
  316. }
  317. fuzzer_test("mojo_core_channel_fuzzer") {
  318. sources = [ "channel_fuzzer.cc" ]
  319. deps = [
  320. ":core_impl_for_fuzzers",
  321. "//base",
  322. "//mojo/public/cpp/platform",
  323. ]
  324. }
  325. if (is_mac) {
  326. protoc_convert("mojo_core_channel_mac_fuzzer_convert_corpus") {
  327. sources = [
  328. "test/data/channel_mac/bad_handshake1.textproto",
  329. "test/data/channel_mac/bad_handshake2.textproto",
  330. "test/data/channel_mac/bad_handshake3.textproto",
  331. "test/data/channel_mac/bad_message1.textproto",
  332. "test/data/channel_mac/complex_messages.textproto",
  333. "test/data/channel_mac/double_handshake.textproto",
  334. "test/data/channel_mac/handshake.textproto",
  335. "test/data/channel_mac/invalid_handles.textproto",
  336. "test/data/channel_mac/non_complex_with_descriptor_count.textproto",
  337. "test/data/channel_mac/ool_type_mismatch.textproto",
  338. "test/data/channel_mac/simple_message1.textproto",
  339. "test/data/channel_mac/simple_message2.textproto",
  340. ]
  341. inputs = [
  342. "test/data/channel_mac/channel_mac.proto",
  343. "//testing/libfuzzer/fuzzers/mach/mach_message.proto",
  344. ]
  345. output_pattern = "$target_gen_dir/mojo_core_channel_mac_corpus/{{source_name_part}}.binarypb"
  346. args = [
  347. "--encode=mojo_fuzzer.ChannelMac",
  348. "-I",
  349. rebase_path("//"),
  350. "mojo/core/test/data/channel_mac/channel_mac.proto",
  351. ]
  352. }
  353. fuzzer_test("mojo_core_channel_mac_fuzzer") {
  354. sources = [ "channel_mac_fuzzer.cc" ]
  355. seed_corpus = "$target_gen_dir/mojo_core_channel_mac_corpus"
  356. seed_corpus_deps = [ ":mojo_core_channel_mac_fuzzer_convert_corpus" ]
  357. deps = [
  358. ":core_impl_for_fuzzers",
  359. "test:channel_mac_proto",
  360. "//base",
  361. "//base/test:test_support",
  362. "//testing/libfuzzer/fuzzers/mach:converter",
  363. "//third_party/libprotobuf-mutator",
  364. ]
  365. }
  366. }
  367. fuzzer_test("mojo_core_node_channel_fuzzer") {
  368. sources = [ "node_channel_fuzzer.cc" ]
  369. deps = [
  370. ":core_impl_for_fuzzers",
  371. "//base",
  372. "//mojo/core/test:test_support",
  373. "//mojo/public/cpp/platform",
  374. ]
  375. }
  376. fuzzer_test("mojo_core_port_event_fuzzer") {
  377. sources = [ "port_event_fuzzer.cc" ]
  378. deps = [
  379. ":core_impl_for_fuzzers",
  380. "//base",
  381. ]
  382. }
  383. fuzzer_test("mojo_core_user_message_fuzzer") {
  384. sources = [ "user_message_fuzzer.cc" ]
  385. deps = [
  386. ":core_impl_for_fuzzers",
  387. "//base",
  388. ]
  389. }