• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Bazel (http://bazel.io/) BUILD file for Protobuf.
2
3licenses(["notice"])
4
5################################################################################
6# Protobuf Runtime Library
7################################################################################
8
9COPTS = [
10    "-DHAVE_PTHREAD",
11    "-Wall",
12    "-Wwrite-strings",
13    "-Woverloaded-virtual",
14    "-Wno-sign-compare",
15    "-Wno-error=unused-function",
16]
17
18config_setting(
19    name = "android",
20    values = {
21        "crosstool_top": "//external:android/crosstool",
22    },
23)
24
25# Android builds do not need to link in a separate pthread library.
26LINK_OPTS = select({
27    ":android": [],
28    "//conditions:default": ["-lpthread"],
29})
30
31load(
32    "protobuf",
33    "cc_proto_library",
34    "py_proto_library",
35    "internal_copied_filegroup",
36    "internal_gen_well_known_protos_java",
37    "internal_protobuf_py_tests",
38)
39
40config_setting(
41    name = "ios_armv7",
42    values = {
43        "ios_cpu": "armv7",
44    },
45)
46
47config_setting(
48    name = "ios_armv7s",
49    values = {
50        "ios_cpu": "armv7s",
51    },
52)
53
54config_setting(
55    name = "ios_arm64",
56    values = {
57        "ios_cpu": "arm64",
58    },
59)
60
61IOS_ARM_COPTS = COPTS + [
62    "-DOS_IOS",
63    "-miphoneos-version-min=7.0",
64    "-arch armv7",
65    "-arch armv7s",
66    "-arch arm64",
67    "-D__thread=",
68    "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/",
69]
70
71cc_library(
72    name = "protobuf_lite",
73    srcs = [
74        # AUTOGEN(protobuf_lite_srcs)
75        "src/google/protobuf/arena.cc",
76        "src/google/protobuf/arenastring.cc",
77        "src/google/protobuf/extension_set.cc",
78        "src/google/protobuf/generated_message_util.cc",
79        "src/google/protobuf/io/coded_stream.cc",
80        "src/google/protobuf/io/zero_copy_stream.cc",
81        "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
82        "src/google/protobuf/message_lite.cc",
83        "src/google/protobuf/repeated_field.cc",
84        "src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
85        "src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc",
86        "src/google/protobuf/stubs/bytestream.cc",
87        "src/google/protobuf/stubs/common.cc",
88        "src/google/protobuf/stubs/int128.cc",
89        "src/google/protobuf/stubs/once.cc",
90        "src/google/protobuf/stubs/status.cc",
91        "src/google/protobuf/stubs/statusor.cc",
92        "src/google/protobuf/stubs/stringpiece.cc",
93        "src/google/protobuf/stubs/stringprintf.cc",
94        "src/google/protobuf/stubs/structurally_valid.cc",
95        "src/google/protobuf/stubs/strutil.cc",
96        "src/google/protobuf/stubs/time.cc",
97        "src/google/protobuf/wire_format_lite.cc",
98    ],
99    hdrs = glob(["src/google/protobuf/**/*.h"]),
100    copts = select({
101        ":ios_armv7": IOS_ARM_COPTS,
102        ":ios_armv7s": IOS_ARM_COPTS,
103        ":ios_arm64": IOS_ARM_COPTS,
104        "//conditions:default": COPTS,
105    }),
106    includes = ["src/"],
107    linkopts = LINK_OPTS,
108    visibility = ["//visibility:public"],
109)
110
111cc_library(
112    name = "protobuf",
113    srcs = [
114        # AUTOGEN(protobuf_srcs)
115        "src/google/protobuf/any.cc",
116        "src/google/protobuf/any.pb.cc",
117        "src/google/protobuf/api.pb.cc",
118        "src/google/protobuf/compiler/importer.cc",
119        "src/google/protobuf/compiler/parser.cc",
120        "src/google/protobuf/descriptor.cc",
121        "src/google/protobuf/descriptor.pb.cc",
122        "src/google/protobuf/descriptor_database.cc",
123        "src/google/protobuf/duration.pb.cc",
124        "src/google/protobuf/dynamic_message.cc",
125        "src/google/protobuf/empty.pb.cc",
126        "src/google/protobuf/extension_set_heavy.cc",
127        "src/google/protobuf/field_mask.pb.cc",
128        "src/google/protobuf/generated_message_reflection.cc",
129        "src/google/protobuf/io/gzip_stream.cc",
130        "src/google/protobuf/io/printer.cc",
131        "src/google/protobuf/io/strtod.cc",
132        "src/google/protobuf/io/tokenizer.cc",
133        "src/google/protobuf/io/zero_copy_stream_impl.cc",
134        "src/google/protobuf/map_field.cc",
135        "src/google/protobuf/message.cc",
136        "src/google/protobuf/reflection_ops.cc",
137        "src/google/protobuf/service.cc",
138        "src/google/protobuf/source_context.pb.cc",
139        "src/google/protobuf/struct.pb.cc",
140        "src/google/protobuf/stubs/mathlimits.cc",
141        "src/google/protobuf/stubs/substitute.cc",
142        "src/google/protobuf/text_format.cc",
143        "src/google/protobuf/timestamp.pb.cc",
144        "src/google/protobuf/type.pb.cc",
145        "src/google/protobuf/unknown_field_set.cc",
146        "src/google/protobuf/util/field_comparator.cc",
147        "src/google/protobuf/util/field_mask_util.cc",
148        "src/google/protobuf/util/internal/datapiece.cc",
149        "src/google/protobuf/util/internal/default_value_objectwriter.cc",
150        "src/google/protobuf/util/internal/error_listener.cc",
151        "src/google/protobuf/util/internal/field_mask_utility.cc",
152        "src/google/protobuf/util/internal/json_escaping.cc",
153        "src/google/protobuf/util/internal/json_objectwriter.cc",
154        "src/google/protobuf/util/internal/json_stream_parser.cc",
155        "src/google/protobuf/util/internal/object_writer.cc",
156        "src/google/protobuf/util/internal/proto_writer.cc",
157        "src/google/protobuf/util/internal/protostream_objectsource.cc",
158        "src/google/protobuf/util/internal/protostream_objectwriter.cc",
159        "src/google/protobuf/util/internal/type_info.cc",
160        "src/google/protobuf/util/internal/type_info_test_helper.cc",
161        "src/google/protobuf/util/internal/utility.cc",
162        "src/google/protobuf/util/json_util.cc",
163        "src/google/protobuf/util/message_differencer.cc",
164        "src/google/protobuf/util/time_util.cc",
165        "src/google/protobuf/util/type_resolver_util.cc",
166        "src/google/protobuf/wire_format.cc",
167        "src/google/protobuf/wrappers.pb.cc",
168    ],
169    hdrs = glob(["src/**/*.h"]),
170    copts = select({
171        ":ios_armv7": IOS_ARM_COPTS,
172        ":ios_armv7s": IOS_ARM_COPTS,
173        ":ios_arm64": IOS_ARM_COPTS,
174        "//conditions:default": COPTS,
175    }),
176    includes = ["src/"],
177    linkopts = LINK_OPTS,
178    visibility = ["//visibility:public"],
179    deps = [":protobuf_lite"],
180)
181
182objc_library(
183    name = "protobuf_objc",
184    hdrs = ["objectivec/GPBProtocolBuffers.h"],
185    includes = ["objectivec"],
186    non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
187    visibility = ["//visibility:public"],
188)
189
190RELATIVE_WELL_KNOWN_PROTOS = [
191    # AUTOGEN(well_known_protos)
192    "google/protobuf/any.proto",
193    "google/protobuf/api.proto",
194    "google/protobuf/compiler/plugin.proto",
195    "google/protobuf/descriptor.proto",
196    "google/protobuf/duration.proto",
197    "google/protobuf/empty.proto",
198    "google/protobuf/field_mask.proto",
199    "google/protobuf/source_context.proto",
200    "google/protobuf/struct.proto",
201    "google/protobuf/timestamp.proto",
202    "google/protobuf/type.proto",
203    "google/protobuf/wrappers.proto",
204]
205
206WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
207
208filegroup(
209    name = "well_known_protos",
210    srcs = WELL_KNOWN_PROTOS,
211    visibility = ["//visibility:public"],
212)
213
214cc_proto_library(
215    name = "cc_wkt_protos",
216    srcs = WELL_KNOWN_PROTOS,
217    include = "src",
218    default_runtime = ":protobuf",
219    internal_bootstrap_hack = 1,
220    protoc = ":protoc",
221    visibility = ["//visibility:public"],
222)
223
224################################################################################
225# Protocol Buffers Compiler
226################################################################################
227
228cc_library(
229    name = "protoc_lib",
230    srcs = [
231        # AUTOGEN(protoc_lib_srcs)
232        "src/google/protobuf/compiler/code_generator.cc",
233        "src/google/protobuf/compiler/command_line_interface.cc",
234        "src/google/protobuf/compiler/cpp/cpp_enum.cc",
235        "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
236        "src/google/protobuf/compiler/cpp/cpp_extension.cc",
237        "src/google/protobuf/compiler/cpp/cpp_field.cc",
238        "src/google/protobuf/compiler/cpp/cpp_file.cc",
239        "src/google/protobuf/compiler/cpp/cpp_generator.cc",
240        "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
241        "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
242        "src/google/protobuf/compiler/cpp/cpp_message.cc",
243        "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
244        "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
245        "src/google/protobuf/compiler/cpp/cpp_service.cc",
246        "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
247        "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
248        "src/google/protobuf/compiler/csharp/csharp_enum.cc",
249        "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
250        "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
251        "src/google/protobuf/compiler/csharp/csharp_generator.cc",
252        "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
253        "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
254        "src/google/protobuf/compiler/csharp/csharp_message.cc",
255        "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
256        "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
257        "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
258        "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
259        "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
260        "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
261        "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
262        "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
263        "src/google/protobuf/compiler/java/java_context.cc",
264        "src/google/protobuf/compiler/java/java_doc_comment.cc",
265        "src/google/protobuf/compiler/java/java_enum.cc",
266        "src/google/protobuf/compiler/java/java_enum_field.cc",
267        "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
268        "src/google/protobuf/compiler/java/java_enum_lite.cc",
269        "src/google/protobuf/compiler/java/java_extension.cc",
270        "src/google/protobuf/compiler/java/java_extension_lite.cc",
271        "src/google/protobuf/compiler/java/java_field.cc",
272        "src/google/protobuf/compiler/java/java_file.cc",
273        "src/google/protobuf/compiler/java/java_generator.cc",
274        "src/google/protobuf/compiler/java/java_generator_factory.cc",
275        "src/google/protobuf/compiler/java/java_helpers.cc",
276        "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
277        "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
278        "src/google/protobuf/compiler/java/java_map_field.cc",
279        "src/google/protobuf/compiler/java/java_map_field_lite.cc",
280        "src/google/protobuf/compiler/java/java_message.cc",
281        "src/google/protobuf/compiler/java/java_message_builder.cc",
282        "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
283        "src/google/protobuf/compiler/java/java_message_field.cc",
284        "src/google/protobuf/compiler/java/java_message_field_lite.cc",
285        "src/google/protobuf/compiler/java/java_message_lite.cc",
286        "src/google/protobuf/compiler/java/java_name_resolver.cc",
287        "src/google/protobuf/compiler/java/java_primitive_field.cc",
288        "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
289        "src/google/protobuf/compiler/java/java_service.cc",
290        "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
291        "src/google/protobuf/compiler/java/java_string_field.cc",
292        "src/google/protobuf/compiler/java/java_string_field_lite.cc",
293        "src/google/protobuf/compiler/javanano/javanano_enum.cc",
294        "src/google/protobuf/compiler/javanano/javanano_enum_field.cc",
295        "src/google/protobuf/compiler/javanano/javanano_extension.cc",
296        "src/google/protobuf/compiler/javanano/javanano_field.cc",
297        "src/google/protobuf/compiler/javanano/javanano_file.cc",
298        "src/google/protobuf/compiler/javanano/javanano_generator.cc",
299        "src/google/protobuf/compiler/javanano/javanano_helpers.cc",
300        "src/google/protobuf/compiler/javanano/javanano_map_field.cc",
301        "src/google/protobuf/compiler/javanano/javanano_message.cc",
302        "src/google/protobuf/compiler/javanano/javanano_message_field.cc",
303        "src/google/protobuf/compiler/javanano/javanano_primitive_field.cc",
304        "src/google/protobuf/compiler/js/js_generator.cc",
305        "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
306        "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
307        "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
308        "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
309        "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
310        "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
311        "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
312        "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
313        "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
314        "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
315        "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
316        "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
317        "src/google/protobuf/compiler/plugin.cc",
318        "src/google/protobuf/compiler/plugin.pb.cc",
319        "src/google/protobuf/compiler/python/python_generator.cc",
320        "src/google/protobuf/compiler/ruby/ruby_generator.cc",
321        "src/google/protobuf/compiler/subprocess.cc",
322        "src/google/protobuf/compiler/zip_writer.cc",
323    ],
324    copts = COPTS,
325    includes = ["src/"],
326    linkopts = LINK_OPTS,
327    visibility = ["//visibility:public"],
328    deps = [":protobuf"],
329)
330
331cc_binary(
332    name = "protoc",
333    srcs = ["src/google/protobuf/compiler/main.cc"],
334    linkopts = LINK_OPTS,
335    visibility = ["//visibility:public"],
336    deps = [":protoc_lib"],
337)
338
339################################################################################
340# Tests
341################################################################################
342
343RELATIVE_LITE_TEST_PROTOS = [
344    # AUTOGEN(lite_test_protos)
345    "google/protobuf/map_lite_unittest.proto",
346    "google/protobuf/unittest_import_lite.proto",
347    "google/protobuf/unittest_import_public_lite.proto",
348    "google/protobuf/unittest_lite.proto",
349    "google/protobuf/unittest_no_arena_lite.proto",
350]
351
352LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
353
354RELATIVE_TEST_PROTOS = [
355    # AUTOGEN(test_protos)
356    "google/protobuf/any_test.proto",
357    "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
358    "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
359    "google/protobuf/map_proto2_unittest.proto",
360    "google/protobuf/map_unittest.proto",
361    "google/protobuf/unittest.proto",
362    "google/protobuf/unittest_arena.proto",
363    "google/protobuf/unittest_custom_options.proto",
364    "google/protobuf/unittest_drop_unknown_fields.proto",
365    "google/protobuf/unittest_embed_optimize_for.proto",
366    "google/protobuf/unittest_empty.proto",
367    "google/protobuf/unittest_enormous_descriptor.proto",
368    "google/protobuf/unittest_import.proto",
369    "google/protobuf/unittest_import_public.proto",
370    "google/protobuf/unittest_lite_imports_nonlite.proto",
371    "google/protobuf/unittest_mset.proto",
372    "google/protobuf/unittest_mset_wire_format.proto",
373    "google/protobuf/unittest_no_arena.proto",
374    "google/protobuf/unittest_no_arena_import.proto",
375    "google/protobuf/unittest_no_field_presence.proto",
376    "google/protobuf/unittest_no_generic_services.proto",
377    "google/protobuf/unittest_optimize_for.proto",
378    "google/protobuf/unittest_preserve_unknown_enum.proto",
379    "google/protobuf/unittest_preserve_unknown_enum2.proto",
380    "google/protobuf/unittest_proto3_arena.proto",
381    "google/protobuf/unittest_proto3_arena_lite.proto",
382    "google/protobuf/unittest_proto3_lite.proto",
383    "google/protobuf/unittest_well_known_types.proto",
384    "google/protobuf/util/internal/testdata/anys.proto",
385    "google/protobuf/util/internal/testdata/books.proto",
386    "google/protobuf/util/internal/testdata/default_value.proto",
387    "google/protobuf/util/internal/testdata/default_value_test.proto",
388    "google/protobuf/util/internal/testdata/field_mask.proto",
389    "google/protobuf/util/internal/testdata/maps.proto",
390    "google/protobuf/util/internal/testdata/oneofs.proto",
391    "google/protobuf/util/internal/testdata/struct.proto",
392    "google/protobuf/util/internal/testdata/timestamp_duration.proto",
393    "google/protobuf/util/json_format_proto3.proto",
394    "google/protobuf/util/message_differencer_unittest.proto",
395]
396
397TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
398
399cc_proto_library(
400    name = "cc_test_protos",
401    srcs = LITE_TEST_PROTOS + TEST_PROTOS,
402    include = "src",
403    default_runtime = ":protobuf",
404    protoc = ":protoc",
405    deps = [":cc_wkt_protos"],
406)
407
408COMMON_TEST_SRCS = [
409    # AUTOGEN(common_test_srcs)
410    "src/google/protobuf/arena_test_util.cc",
411    "src/google/protobuf/map_test_util.cc",
412    "src/google/protobuf/test_util.cc",
413    "src/google/protobuf/testing/file.cc",
414    "src/google/protobuf/testing/googletest.cc",
415]
416
417cc_binary(
418    name = "test_plugin",
419    srcs = [
420        # AUTOGEN(test_plugin_srcs)
421        "src/google/protobuf/compiler/mock_code_generator.cc",
422        "src/google/protobuf/compiler/test_plugin.cc",
423        "src/google/protobuf/testing/file.cc",
424    ],
425    deps = [
426        ":protobuf",
427        ":protoc_lib",
428        "//external:gtest",
429    ],
430)
431
432cc_test(
433    name = "protobuf_test",
434    srcs = COMMON_TEST_SRCS + [
435        # AUTOGEN(test_srcs)
436        "src/google/protobuf/any_test.cc",
437        "src/google/protobuf/arena_unittest.cc",
438        "src/google/protobuf/arenastring_unittest.cc",
439        "src/google/protobuf/compiler/command_line_interface_unittest.cc",
440        "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
441        "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
442        "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
443        "src/google/protobuf/compiler/cpp/metadata_test.cc",
444        "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
445        "src/google/protobuf/compiler/importer_unittest.cc",
446        "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
447        "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
448        "src/google/protobuf/compiler/mock_code_generator.cc",
449        "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
450        "src/google/protobuf/compiler/parser_unittest.cc",
451        "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
452        "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
453        "src/google/protobuf/descriptor_database_unittest.cc",
454        "src/google/protobuf/descriptor_unittest.cc",
455        "src/google/protobuf/drop_unknown_fields_test.cc",
456        "src/google/protobuf/dynamic_message_unittest.cc",
457        "src/google/protobuf/extension_set_unittest.cc",
458        "src/google/protobuf/generated_message_reflection_unittest.cc",
459        "src/google/protobuf/io/coded_stream_unittest.cc",
460        "src/google/protobuf/io/printer_unittest.cc",
461        "src/google/protobuf/io/tokenizer_unittest.cc",
462        "src/google/protobuf/io/zero_copy_stream_unittest.cc",
463        "src/google/protobuf/map_field_test.cc",
464        "src/google/protobuf/map_test.cc",
465        "src/google/protobuf/message_unittest.cc",
466        "src/google/protobuf/no_field_presence_test.cc",
467        "src/google/protobuf/preserve_unknown_enum_test.cc",
468        "src/google/protobuf/proto3_arena_lite_unittest.cc",
469        "src/google/protobuf/proto3_arena_unittest.cc",
470        "src/google/protobuf/proto3_lite_unittest.cc",
471        "src/google/protobuf/reflection_ops_unittest.cc",
472        "src/google/protobuf/repeated_field_reflection_unittest.cc",
473        "src/google/protobuf/repeated_field_unittest.cc",
474        "src/google/protobuf/stubs/bytestream_unittest.cc",
475        "src/google/protobuf/stubs/common_unittest.cc",
476        "src/google/protobuf/stubs/int128_unittest.cc",
477        "src/google/protobuf/stubs/once_unittest.cc",
478        "src/google/protobuf/stubs/status_test.cc",
479        "src/google/protobuf/stubs/statusor_test.cc",
480        "src/google/protobuf/stubs/stringpiece_unittest.cc",
481        "src/google/protobuf/stubs/stringprintf_unittest.cc",
482        "src/google/protobuf/stubs/structurally_valid_unittest.cc",
483        "src/google/protobuf/stubs/strutil_unittest.cc",
484        "src/google/protobuf/stubs/template_util_unittest.cc",
485        "src/google/protobuf/stubs/time_test.cc",
486        "src/google/protobuf/stubs/type_traits_unittest.cc",
487        "src/google/protobuf/text_format_unittest.cc",
488        "src/google/protobuf/unknown_field_set_unittest.cc",
489        "src/google/protobuf/util/field_comparator_test.cc",
490        "src/google/protobuf/util/field_mask_util_test.cc",
491        "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
492        "src/google/protobuf/util/internal/json_objectwriter_test.cc",
493        "src/google/protobuf/util/internal/json_stream_parser_test.cc",
494        "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
495        "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
496        "src/google/protobuf/util/internal/type_info_test_helper.cc",
497        "src/google/protobuf/util/json_util_test.cc",
498        "src/google/protobuf/util/message_differencer_unittest.cc",
499        "src/google/protobuf/util/time_util_test.cc",
500        "src/google/protobuf/util/type_resolver_util_test.cc",
501        "src/google/protobuf/well_known_types_unittest.cc",
502        "src/google/protobuf/wire_format_unittest.cc",
503    ],
504    copts = COPTS,
505    data = [
506        ":test_plugin",
507    ] + glob([
508        "src/google/protobuf/**/*",
509    ]),
510    includes = [
511        "src/",
512    ],
513    linkopts = LINK_OPTS,
514    deps = [
515        ":cc_test_protos",
516        ":protobuf",
517        ":protoc_lib",
518        "//external:gtest_main",
519    ],
520)
521
522################################################################################
523# Java support
524################################################################################
525internal_gen_well_known_protos_java(
526    srcs = WELL_KNOWN_PROTOS,
527)
528
529java_library(
530    name = "protobuf_java",
531    srcs = glob([
532        "java/core/src/main/java/com/google/protobuf/*.java",
533    ]) + [
534        ":gen_well_known_protos_java",
535    ],
536    visibility = ["//visibility:public"],
537)
538
539java_library(
540    name = "protobuf_java_util",
541    srcs = glob([
542        "java/util/src/main/java/com/google/protobuf/util/*.java",
543    ]),
544    deps = [
545        "protobuf_java",
546        "//external:gson",
547        "//external:guava",
548    ],
549    visibility = ["//visibility:public"],
550)
551
552################################################################################
553# Python support
554################################################################################
555
556py_library(
557    name = "python_srcs",
558    srcs = glob(
559        [
560            "python/google/protobuf/*.py",
561            "python/google/protobuf/**/*.py",
562        ],
563        exclude = [
564            "python/google/protobuf/__init__.py",
565            "python/google/protobuf/**/__init__.py",
566            "python/google/protobuf/internal/*_test.py",
567            "python/google/protobuf/internal/test_util.py",
568        ],
569    ),
570    srcs_version = "PY2AND3",
571    imports = ["python"],
572)
573
574cc_binary(
575    name = "internal/_api_implementation.so",
576    srcs = ["python/google/protobuf/internal/api_implementation.cc"],
577    copts = COPTS + [
578        "-DPYTHON_PROTO2_CPP_IMPL_V2",
579    ],
580    linkshared = 1,
581    linkstatic = 1,
582    deps = select({
583        "//conditions:default": [],
584        ":use_fast_cpp_protos": ["//external:python_headers"],
585    }),
586)
587
588cc_binary(
589    name = "pyext/_message.so",
590    srcs = glob([
591        "python/google/protobuf/pyext/*.cc",
592        "python/google/protobuf/pyext/*.h",
593    ]),
594    copts = COPTS + [
595        "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
596    ] + select({
597        "//conditions:default": [],
598        ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
599    }),
600    includes = [
601        "python/",
602        "src/",
603    ],
604    linkshared = 1,
605    linkstatic = 1,
606    deps = [
607        ":protobuf",
608    ] + select({
609        "//conditions:default": [],
610        ":use_fast_cpp_protos": ["//external:python_headers"],
611    }),
612)
613
614config_setting(
615    name = "use_fast_cpp_protos",
616    values = {
617        "define": "use_fast_cpp_protos=true",
618    },
619)
620
621config_setting(
622    name = "allow_oversize_protos",
623    values = {
624        "define": "allow_oversize_protos=true",
625    },
626)
627
628# Copy the builtin proto files from src/google/protobuf to
629# python/google/protobuf. This way, the generated Python sources will be in the
630# same directory as the Python runtime sources. This is necessary for the
631# modules to be imported correctly since they are all part of the same Python
632# package.
633internal_copied_filegroup(
634    name = "protos_python",
635    srcs = WELL_KNOWN_PROTOS,
636    strip_prefix = "src",
637    dest = "python",
638)
639
640# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
641# which case we can simply add :protos_python in srcs.
642COPIED_WELL_KNOWN_PROTOS = ["python/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
643
644py_proto_library(
645    name = "protobuf_python",
646    srcs = COPIED_WELL_KNOWN_PROTOS,
647    include = "python",
648    data = select({
649        "//conditions:default": [],
650        ":use_fast_cpp_protos": [
651            ":internal/_api_implementation.so",
652            ":pyext/_message.so",
653        ],
654    }),
655    default_runtime = "",
656    protoc = ":protoc",
657    py_libs = [
658        ":python_srcs",
659        "//external:six"
660    ],
661    srcs_version = "PY2AND3",
662    visibility = ["//visibility:public"],
663)
664
665# Copy the test proto files from src/google/protobuf to
666# python/google/protobuf. This way, the generated Python sources will be in the
667# same directory as the Python runtime sources. This is necessary for the
668# modules to be imported correctly by the tests since they are all part of the
669# same Python package.
670internal_copied_filegroup(
671    name = "protos_python_test",
672    srcs = LITE_TEST_PROTOS + TEST_PROTOS,
673    strip_prefix = "src",
674    dest = "python",
675)
676
677# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
678# which case we can simply add :protos_python_test in srcs.
679COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
680COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]
681
682py_proto_library(
683    name = "python_common_test_protos",
684    srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
685    include = "python",
686    default_runtime = "",
687    protoc = ":protoc",
688    srcs_version = "PY2AND3",
689    deps = [":protobuf_python"],
690)
691
692py_proto_library(
693    name = "python_specific_test_protos",
694    srcs = glob([
695        "python/google/protobuf/internal/*.proto",
696        "python/google/protobuf/internal/import_test_package/*.proto",
697    ]),
698    include = "python",
699    default_runtime = ":protobuf_python",
700    protoc = ":protoc",
701    srcs_version = "PY2AND3",
702    deps = [":python_common_test_protos"],
703)
704
705py_library(
706    name = "python_tests",
707    srcs = glob(
708        [
709            "python/google/protobuf/internal/*_test.py",
710            "python/google/protobuf/internal/test_util.py",
711            "python/google/protobuf/internal/import_test_package/__init__.py",
712        ],
713    ),
714    imports = ["python"],
715    srcs_version = "PY2AND3",
716    deps = [
717        ":protobuf_python",
718        ":python_common_test_protos",
719        ":python_specific_test_protos",
720    ],
721)
722
723internal_protobuf_py_tests(
724    name = "python_tests_batch",
725    data = glob([
726        "src/google/protobuf/**/*",
727    ]),
728    modules = [
729        "descriptor_database_test",
730        "descriptor_pool_test",
731        "descriptor_test",
732        "generator_test",
733        "json_format_test",
734        "message_factory_test",
735        "message_test",
736        "proto_builder_test",
737        "reflection_test",
738        "service_reflection_test",
739        "symbol_database_test",
740        "text_encoding_test",
741        "text_format_test",
742        "unknown_fields_test",
743        "wire_format_test",
744    ],
745    deps = [":python_tests"],
746)
747