BUILD.gn 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. # Copyright 2014 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/linux/gtk/gtk.gni")
  5. import("//build/config/sanitizers/sanitizers.gni")
  6. # Includes default args like 'enable_js_protobuf'.
  7. import("proto_library.gni")
  8. import("proto_sources.gni")
  9. if (enable_js_protobuf) {
  10. import("//third_party/closure_compiler/compile_js.gni")
  11. }
  12. config("protobuf_config") {
  13. include_dirs = [ "src" ]
  14. defines = [
  15. "GOOGLE_PROTOBUF_NO_RTTI",
  16. "GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
  17. "GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE=0",
  18. ]
  19. if (!is_win) {
  20. defines += [ "HAVE_PTHREAD" ]
  21. }
  22. }
  23. config("protobuf_warnings") {
  24. cflags = []
  25. if (is_clang) {
  26. # protobuf-3 contains a few functions that are unused.
  27. cflags += [ "-Wno-unused-function" ]
  28. }
  29. }
  30. config("protoc_warnings") {
  31. cflags = []
  32. if (is_clang) {
  33. # Some generates contain a few fields that are not used.
  34. cflags += [ "-Wno-unused-private-field" ]
  35. }
  36. }
  37. if (is_component_build) {
  38. config("protobuf_use_dlls") {
  39. defines = [ "PROTOBUF_USE_DLLS" ]
  40. }
  41. }
  42. # This config should be applied to targets using generated code from the proto
  43. # compiler. It sets up the include directories properly.
  44. config("using_proto") {
  45. include_dirs = [
  46. "src",
  47. "$root_gen_dir/protoc_out",
  48. ]
  49. }
  50. config("allow_deprecated_proto_fields") {
  51. if (is_clang) {
  52. cflags = [ "-DPROTOBUF_ALLOW_DEPRECATED=1" ]
  53. }
  54. }
  55. protobuf_lite_cflags = []
  56. if (is_win) {
  57. protobuf_lite_cflags = [
  58. "/wd4018", # signed/unsigned mismatch in comparison
  59. "/wd4065", # switch statement contains 'default' but no 'case' labels
  60. "/wd4146", # unary minus operator applied to unsigned type
  61. "/wd4244", # implicit conversion, possible loss of data
  62. "/wd4267", # size_t to int truncation
  63. "/wd4291", # no matching operator delete for a placement new.
  64. "/wd4305", # double to float truncation
  65. "/wd4355", # 'this' used in base member initializer list
  66. "/wd4506", # no definition for inline function (protobuf issue #240)
  67. "/wd4715", # not all control paths return a value (fixed in trunk)
  68. ]
  69. }
  70. # Do not allow libprotobuf_lite to be dynamically linked on Linux. Later
  71. # versions of Ubuntu like Xenial and Yakkety link in the system
  72. # libprotobuf_lite by the following dependency chain: chrome -> gtk ->
  73. # libmirclient -> libmirprotobuf -> libprotobuf-lite. Trying to load
  74. # the system libprotobuf-lite after already having loaded the libprotobuf_lite
  75. # component will result in an immediate crash. (crbug.com/700120)
  76. if (is_component_build && use_gtk) {
  77. shared_library("mirclient") {
  78. inputs = [ "mirclient.map" ]
  79. sources = [ "mirclient.cc" ]
  80. ldflags =
  81. [ "-Wl,--version-script=" +
  82. rebase_path("//third_party/protobuf/mirclient.map", root_build_dir) ]
  83. output_extension = "so.9"
  84. }
  85. }
  86. component("protobuf_lite") {
  87. sources = protobuf_lite_sources + protobuf_headers
  88. configs -= [ "//build/config/compiler:chromium_code" ]
  89. configs += [
  90. "//build/config/compiler:no_chromium_code",
  91. # Must be after no_chromium_code for warning flags to be ordered
  92. # correctly.
  93. ":protobuf_warnings",
  94. ]
  95. # Build protobuf_lite with full optimizations so Clang can optimize the
  96. # initializer out. See 0029-make-initializers-optimizable.patch.
  97. if (!is_debug && is_android) {
  98. configs -= [ "//build/config/compiler:default_optimization" ]
  99. configs += [ "//build/config/compiler:optimize_max" ]
  100. }
  101. # Remove Sanitizers and coverage for a performance boost when fuzzing. This is
  102. # OK because the only fuzzers that use protobuf are libprotobuf-mutator based
  103. # fuzzers, and they don't actually target the protobuf code, they just use it.
  104. configs -= not_fuzzed_remove_configs
  105. configs += [ "//build/config/sanitizers:not_fuzzed" ]
  106. if (is_win) {
  107. configs -= [ "//build/config/win:lean_and_mean" ]
  108. }
  109. public_configs = [ ":protobuf_config" ]
  110. if (is_android) {
  111. libs = [ "log" ] # Used by src/google/protobuf/stubs/common.cc
  112. }
  113. cflags = protobuf_lite_cflags
  114. if (is_component_build && use_gtk) {
  115. deps = [ ":mirclient" ]
  116. }
  117. # Required for component builds. See http://crbug.com/172800.
  118. if (is_component_build) {
  119. public_configs += [ ":protobuf_use_dlls" ]
  120. defines = [ "LIBPROTOBUF_EXPORTS" ]
  121. }
  122. }
  123. # This is the full, heavy protobuf lib that's needed for c++ .protos that don't
  124. # specify the LITE_RUNTIME option. The protocol compiler itself (protoc) falls
  125. # into that category. Do not use in Chrome code.
  126. static_library("protobuf_full") {
  127. # Prevent people from depending on this outside our file.
  128. visibility = [
  129. ":*",
  130. # requires descriptors & reflection; testonly.
  131. "//third_party/libprotobuf-mutator:*",
  132. # Chromecast requires descriptors and reflection.
  133. "//chromecast/*",
  134. # libassistant requires descriptors and reflection for testing.
  135. "//libassistant/*",
  136. # Perfetto uses the full library for testing.
  137. "//third_party/perfetto/gn:protobuf_full",
  138. # Some tests inside ChromeOS need reflection to parse golden files.
  139. # Not included in production code.
  140. "//chrome/test:usage_time_limit_unittests",
  141. # The protobuf-based SQLite and GPU fuzzers need protobuf_full and are not
  142. # included in Chrome.
  143. "//gpu:gl_lpm_fuzzer_proto",
  144. "//gpu:gl_lpm_fuzzer_proto_gen",
  145. "//gpu:gl_lpm_shader_to_string_unittest",
  146. "//third_party/sqlite:sqlite3_lpm_corpus_gen",
  147. # The protobuf-based Mojo LPM fuzzer needs protobuf_full and is not included
  148. # in Chrome.
  149. "//mojo/public/tools/fuzzers:mojolpm",
  150. # The root store tool is not part of Chrome itself, and needs to parse
  151. # human-readable protobufs. Protobuf is stored in //net/cert however as
  152. # browser needs to be able to parse serialized protobuf (which is exposed
  153. # as a separate lite BUILD rule).
  154. "//net/cert:root_store_proto_full",
  155. # The spirv-fuzz fuzzer tool needs protobuf_full and is not included in
  156. # Chrome.
  157. "//third_party/vulkan-deps/spirv-tools/src:spirv-fuzz",
  158. "//third_party/vulkan-deps/spirv-tools/src:spvtools_fuzz",
  159. "//third_party/vulkan-deps/spirv-tools/src:spvtools_fuzz_proto",
  160. # Some fuzzers for tint need protobuf_full and are not included in Chrome.
  161. # TODO(dawn:1339): Remove the *third_party/tint* entries once Tint
  162. # is merged into Dawn
  163. "//third_party/dawn/src/tint/fuzzers/tint_ast_fuzzer:tint_ast_fuzzer",
  164. "//third_party/dawn/src/tint/fuzzers/tint_ast_fuzzer:tint_ast_fuzzer_proto",
  165. "//third_party/dawn/src/tint/fuzzers/tint_spirv_tools_fuzzer:tint_spirv_tools_fuzzer",
  166. "//third_party/dawn/third_party/tint/src/tint/fuzzers/tint_ast_fuzzer:tint_ast_fuzzer",
  167. "//third_party/dawn/third_party/tint/src/tint/fuzzers/tint_ast_fuzzer:tint_ast_fuzzer_proto",
  168. "//third_party/dawn/third_party/tint/src/tint/fuzzers/tint_spirv_tools_fuzzer:tint_spirv_tools_fuzzer",
  169. # The Cast Core gRPC generator tool.
  170. "//third_party/cast_core/public/src/build/chromium:cast_core_grpc_generator",
  171. # Used for testing protobuf generation.
  172. "//components/services/screen_ai:test_support",
  173. ]
  174. # TODO(crbug.com/1338164): This ends up linking two copies of
  175. # protobuf_lite_sources in some targets, which is an ODR violation.
  176. sources = protobuf_lite_sources + protobuf_sources + protobuf_headers
  177. deps = [ "//third_party/zlib" ]
  178. if (is_android) {
  179. libs = [ "log" ] # Used by src/google/protobuf/stubs/common.cc
  180. }
  181. configs -= [ "//build/config/compiler:chromium_code" ]
  182. configs += [
  183. "//build/config/compiler:no_chromium_code",
  184. # Must be after no_chromium_code for warning flags to be ordered
  185. # correctly.
  186. ":protobuf_warnings",
  187. ]
  188. # Remove coverage and Sanitizers other than ASan for a performance boost when
  189. # fuzzing. ASan can't be removed here because of a bug preventing unsanitized
  190. # code from using libc++, which protobuf_full uses.
  191. configs -= not_fuzzed_remove_nonasan_configs
  192. configs += [ "//build/config/sanitizers:not_fuzzed" ]
  193. if (is_win) {
  194. configs -= [ "//build/config/win:lean_and_mean" ]
  195. }
  196. public_configs = [ ":protobuf_config" ]
  197. cflags = protobuf_lite_cflags
  198. defines = [ "HAVE_ZLIB" ]
  199. }
  200. # Only compile the compiler for the host architecture.
  201. if (current_toolchain == host_toolchain) {
  202. # protoc compiler is separated into protoc library and executable targets to
  203. # support protoc plugins that need to link libprotoc, but not the main()
  204. # itself. See src/google/protobuf/compiler/plugin.h
  205. static_library("protoc_lib") {
  206. sources = protoc_sources + protoc_headers
  207. configs -= [ "//build/config/compiler:chromium_code" ]
  208. configs += [
  209. "//build/config/compiler:no_chromium_code",
  210. # Must be after no_chromium_code for warning flags to be ordered
  211. # correctly.
  212. ":protobuf_warnings",
  213. ":protoc_warnings",
  214. ]
  215. if (is_win) {
  216. # This is defined internally, don't warn on duplicate.
  217. configs -= [ "//build/config/win:lean_and_mean" ]
  218. }
  219. public_configs = [ ":protobuf_config" ]
  220. cflags = protobuf_lite_cflags
  221. public_deps = [ ":protobuf_full" ]
  222. }
  223. executable("protoc") {
  224. sources = [ "src/google/protobuf/compiler/main.cc" ]
  225. configs -= [ "//build/config/compiler:chromium_code" ]
  226. configs += [ "//build/config/compiler:no_chromium_code" ]
  227. cflags = protobuf_lite_cflags
  228. deps = [
  229. ":protoc_lib",
  230. # Default manifest on Windows (a no-op elsewhere).
  231. "//build/win:default_exe_manifest",
  232. ]
  233. }
  234. }
  235. google_python_dir = "$root_out_dir/pyproto/google"
  236. copy("copy_google_protobuf") {
  237. # TODO(ncarter): protoc's python generator treats descriptor.proto
  238. # specially, but only when the input path is exactly
  239. # "google/protobuf/descriptor.proto". I'm not sure how to execute a rule
  240. # from a different directory. For now, use a manually-generated copy of
  241. # descriptor_pb2.py.
  242. sources = pyproto_sources + [ "python/google/protobuf/descriptor_pb2.py" ]
  243. outputs = [ "$google_python_dir/protobuf/{{source_file_part}}" ]
  244. }
  245. copy("copy_google_protobuf_internal") {
  246. sources = pyproto_internal_sources
  247. outputs = [ "$google_python_dir/protobuf/internal/{{source_file_part}}" ]
  248. }
  249. # Build time dependency for action rules.
  250. group("py_proto") {
  251. public_deps = [
  252. ":copy_google_protobuf",
  253. ":copy_google_protobuf_internal",
  254. ]
  255. }
  256. # Runtime dependency if the target needs the python scripts.
  257. group("py_proto_runtime") {
  258. deps = [ ":py_proto" ]
  259. # Targets that depend on this should depend on the copied data files.
  260. data = get_target_outputs(":copy_google_protobuf")
  261. data += get_target_outputs(":copy_google_protobuf_internal")
  262. }
  263. # JS protobuf library.
  264. if (enable_js_protobuf) {
  265. js_library("js_proto") {
  266. sources = [
  267. "//third_party/google-closure-library/closure/goog/array/array.js",
  268. "//third_party/google-closure-library/closure/goog/asserts/asserts.js",
  269. "//third_party/google-closure-library/closure/goog/base.js",
  270. "//third_party/google-closure-library/closure/goog/crypt/base64.js",
  271. "//third_party/google-closure-library/closure/goog/crypt/crypt.js",
  272. "//third_party/google-closure-library/closure/goog/debug/error.js",
  273. "//third_party/google-closure-library/closure/goog/dom/asserts.js",
  274. "//third_party/google-closure-library/closure/goog/dom/browserfeature.js",
  275. "//third_party/google-closure-library/closure/goog/dom/dom.js",
  276. "//third_party/google-closure-library/closure/goog/dom/htmlelement.js",
  277. "//third_party/google-closure-library/closure/goog/dom/nodetype.js",
  278. "//third_party/google-closure-library/closure/goog/dom/safe.js",
  279. "//third_party/google-closure-library/closure/goog/dom/tagname.js",
  280. "//third_party/google-closure-library/closure/goog/dom/tags.js",
  281. "//third_party/google-closure-library/closure/goog/fs/blob.js",
  282. "//third_party/google-closure-library/closure/goog/fs/url.js",
  283. "//third_party/google-closure-library/closure/goog/functions/functions.js",
  284. "//third_party/google-closure-library/closure/goog/goog.js",
  285. "//third_party/google-closure-library/closure/goog/html/safehtml.js",
  286. "//third_party/google-closure-library/closure/goog/html/safescript.js",
  287. "//third_party/google-closure-library/closure/goog/html/safestyle.js",
  288. "//third_party/google-closure-library/closure/goog/html/safestylesheet.js",
  289. "//third_party/google-closure-library/closure/goog/html/safeurl.js",
  290. "//third_party/google-closure-library/closure/goog/html/trustedresourceurl.js",
  291. "//third_party/google-closure-library/closure/goog/html/trustedtypes.js",
  292. "//third_party/google-closure-library/closure/goog/html/uncheckedconversions.js",
  293. "//third_party/google-closure-library/closure/goog/i18n/bidi.js",
  294. "//third_party/google-closure-library/closure/goog/labs/useragent/browser.js",
  295. "//third_party/google-closure-library/closure/goog/labs/useragent/engine.js",
  296. "//third_party/google-closure-library/closure/goog/labs/useragent/platform.js",
  297. "//third_party/google-closure-library/closure/goog/labs/useragent/useragent.js",
  298. "//third_party/google-closure-library/closure/goog/labs/useragent/util.js",
  299. "//third_party/google-closure-library/closure/goog/math/coordinate.js",
  300. "//third_party/google-closure-library/closure/goog/math/math.js",
  301. "//third_party/google-closure-library/closure/goog/math/size.js",
  302. "//third_party/google-closure-library/closure/goog/memoize/memoize.js",
  303. "//third_party/google-closure-library/closure/goog/object/object.js",
  304. "//third_party/google-closure-library/closure/goog/reflect/reflect.js",
  305. "//third_party/google-closure-library/closure/goog/string/const.js",
  306. "//third_party/google-closure-library/closure/goog/string/internal.js",
  307. "//third_party/google-closure-library/closure/goog/string/string.js",
  308. "//third_party/google-closure-library/closure/goog/string/typedstring.js",
  309. "//third_party/google-closure-library/closure/goog/useragent/product.js",
  310. "//third_party/google-closure-library/closure/goog/useragent/useragent.js",
  311. "js/binary/arith.js",
  312. "js/binary/constants.js",
  313. "js/binary/decoder.js",
  314. "js/binary/encoder.js",
  315. "js/binary/reader.js",
  316. "js/binary/utils.js",
  317. "js/binary/writer.js",
  318. "js/map.js",
  319. "js/message.js",
  320. ]
  321. }
  322. }