blob: bb5d889fdd74181f09572a8d931483622ae4aef9 [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001# Bazel (http://bazel.io/) BUILD file for Protobuf.
2
3licenses(["notice"])
4
Brian Silverman3fca9d72016-02-20 02:32:51 -05005load("/tools/build_rules/select", "compiler_select")
6
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(
38 "protobuf",
39 "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
174cc_proto_library(
175 name = "cc_wkt_protos",
176 srcs = WELL_KNOWN_PROTOS,
177 include = "src",
178 default_runtime = ":protobuf",
179 internal_bootstrap_hack = 1,
180 protoc = ":protoc",
181 visibility = ["//visibility:public"],
182)
183
184################################################################################
185# Protocol Buffers Compiler
186################################################################################
187
188cc_library(
189 name = "protoc_lib",
190 srcs = [
191 # AUTOGEN(protoc_lib_srcs)
192 "src/google/protobuf/compiler/code_generator.cc",
193 "src/google/protobuf/compiler/command_line_interface.cc",
194 "src/google/protobuf/compiler/cpp/cpp_enum.cc",
195 "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
196 "src/google/protobuf/compiler/cpp/cpp_extension.cc",
197 "src/google/protobuf/compiler/cpp/cpp_field.cc",
198 "src/google/protobuf/compiler/cpp/cpp_file.cc",
199 "src/google/protobuf/compiler/cpp/cpp_generator.cc",
200 "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
201 "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
202 "src/google/protobuf/compiler/cpp/cpp_message.cc",
203 "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
204 "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
205 "src/google/protobuf/compiler/cpp/cpp_service.cc",
206 "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
207 "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
208 "src/google/protobuf/compiler/csharp/csharp_enum.cc",
209 "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
210 "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
211 "src/google/protobuf/compiler/csharp/csharp_generator.cc",
212 "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
213 "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
214 "src/google/protobuf/compiler/csharp/csharp_message.cc",
215 "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
216 "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
217 "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
218 "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
219 "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
220 "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
221 "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
222 "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
223 "src/google/protobuf/compiler/java/java_context.cc",
224 "src/google/protobuf/compiler/java/java_doc_comment.cc",
225 "src/google/protobuf/compiler/java/java_enum.cc",
226 "src/google/protobuf/compiler/java/java_enum_field.cc",
227 "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
228 "src/google/protobuf/compiler/java/java_enum_lite.cc",
229 "src/google/protobuf/compiler/java/java_extension.cc",
230 "src/google/protobuf/compiler/java/java_field.cc",
231 "src/google/protobuf/compiler/java/java_file.cc",
232 "src/google/protobuf/compiler/java/java_generator.cc",
233 "src/google/protobuf/compiler/java/java_generator_factory.cc",
234 "src/google/protobuf/compiler/java/java_helpers.cc",
235 "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
236 "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
237 "src/google/protobuf/compiler/java/java_map_field.cc",
238 "src/google/protobuf/compiler/java/java_map_field_lite.cc",
239 "src/google/protobuf/compiler/java/java_message.cc",
240 "src/google/protobuf/compiler/java/java_message_builder.cc",
241 "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
242 "src/google/protobuf/compiler/java/java_message_field.cc",
243 "src/google/protobuf/compiler/java/java_message_field_lite.cc",
244 "src/google/protobuf/compiler/java/java_message_lite.cc",
245 "src/google/protobuf/compiler/java/java_name_resolver.cc",
246 "src/google/protobuf/compiler/java/java_primitive_field.cc",
247 "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
248 "src/google/protobuf/compiler/java/java_service.cc",
249 "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
250 "src/google/protobuf/compiler/java/java_string_field.cc",
251 "src/google/protobuf/compiler/java/java_string_field_lite.cc",
252 "src/google/protobuf/compiler/javanano/javanano_enum.cc",
253 "src/google/protobuf/compiler/javanano/javanano_enum_field.cc",
254 "src/google/protobuf/compiler/javanano/javanano_extension.cc",
255 "src/google/protobuf/compiler/javanano/javanano_field.cc",
256 "src/google/protobuf/compiler/javanano/javanano_file.cc",
257 "src/google/protobuf/compiler/javanano/javanano_generator.cc",
258 "src/google/protobuf/compiler/javanano/javanano_helpers.cc",
259 "src/google/protobuf/compiler/javanano/javanano_map_field.cc",
260 "src/google/protobuf/compiler/javanano/javanano_message.cc",
261 "src/google/protobuf/compiler/javanano/javanano_message_field.cc",
262 "src/google/protobuf/compiler/javanano/javanano_primitive_field.cc",
263 "src/google/protobuf/compiler/js/js_generator.cc",
264 "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
265 "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
266 "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
267 "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
268 "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
269 "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
270 "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
271 "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
272 "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
273 "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
274 "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
275 "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
276 "src/google/protobuf/compiler/plugin.cc",
277 "src/google/protobuf/compiler/plugin.pb.cc",
278 "src/google/protobuf/compiler/python/python_generator.cc",
279 "src/google/protobuf/compiler/ruby/ruby_generator.cc",
280 "src/google/protobuf/compiler/subprocess.cc",
281 "src/google/protobuf/compiler/zip_writer.cc",
282 ],
283 copts = COPTS,
284 includes = ["src/"],
285 linkopts = LINK_OPTS,
286 visibility = ["//visibility:public"],
287 deps = [":protobuf"],
288)
289
290cc_binary(
291 name = "protoc",
292 srcs = ["src/google/protobuf/compiler/main.cc"],
293 linkopts = LINK_OPTS,
294 visibility = ["//visibility:public"],
295 deps = [":protoc_lib"],
296)
297
298################################################################################
299# Tests
300################################################################################
301
302RELATIVE_LITE_TEST_PROTOS = [
303 # AUTOGEN(lite_test_protos)
304 "google/protobuf/map_lite_unittest.proto",
305 "google/protobuf/unittest_import_lite.proto",
306 "google/protobuf/unittest_import_public_lite.proto",
307 "google/protobuf/unittest_lite.proto",
308 "google/protobuf/unittest_no_arena_lite.proto",
309]
310
311LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
312
313RELATIVE_TEST_PROTOS = [
314 # AUTOGEN(test_protos)
315 "google/protobuf/any_test.proto",
316 "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
317 "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
318 "google/protobuf/map_proto2_unittest.proto",
319 "google/protobuf/map_unittest.proto",
320 "google/protobuf/unittest.proto",
321 "google/protobuf/unittest_arena.proto",
322 "google/protobuf/unittest_custom_options.proto",
323 "google/protobuf/unittest_drop_unknown_fields.proto",
324 "google/protobuf/unittest_embed_optimize_for.proto",
325 "google/protobuf/unittest_empty.proto",
326 "google/protobuf/unittest_enormous_descriptor.proto",
327 "google/protobuf/unittest_import.proto",
328 "google/protobuf/unittest_import_public.proto",
329 "google/protobuf/unittest_lite_imports_nonlite.proto",
330 "google/protobuf/unittest_mset.proto",
331 "google/protobuf/unittest_mset_wire_format.proto",
332 "google/protobuf/unittest_no_arena.proto",
333 "google/protobuf/unittest_no_arena_import.proto",
334 "google/protobuf/unittest_no_field_presence.proto",
335 "google/protobuf/unittest_no_generic_services.proto",
336 "google/protobuf/unittest_optimize_for.proto",
337 "google/protobuf/unittest_preserve_unknown_enum.proto",
338 "google/protobuf/unittest_preserve_unknown_enum2.proto",
339 "google/protobuf/unittest_proto3_arena.proto",
340 "google/protobuf/unittest_well_known_types.proto",
341 "google/protobuf/util/internal/testdata/anys.proto",
342 "google/protobuf/util/internal/testdata/books.proto",
343 "google/protobuf/util/internal/testdata/default_value.proto",
344 "google/protobuf/util/internal/testdata/default_value_test.proto",
345 "google/protobuf/util/internal/testdata/field_mask.proto",
346 "google/protobuf/util/internal/testdata/maps.proto",
347 "google/protobuf/util/internal/testdata/oneofs.proto",
348 "google/protobuf/util/internal/testdata/struct.proto",
349 "google/protobuf/util/internal/testdata/timestamp_duration.proto",
350 "google/protobuf/util/json_format_proto3.proto",
351 "google/protobuf/util/message_differencer_unittest.proto",
352]
353
354TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
355
356cc_proto_library(
357 name = "cc_test_protos",
358 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
359 include = "src",
360 default_runtime = ":protobuf",
361 protoc = ":protoc",
362 deps = [":cc_wkt_protos"],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500363 copts = COPTS,
Brian Silverman9c614bc2016-02-15 20:20:02 -0500364)
365
366COMMON_TEST_SRCS = [
367 # AUTOGEN(common_test_srcs)
368 "src/google/protobuf/arena_test_util.cc",
369 "src/google/protobuf/map_test_util.cc",
370 "src/google/protobuf/test_util.cc",
371 "src/google/protobuf/testing/file.cc",
372 "src/google/protobuf/testing/googletest.cc",
373]
374
375cc_binary(
376 name = "test_plugin",
377 srcs = [
378 # AUTOGEN(test_plugin_srcs)
379 "src/google/protobuf/compiler/mock_code_generator.cc",
380 "src/google/protobuf/compiler/test_plugin.cc",
381 "src/google/protobuf/testing/file.cc",
382 ],
383 deps = [
384 ":protobuf",
385 ":protoc_lib",
386 "//external:gtest",
387 ],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500388 copts = COPTS,
Brian Silverman9c614bc2016-02-15 20:20:02 -0500389)
390
391cc_test(
392 name = "protobuf_test",
393 srcs = COMMON_TEST_SRCS + [
394 # AUTOGEN(test_srcs)
395 "src/google/protobuf/any_test.cc",
396 "src/google/protobuf/arena_unittest.cc",
397 "src/google/protobuf/arenastring_unittest.cc",
398 "src/google/protobuf/compiler/command_line_interface_unittest.cc",
399 "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
400 "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
401 "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
402 "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
403 "src/google/protobuf/compiler/importer_unittest.cc",
404 "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
405 "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
406 "src/google/protobuf/compiler/mock_code_generator.cc",
407 "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
408 "src/google/protobuf/compiler/parser_unittest.cc",
409 "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
410 "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
411 "src/google/protobuf/descriptor_database_unittest.cc",
412 "src/google/protobuf/descriptor_unittest.cc",
413 "src/google/protobuf/drop_unknown_fields_test.cc",
414 "src/google/protobuf/dynamic_message_unittest.cc",
415 "src/google/protobuf/extension_set_unittest.cc",
416 "src/google/protobuf/generated_message_reflection_unittest.cc",
417 "src/google/protobuf/io/coded_stream_unittest.cc",
418 "src/google/protobuf/io/printer_unittest.cc",
419 "src/google/protobuf/io/tokenizer_unittest.cc",
420 "src/google/protobuf/io/zero_copy_stream_unittest.cc",
421 "src/google/protobuf/map_field_test.cc",
422 "src/google/protobuf/map_test.cc",
423 "src/google/protobuf/message_unittest.cc",
424 "src/google/protobuf/no_field_presence_test.cc",
425 "src/google/protobuf/preserve_unknown_enum_test.cc",
426 "src/google/protobuf/proto3_arena_unittest.cc",
427 "src/google/protobuf/reflection_ops_unittest.cc",
428 "src/google/protobuf/repeated_field_reflection_unittest.cc",
429 "src/google/protobuf/repeated_field_unittest.cc",
430 "src/google/protobuf/stubs/bytestream_unittest.cc",
431 "src/google/protobuf/stubs/common_unittest.cc",
432 "src/google/protobuf/stubs/int128_unittest.cc",
433 "src/google/protobuf/stubs/once_unittest.cc",
434 "src/google/protobuf/stubs/status_test.cc",
435 "src/google/protobuf/stubs/statusor_test.cc",
436 "src/google/protobuf/stubs/stringpiece_unittest.cc",
437 "src/google/protobuf/stubs/stringprintf_unittest.cc",
438 "src/google/protobuf/stubs/structurally_valid_unittest.cc",
439 "src/google/protobuf/stubs/strutil_unittest.cc",
440 "src/google/protobuf/stubs/template_util_unittest.cc",
441 "src/google/protobuf/stubs/time_test.cc",
442 "src/google/protobuf/stubs/type_traits_unittest.cc",
443 "src/google/protobuf/text_format_unittest.cc",
444 "src/google/protobuf/unknown_field_set_unittest.cc",
445 "src/google/protobuf/util/field_comparator_test.cc",
446 "src/google/protobuf/util/field_mask_util_test.cc",
447 "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
448 "src/google/protobuf/util/internal/json_objectwriter_test.cc",
449 "src/google/protobuf/util/internal/json_stream_parser_test.cc",
450 "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
451 "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
452 "src/google/protobuf/util/internal/type_info_test_helper.cc",
453 "src/google/protobuf/util/json_util_test.cc",
454 "src/google/protobuf/util/message_differencer_unittest.cc",
455 "src/google/protobuf/util/time_util_test.cc",
456 "src/google/protobuf/util/type_resolver_util_test.cc",
457 "src/google/protobuf/well_known_types_unittest.cc",
458 "src/google/protobuf/wire_format_unittest.cc",
459 ],
460 copts = COPTS,
461 data = [
462 ":test_plugin",
463 ] + glob([
464 "src/google/protobuf/**/*",
465 ]),
466 includes = [
467 "src/",
468 ],
469 linkopts = LINK_OPTS,
470 deps = [
471 ":cc_test_protos",
472 ":protobuf",
473 ":protoc_lib",
474 "//external:gtest_main",
475 ],
476)
477
478################################################################################
479# Java support
480################################################################################
481genrule(
482 name = "gen_well_known_protos_java",
483 srcs = WELL_KNOWN_PROTOS,
484 outs = [
485 "wellknown.srcjar"
486 ],
487 cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" +
Brian Silverman3fca9d72016-02-20 02:32:51 -0500488 " -Ithird_party/protobuf/src $(SRCS) " +
Brian Silverman9c614bc2016-02-15 20:20:02 -0500489 " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar",
490 tools = [":protoc"],
491)
492
493java_library(
494 name = "protobuf_java",
495 srcs = glob([
496 "java/core/src/main/java/com/google/protobuf/*.java",
497 ]) + [
498 ":gen_well_known_protos_java",
499 ],
500 visibility = ["//visibility:public"],
501)
502
503################################################################################
504# Python support
505################################################################################
506
507# Hack:
508# protoc generated files contain imports like:
509# "from google.protobuf.xxx import yyy"
510# However, the sources files of the python runtime are not directly under
511# "google/protobuf" (they are under python/google/protobuf). We workaround
512# this by copying runtime source files into the desired location to workaround
513# the import issue. Ideally py_library should support something similiar to the
514# "include" attribute in cc_library to inject the PYTHON_PATH for all libraries
515# that depend on the target.
516#
517# If you use python protobuf as a third_party library in your bazel managed
518# project:
519# 1) Please import the whole package to //google/protobuf in your
520# project. Otherwise, bazel disallows generated files out of the current
521# package, thus we won't be able to copy protobuf runtime files into
522# //google/protobuf/.
523# 2) The runtime also requires "six" for Python2/3 compatibility, please see the
524# WORKSPACE file and bind "six" to your workspace as well.
525internal_copied_filegroup(
526 name = "python_srcs",
527 srcs = glob(
528 [
529 "python/google/protobuf/*.py",
530 "python/google/protobuf/**/*.py",
531 ],
532 exclude = [
533 "python/google/protobuf/internal/*_test.py",
534 "python/google/protobuf/internal/test_util.py",
535 ],
536 ),
537 include = "python",
538)
539
Brian Silverman3fca9d72016-02-20 02:32:51 -0500540'''
Brian Silverman9c614bc2016-02-15 20:20:02 -0500541cc_binary(
542 name = "internal/_api_implementation.so",
543 srcs = ["python/google/protobuf/internal/api_implementation.cc"],
544 copts = COPTS + [
545 "-DPYTHON_PROTO2_CPP_IMPL_V2",
546 ],
547 linkshared = 1,
548 linkstatic = 1,
549 deps = select({
550 "//conditions:default": [],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500551 ":use_fast_cpp_protos": ["//third_party/protobuf/util/python:python_headers"],
Brian Silverman9c614bc2016-02-15 20:20:02 -0500552 }),
553)
554
555cc_binary(
556 name = "pyext/_message.so",
557 srcs = glob([
558 "python/google/protobuf/pyext/*.cc",
559 "python/google/protobuf/pyext/*.h",
560 ]),
561 copts = COPTS + [
562 "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
563 ],
564 includes = [
565 "python/",
566 "src/",
567 ],
568 linkshared = 1,
569 linkstatic = 1,
570 deps = [
571 ":protobuf",
572 ] + select({
573 "//conditions:default": [],
Brian Silverman3fca9d72016-02-20 02:32:51 -0500574 ":use_fast_cpp_protos": ["//third_party/protobuf/util/python:python_headers"],
Brian Silverman9c614bc2016-02-15 20:20:02 -0500575 }),
576)
Brian Silverman3fca9d72016-02-20 02:32:51 -0500577'''
Brian Silverman9c614bc2016-02-15 20:20:02 -0500578
579config_setting(
580 name = "use_fast_cpp_protos",
581 values = {
582 "define": "use_fast_cpp_protos=true",
583 },
584)
585
586py_proto_library(
587 name = "protobuf_python",
588 srcs = WELL_KNOWN_PROTOS,
589 include = "src",
590 data = select({
591 "//conditions:default": [],
592 ":use_fast_cpp_protos": [
593 ":internal/_api_implementation.so",
594 ":pyext/_message.so",
595 ],
596 }),
597 default_runtime = "",
598 protoc = ":protoc",
599 py_extra_srcs = [":python_srcs"],
600 py_libs = ["//external:six"],
601 srcs_version = "PY2AND3",
602 visibility = ["//visibility:public"],
603)
604
605internal_copied_filegroup(
606 name = "python_test_srcs",
607 srcs = glob(
608 [
609 "python/google/protobuf/internal/*_test.py",
610 "python/google/protobuf/internal/test_util.py",
611 ],
612 ),
613 include = "python",
614)
615
616py_proto_library(
617 name = "python_common_test_protos",
618 srcs = LITE_TEST_PROTOS + TEST_PROTOS,
619 include = "src",
620 default_runtime = "",
621 protoc = ":protoc",
622 deps = [":protobuf_python"],
623)
624
625py_proto_library(
626 name = "python_specific_test_protos",
627 srcs = glob([
628 "python/google/protobuf/internal/*.proto",
629 "python/google/protobuf/internal/import_test_package/*.proto",
630 ]),
631 include = "python",
632 default_runtime = ":protobuf_python",
633 protoc = ":protoc",
634 deps = [":python_common_test_protos"],
635)
636
637py_library(
638 name = "python_tests",
639 srcs = [":python_test_srcs"],
640 srcs_version = "PY2AND3",
641 deps = [
642 ":protobuf_python",
643 ":python_common_test_protos",
644 ":python_specific_test_protos",
645 ],
646)
647
648internal_protobuf_py_tests(
649 name = "python_tests_batch",
650 data = glob([
651 "src/google/protobuf/**/*",
652 ]),
653 modules = [
654 "descriptor_database_test",
655 "descriptor_pool_test",
656 "descriptor_test",
657 "generator_test",
658 "json_format_test",
659 "message_factory_test",
660 "message_test",
661 "proto_builder_test",
662 "reflection_test",
663 "service_reflection_test",
664 "symbol_database_test",
665 "text_encoding_test",
666 "text_format_test",
667 "unknown_fields_test",
668 "wire_format_test",
669 ],
670 deps = [":python_tests"],
671)