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