blob: ddeeb776cf6bd86bc63591d19fc0d178631b381b [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001# Bazel (http://bazel.io/) BUILD file for Protobuf.
2
3licenses(["notice"])
4
Austin Schuh4f857292018-02-15 23:42:04 -08005load("//tools/build_rules:select.bzl", "compiler_select")
Brian Silverman3fca9d72016-02-20 02:32:51 -05006
Brian Silverman9c614bc2016-02-15 20:20:02 -05007################################################################################
8# Protobuf Runtime Library
9################################################################################
10
11COPTS = [
12 "-DHAVE_PTHREAD",
Brian Silverman3fca9d72016-02-20 02:32:51 -050013 "-DGOOGLE_THIRD_PARTY_PROTOBUF",
Brian Silverman9c614bc2016-02-15 20:20:02 -050014 "-Wall",
15 "-Wwrite-strings",
16 "-Woverloaded-virtual",
17 "-Wno-sign-compare",
Brian Silverman3fca9d72016-02-20 02:32:51 -050018 "-Wno-unused-function",
19 "-Wno-unused-parameter",
20 "-Wno-format-nonliteral",
21 "-Wno-switch-enum",
22 "-Wno-missing-field-initializers",
23 "-Wno-ignored-qualifiers",
24] + compiler_select({
25 "gcc": [
26 "-Wno-error=cast-align",
27 ],
28 "clang": [
29 "-Wno-unused-const-variable",
30 "-Wno-unused-private-field",
31 ],
32})
Brian Silverman9c614bc2016-02-15 20:20:02 -050033
34# Bazel should provide portable link_opts for pthread.
35LINK_OPTS = ["-lpthread"]
36
37load(
Austin Schuh4f857292018-02-15 23:42:04 -080038 ":protobuf.bzl",
Brian Silverman9c614bc2016-02-15 20:20:02 -050039 "cc_proto_library",
40 "py_proto_library",
41 "internal_copied_filegroup",
42 "internal_protobuf_py_tests",
43)
44
45cc_library(
46 name = "protobuf_lite",
47 srcs = [
48 # AUTOGEN(protobuf_lite_srcs)
49 "src/google/protobuf/arena.cc",
50 "src/google/protobuf/arenastring.cc",
51 "src/google/protobuf/extension_set.cc",
52 "src/google/protobuf/generated_message_util.cc",
53 "src/google/protobuf/io/coded_stream.cc",
54 "src/google/protobuf/io/zero_copy_stream.cc",
55 "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
56 "src/google/protobuf/message_lite.cc",
57 "src/google/protobuf/repeated_field.cc",
58 "src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
59 "src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc",
60 "src/google/protobuf/stubs/bytestream.cc",
61 "src/google/protobuf/stubs/common.cc",
62 "src/google/protobuf/stubs/int128.cc",
63 "src/google/protobuf/stubs/once.cc",
64 "src/google/protobuf/stubs/status.cc",
65 "src/google/protobuf/stubs/statusor.cc",
66 "src/google/protobuf/stubs/stringpiece.cc",
67 "src/google/protobuf/stubs/stringprintf.cc",
68 "src/google/protobuf/stubs/structurally_valid.cc",
69 "src/google/protobuf/stubs/strutil.cc",
70 "src/google/protobuf/stubs/time.cc",
71 "src/google/protobuf/wire_format_lite.cc",
72 ],
73 hdrs = glob(["src/google/protobuf/**/*.h"]),
74 copts = COPTS,
75 includes = ["src/"],
76 linkopts = LINK_OPTS,
77 visibility = ["//visibility:public"],
78)
79
80cc_library(
81 name = "protobuf",
82 srcs = [
83 # AUTOGEN(protobuf_srcs)
84 "src/google/protobuf/any.cc",
85 "src/google/protobuf/any.pb.cc",
86 "src/google/protobuf/api.pb.cc",
87 "src/google/protobuf/compiler/importer.cc",
88 "src/google/protobuf/compiler/parser.cc",
89 "src/google/protobuf/descriptor.cc",
90 "src/google/protobuf/descriptor.pb.cc",
91 "src/google/protobuf/descriptor_database.cc",
92 "src/google/protobuf/duration.pb.cc",
93 "src/google/protobuf/dynamic_message.cc",
94 "src/google/protobuf/empty.pb.cc",
95 "src/google/protobuf/extension_set_heavy.cc",
96 "src/google/protobuf/field_mask.pb.cc",
97 "src/google/protobuf/generated_message_reflection.cc",
98 "src/google/protobuf/io/gzip_stream.cc",
99 "src/google/protobuf/io/printer.cc",
100 "src/google/protobuf/io/strtod.cc",
101 "src/google/protobuf/io/tokenizer.cc",
102 "src/google/protobuf/io/zero_copy_stream_impl.cc",
103 "src/google/protobuf/map_field.cc",
104 "src/google/protobuf/message.cc",
105 "src/google/protobuf/reflection_ops.cc",
106 "src/google/protobuf/service.cc",
107 "src/google/protobuf/source_context.pb.cc",
108 "src/google/protobuf/struct.pb.cc",
109 "src/google/protobuf/stubs/mathlimits.cc",
110 "src/google/protobuf/stubs/substitute.cc",
111 "src/google/protobuf/text_format.cc",
112 "src/google/protobuf/timestamp.pb.cc",
113 "src/google/protobuf/type.pb.cc",
114 "src/google/protobuf/unknown_field_set.cc",
115 "src/google/protobuf/util/field_comparator.cc",
116 "src/google/protobuf/util/field_mask_util.cc",
117 "src/google/protobuf/util/internal/datapiece.cc",
118 "src/google/protobuf/util/internal/default_value_objectwriter.cc",
119 "src/google/protobuf/util/internal/error_listener.cc",
120 "src/google/protobuf/util/internal/field_mask_utility.cc",
121 "src/google/protobuf/util/internal/json_escaping.cc",
122 "src/google/protobuf/util/internal/json_objectwriter.cc",
123 "src/google/protobuf/util/internal/json_stream_parser.cc",
124 "src/google/protobuf/util/internal/object_writer.cc",
125 "src/google/protobuf/util/internal/proto_writer.cc",
126 "src/google/protobuf/util/internal/protostream_objectsource.cc",
127 "src/google/protobuf/util/internal/protostream_objectwriter.cc",
128 "src/google/protobuf/util/internal/type_info.cc",
129 "src/google/protobuf/util/internal/type_info_test_helper.cc",
130 "src/google/protobuf/util/internal/utility.cc",
131 "src/google/protobuf/util/json_util.cc",
132 "src/google/protobuf/util/message_differencer.cc",
133 "src/google/protobuf/util/time_util.cc",
134 "src/google/protobuf/util/type_resolver_util.cc",
135 "src/google/protobuf/wire_format.cc",
136 "src/google/protobuf/wrappers.pb.cc",
137 ],
138 hdrs = glob(["src/**/*.h"]),
139 copts = COPTS,
140 includes = ["src/"],
141 linkopts = LINK_OPTS,
142 visibility = ["//visibility:public"],
143 deps = [":protobuf_lite"],
144)
145
Brian Silverman3fca9d72016-02-20 02:32:51 -0500146'''
Brian Silverman9c614bc2016-02-15 20:20:02 -0500147objc_library(
148 name = "protobuf_objc",
149 hdrs = ["objectivec/GPBProtocolBuffers.h"],
150 includes = ["objectivec"],
151 non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
152 visibility = ["//visibility:public"],
153)
Brian Silverman3fca9d72016-02-20 02:32:51 -0500154'''
Brian Silverman9c614bc2016-02-15 20:20:02 -0500155
156RELATIVE_WELL_KNOWN_PROTOS = [
157 # AUTOGEN(well_known_protos)
158 "google/protobuf/any.proto",
159 "google/protobuf/api.proto",
160 "google/protobuf/compiler/plugin.proto",
161 "google/protobuf/descriptor.proto",
162 "google/protobuf/duration.proto",
163 "google/protobuf/empty.proto",
164 "google/protobuf/field_mask.proto",
165 "google/protobuf/source_context.proto",
166 "google/protobuf/struct.proto",
167 "google/protobuf/timestamp.proto",
168 "google/protobuf/type.proto",
169 "google/protobuf/wrappers.proto",
170]
171
172WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
173
Brian Silvermaneb16fa42016-02-20 15:29:56 -0500174filegroup(
175 name = "well_known_protos",
176 srcs = WELL_KNOWN_PROTOS,
177 visibility = ["//visibility:public"],
178)
179
Brian Silverman9c614bc2016-02-15 20:20:02 -0500180cc_proto_library(
181 name = "cc_wkt_protos",
182 srcs = WELL_KNOWN_PROTOS,
183 include = "src",
184 default_runtime = ":protobuf",
185 internal_bootstrap_hack = 1,
186 protoc = ":protoc",
187 visibility = ["//visibility:public"],
188)
189
190################################################################################
191# Protocol Buffers Compiler
192################################################################################
193
194cc_library(
195 name = "protoc_lib",
196 srcs = [
197 # AUTOGEN(protoc_lib_srcs)
198 "src/google/protobuf/compiler/code_generator.cc",
199 "src/google/protobuf/compiler/command_line_interface.cc",
200 "src/google/protobuf/compiler/cpp/cpp_enum.cc",
201 "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
202 "src/google/protobuf/compiler/cpp/cpp_extension.cc",
203 "src/google/protobuf/compiler/cpp/cpp_field.cc",
204 "src/google/protobuf/compiler/cpp/cpp_file.cc",
205 "src/google/protobuf/compiler/cpp/cpp_generator.cc",
206 "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
207 "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
208 "src/google/protobuf/compiler/cpp/cpp_message.cc",
209 "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
210 "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
211 "src/google/protobuf/compiler/cpp/cpp_service.cc",
212 "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
213 "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
214 "src/google/protobuf/compiler/csharp/csharp_enum.cc",
215 "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
216 "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
217 "src/google/protobuf/compiler/csharp/csharp_generator.cc",
218 "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
219 "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
220 "src/google/protobuf/compiler/csharp/csharp_message.cc",
221 "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
222 "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
223 "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
224 "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
225 "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
226 "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
227 "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
228 "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
229 "src/google/protobuf/compiler/java/java_context.cc",
230 "src/google/protobuf/compiler/java/java_doc_comment.cc",
231 "src/google/protobuf/compiler/java/java_enum.cc",
232 "src/google/protobuf/compiler/java/java_enum_field.cc",
233 "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
234 "src/google/protobuf/compiler/java/java_enum_lite.cc",
235 "src/google/protobuf/compiler/java/java_extension.cc",
236 "src/google/protobuf/compiler/java/java_field.cc",
237 "src/google/protobuf/compiler/java/java_file.cc",
238 "src/google/protobuf/compiler/java/java_generator.cc",
239 "src/google/protobuf/compiler/java/java_generator_factory.cc",
240 "src/google/protobuf/compiler/java/java_helpers.cc",
241 "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
242 "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
243 "src/google/protobuf/compiler/java/java_map_field.cc",
244 "src/google/protobuf/compiler/java/java_map_field_lite.cc",
245 "src/google/protobuf/compiler/java/java_message.cc",
246 "src/google/protobuf/compiler/java/java_message_builder.cc",
247 "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
248 "src/google/protobuf/compiler/java/java_message_field.cc",
249 "src/google/protobuf/compiler/java/java_message_field_lite.cc",
250 "src/google/protobuf/compiler/java/java_message_lite.cc",
251 "src/google/protobuf/compiler/java/java_name_resolver.cc",
252 "src/google/protobuf/compiler/java/java_primitive_field.cc",
253 "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
254 "src/google/protobuf/compiler/java/java_service.cc",
255 "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
256 "src/google/protobuf/compiler/java/java_string_field.cc",
257 "src/google/protobuf/compiler/java/java_string_field_lite.cc",
258 "src/google/protobuf/compiler/javanano/javanano_enum.cc",
259 "src/google/protobuf/compiler/javanano/javanano_enum_field.cc",
260 "src/google/protobuf/compiler/javanano/javanano_extension.cc",
261 "src/google/protobuf/compiler/javanano/javanano_field.cc",
262 "src/google/protobuf/compiler/javanano/javanano_file.cc",
263 "src/google/protobuf/compiler/javanano/javanano_generator.cc",
264 "src/google/protobuf/compiler/javanano/javanano_helpers.cc",
265 "src/google/protobuf/compiler/javanano/javanano_map_field.cc",
266 "src/google/protobuf/compiler/javanano/javanano_message.cc",
267 "src/google/protobuf/compiler/javanano/javanano_message_field.cc",
268 "src/google/protobuf/compiler/javanano/javanano_primitive_field.cc",
269 "src/google/protobuf/compiler/js/js_generator.cc",
270 "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
271 "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
272 "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
273 "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
274 "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
275 "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
276 "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
277 "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
278 "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
279 "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
280 "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
281 "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
282 "src/google/protobuf/compiler/plugin.cc",
283 "src/google/protobuf/compiler/plugin.pb.cc",
284 "src/google/protobuf/compiler/python/python_generator.cc",
285 "src/google/protobuf/compiler/ruby/ruby_generator.cc",
286 "src/google/protobuf/compiler/subprocess.cc",
287 "src/google/protobuf/compiler/zip_writer.cc",
288 ],
289 copts = COPTS,
290 includes = ["src/"],
291 linkopts = LINK_OPTS,
292 visibility = ["//visibility:public"],
293 deps = [":protobuf"],
294)
295
296cc_binary(
297 name = "protoc",
298 srcs = ["src/google/protobuf/compiler/main.cc"],
299 linkopts = LINK_OPTS,
300 visibility = ["//visibility:public"],
301 deps = [":protoc_lib"],
302)
303
304################################################################################
305# Tests
306################################################################################
307
308RELATIVE_LITE_TEST_PROTOS = [
309 # AUTOGEN(lite_test_protos)
310 "google/protobuf/map_lite_unittest.proto",
311 "google/protobuf/unittest_import_lite.proto",
312 "google/protobuf/unittest_import_public_lite.proto",
313 "google/protobuf/unittest_lite.proto",
314 "google/protobuf/unittest_no_arena_lite.proto",
315]
316
317LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
318
319RELATIVE_TEST_PROTOS = [
320 # AUTOGEN(test_protos)
321 "google/protobuf/any_test.proto",
322 "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
323 "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
324 "google/protobuf/map_proto2_unittest.proto",
325 "google/protobuf/map_unittest.proto",
326 "google/protobuf/unittest.proto",
327 "google/protobuf/unittest_arena.proto",
328 "google/protobuf/unittest_custom_options.proto",
329 "google/protobuf/unittest_drop_unknown_fields.proto",
330 "google/protobuf/unittest_embed_optimize_for.proto",
331 "google/protobuf/unittest_empty.proto",
332 "google/protobuf/unittest_enormous_descriptor.proto",
333 "google/protobuf/unittest_import.proto",
334 "google/protobuf/unittest_import_public.proto",
335 "google/protobuf/unittest_lite_imports_nonlite.proto",
336 "google/protobuf/unittest_mset.proto",
337 "google/protobuf/unittest_mset_wire_format.proto",
338 "google/protobuf/unittest_no_arena.proto",
339 "google/protobuf/unittest_no_arena_import.proto",
340 "google/protobuf/unittest_no_field_presence.proto",
341 "google/protobuf/unittest_no_generic_services.proto",
342 "google/protobuf/unittest_optimize_for.proto",
343 "google/protobuf/unittest_preserve_unknown_enum.proto",
344 "google/protobuf/unittest_preserve_unknown_enum2.proto",
345 "google/protobuf/unittest_proto3_arena.proto",
346 "google/protobuf/unittest_well_known_types.proto",
347 "google/protobuf/util/internal/testdata/anys.proto",
348 "google/protobuf/util/internal/testdata/books.proto",
349 "google/protobuf/util/internal/testdata/default_value.proto",
350 "google/protobuf/util/internal/testdata/default_value_test.proto",
351 "google/protobuf/util/internal/testdata/field_mask.proto",
352 "google/protobuf/util/internal/testdata/maps.proto",
353 "google/protobuf/util/internal/testdata/oneofs.proto",
354 "google/protobuf/util/internal/testdata/struct.proto",
355 "google/protobuf/util/internal/testdata/timestamp_duration.proto",
356 "google/protobuf/util/json_format_proto3.proto",
357 "google/protobuf/util/message_differencer_unittest.proto",
358]
359
360TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
361
362cc_proto_library(
363 name = "cc_test_protos",
364 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
365 include = "src",
366 default_runtime = ":protobuf",
367 protoc = ":protoc",
368 deps = [":cc_wkt_protos"],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500369 copts = COPTS,
Brian Silverman9c614bc2016-02-15 20:20:02 -0500370)
371
372COMMON_TEST_SRCS = [
373 # AUTOGEN(common_test_srcs)
374 "src/google/protobuf/arena_test_util.cc",
375 "src/google/protobuf/map_test_util.cc",
376 "src/google/protobuf/test_util.cc",
377 "src/google/protobuf/testing/file.cc",
378 "src/google/protobuf/testing/googletest.cc",
379]
380
381cc_binary(
382 name = "test_plugin",
383 srcs = [
384 # AUTOGEN(test_plugin_srcs)
385 "src/google/protobuf/compiler/mock_code_generator.cc",
386 "src/google/protobuf/compiler/test_plugin.cc",
387 "src/google/protobuf/testing/file.cc",
388 ],
389 deps = [
390 ":protobuf",
391 ":protoc_lib",
392 "//external:gtest",
393 ],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500394 copts = COPTS,
Brian Silverman9c614bc2016-02-15 20:20:02 -0500395)
396
397cc_test(
398 name = "protobuf_test",
399 srcs = COMMON_TEST_SRCS + [
400 # AUTOGEN(test_srcs)
401 "src/google/protobuf/any_test.cc",
402 "src/google/protobuf/arena_unittest.cc",
403 "src/google/protobuf/arenastring_unittest.cc",
404 "src/google/protobuf/compiler/command_line_interface_unittest.cc",
405 "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
406 "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
407 "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
408 "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
409 "src/google/protobuf/compiler/importer_unittest.cc",
410 "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
411 "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
412 "src/google/protobuf/compiler/mock_code_generator.cc",
413 "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
414 "src/google/protobuf/compiler/parser_unittest.cc",
415 "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
416 "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
417 "src/google/protobuf/descriptor_database_unittest.cc",
418 "src/google/protobuf/descriptor_unittest.cc",
419 "src/google/protobuf/drop_unknown_fields_test.cc",
420 "src/google/protobuf/dynamic_message_unittest.cc",
421 "src/google/protobuf/extension_set_unittest.cc",
422 "src/google/protobuf/generated_message_reflection_unittest.cc",
423 "src/google/protobuf/io/coded_stream_unittest.cc",
424 "src/google/protobuf/io/printer_unittest.cc",
425 "src/google/protobuf/io/tokenizer_unittest.cc",
426 "src/google/protobuf/io/zero_copy_stream_unittest.cc",
427 "src/google/protobuf/map_field_test.cc",
428 "src/google/protobuf/map_test.cc",
429 "src/google/protobuf/message_unittest.cc",
430 "src/google/protobuf/no_field_presence_test.cc",
431 "src/google/protobuf/preserve_unknown_enum_test.cc",
432 "src/google/protobuf/proto3_arena_unittest.cc",
433 "src/google/protobuf/reflection_ops_unittest.cc",
434 "src/google/protobuf/repeated_field_reflection_unittest.cc",
435 "src/google/protobuf/repeated_field_unittest.cc",
436 "src/google/protobuf/stubs/bytestream_unittest.cc",
437 "src/google/protobuf/stubs/common_unittest.cc",
438 "src/google/protobuf/stubs/int128_unittest.cc",
439 "src/google/protobuf/stubs/once_unittest.cc",
440 "src/google/protobuf/stubs/status_test.cc",
441 "src/google/protobuf/stubs/statusor_test.cc",
442 "src/google/protobuf/stubs/stringpiece_unittest.cc",
443 "src/google/protobuf/stubs/stringprintf_unittest.cc",
444 "src/google/protobuf/stubs/structurally_valid_unittest.cc",
445 "src/google/protobuf/stubs/strutil_unittest.cc",
446 "src/google/protobuf/stubs/template_util_unittest.cc",
447 "src/google/protobuf/stubs/time_test.cc",
448 "src/google/protobuf/stubs/type_traits_unittest.cc",
449 "src/google/protobuf/text_format_unittest.cc",
450 "src/google/protobuf/unknown_field_set_unittest.cc",
451 "src/google/protobuf/util/field_comparator_test.cc",
452 "src/google/protobuf/util/field_mask_util_test.cc",
453 "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
454 "src/google/protobuf/util/internal/json_objectwriter_test.cc",
455 "src/google/protobuf/util/internal/json_stream_parser_test.cc",
456 "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
457 "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
458 "src/google/protobuf/util/internal/type_info_test_helper.cc",
459 "src/google/protobuf/util/json_util_test.cc",
460 "src/google/protobuf/util/message_differencer_unittest.cc",
461 "src/google/protobuf/util/time_util_test.cc",
462 "src/google/protobuf/util/type_resolver_util_test.cc",
463 "src/google/protobuf/well_known_types_unittest.cc",
464 "src/google/protobuf/wire_format_unittest.cc",
465 ],
466 copts = COPTS,
467 data = [
468 ":test_plugin",
469 ] + glob([
470 "src/google/protobuf/**/*",
471 ]),
472 includes = [
473 "src/",
474 ],
475 linkopts = LINK_OPTS,
476 deps = [
477 ":cc_test_protos",
478 ":protobuf",
479 ":protoc_lib",
480 "//external:gtest_main",
481 ],
482)
483
484################################################################################
485# Java support
486################################################################################
487genrule(
488 name = "gen_well_known_protos_java",
489 srcs = WELL_KNOWN_PROTOS,
490 outs = [
491 "wellknown.srcjar"
492 ],
493 cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" +
Brian Silverman3fca9d72016-02-20 02:32:51 -0500494 " -Ithird_party/protobuf/src $(SRCS) " +
Brian Silverman9c614bc2016-02-15 20:20:02 -0500495 " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar",
496 tools = [":protoc"],
497)
498
499java_library(
500 name = "protobuf_java",
501 srcs = glob([
502 "java/core/src/main/java/com/google/protobuf/*.java",
503 ]) + [
504 ":gen_well_known_protos_java",
505 ],
506 visibility = ["//visibility:public"],
507)
508
509################################################################################
510# Python support
511################################################################################
512
513# Hack:
514# protoc generated files contain imports like:
515# "from google.protobuf.xxx import yyy"
516# However, the sources files of the python runtime are not directly under
517# "google/protobuf" (they are under python/google/protobuf). We workaround
518# this by copying runtime source files into the desired location to workaround
519# the import issue. Ideally py_library should support something similiar to the
520# "include" attribute in cc_library to inject the PYTHON_PATH for all libraries
521# that depend on the target.
522#
523# If you use python protobuf as a third_party library in your bazel managed
524# project:
525# 1) Please import the whole package to //google/protobuf in your
526# project. Otherwise, bazel disallows generated files out of the current
527# package, thus we won't be able to copy protobuf runtime files into
528# //google/protobuf/.
529# 2) The runtime also requires "six" for Python2/3 compatibility, please see the
530# WORKSPACE file and bind "six" to your workspace as well.
531internal_copied_filegroup(
532 name = "python_srcs",
533 srcs = glob(
534 [
535 "python/google/protobuf/*.py",
536 "python/google/protobuf/**/*.py",
537 ],
538 exclude = [
539 "python/google/protobuf/internal/*_test.py",
540 "python/google/protobuf/internal/test_util.py",
541 ],
542 ),
543 include = "python",
544)
545
Brian Silverman3fca9d72016-02-20 02:32:51 -0500546'''
Brian Silverman9c614bc2016-02-15 20:20:02 -0500547cc_binary(
548 name = "internal/_api_implementation.so",
549 srcs = ["python/google/protobuf/internal/api_implementation.cc"],
550 copts = COPTS + [
551 "-DPYTHON_PROTO2_CPP_IMPL_V2",
552 ],
553 linkshared = 1,
554 linkstatic = 1,
555 deps = select({
556 "//conditions:default": [],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500557 ":use_fast_cpp_protos": ["//third_party/protobuf/util/python:python_headers"],
Brian Silverman9c614bc2016-02-15 20:20:02 -0500558 }),
559)
560
561cc_binary(
562 name = "pyext/_message.so",
563 srcs = glob([
564 "python/google/protobuf/pyext/*.cc",
565 "python/google/protobuf/pyext/*.h",
566 ]),
567 copts = COPTS + [
568 "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
569 ],
570 includes = [
571 "python/",
572 "src/",
573 ],
574 linkshared = 1,
575 linkstatic = 1,
576 deps = [
577 ":protobuf",
578 ] + select({
579 "//conditions:default": [],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500580 ":use_fast_cpp_protos": ["//third_party/protobuf/util/python:python_headers"],
Brian Silverman9c614bc2016-02-15 20:20:02 -0500581 }),
582)
Brian Silverman3fca9d72016-02-20 02:32:51 -0500583'''
Brian Silverman9c614bc2016-02-15 20:20:02 -0500584
585config_setting(
586 name = "use_fast_cpp_protos",
587 values = {
588 "define": "use_fast_cpp_protos=true",
589 },
590)
591
592py_proto_library(
593 name = "protobuf_python",
594 srcs = WELL_KNOWN_PROTOS,
595 include = "src",
596 data = select({
597 "//conditions:default": [],
598 ":use_fast_cpp_protos": [
599 ":internal/_api_implementation.so",
600 ":pyext/_message.so",
601 ],
602 }),
603 default_runtime = "",
604 protoc = ":protoc",
605 py_extra_srcs = [":python_srcs"],
606 py_libs = ["//external:six"],
607 srcs_version = "PY2AND3",
608 visibility = ["//visibility:public"],
609)
610
611internal_copied_filegroup(
612 name = "python_test_srcs",
613 srcs = glob(
614 [
615 "python/google/protobuf/internal/*_test.py",
616 "python/google/protobuf/internal/test_util.py",
617 ],
618 ),
619 include = "python",
620)
621
622py_proto_library(
623 name = "python_common_test_protos",
624 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
625 include = "src",
626 default_runtime = "",
627 protoc = ":protoc",
628 deps = [":protobuf_python"],
629)
630
631py_proto_library(
632 name = "python_specific_test_protos",
633 srcs = glob([
634 "python/google/protobuf/internal/*.proto",
635 "python/google/protobuf/internal/import_test_package/*.proto",
636 ]),
637 include = "python",
638 default_runtime = ":protobuf_python",
639 protoc = ":protoc",
640 deps = [":python_common_test_protos"],
641)
642
643py_library(
644 name = "python_tests",
645 srcs = [":python_test_srcs"],
646 srcs_version = "PY2AND3",
647 deps = [
648 ":protobuf_python",
649 ":python_common_test_protos",
650 ":python_specific_test_protos",
651 ],
652)
653
654internal_protobuf_py_tests(
655 name = "python_tests_batch",
656 data = glob([
657 "src/google/protobuf/**/*",
658 ]),
659 modules = [
660 "descriptor_database_test",
661 "descriptor_pool_test",
662 "descriptor_test",
663 "generator_test",
664 "json_format_test",
665 "message_factory_test",
666 "message_test",
667 "proto_builder_test",
668 "reflection_test",
669 "service_reflection_test",
670 "symbol_database_test",
671 "text_encoding_test",
672 "text_format_test",
673 "unknown_fields_test",
674 "wire_format_test",
675 ],
676 deps = [":python_tests"],
677)