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