BUILD 29.2 KB
Newer Older
1 2 3 4
# Bazel (http://bazel.io/) BUILD file for Protobuf.

licenses(["notice"])

5 6
exports_files(["LICENSE"])

7 8 9 10
################################################################################
# Protobuf Runtime Library
################################################################################

11 12 13 14 15 16
COPTS = [
    "-DHAVE_PTHREAD",
    "-Wall",
    "-Wwrite-strings",
    "-Woverloaded-virtual",
    "-Wno-sign-compare",
17
    "-Wno-unused-function",
18 19
]

20 21 22 23 24 25 26 27 28
config_setting(
    name = "android",
    values = {
        "crosstool_top": "//external:android/crosstool",
    },
)

# Android builds do not need to link in a separate pthread library.
LINK_OPTS = select({
Andrew Harp's avatar
Andrew Harp committed
29
    ":android": [],
Daniel Ylitalo's avatar
Daniel Ylitalo committed
30
    "//conditions:default": ["-lpthread", "-lm"],
31
})
32

33
load(
34
    ":protobuf.bzl",
35 36
    "cc_proto_library",
    "py_proto_library",
37
    "internal_copied_filegroup",
38
    "internal_gen_well_known_protos_java",
39 40
    "internal_protobuf_py_tests",
)
41

42
config_setting(
43
    name = "ios_armv7",
44 45
    values = {
        "ios_cpu": "armv7",
46 47 48 49 50 51
    },
)

config_setting(
    name = "ios_armv7s",
    values = {
52
        "ios_cpu": "armv7s",
53 54 55 56 57 58
    },
)

config_setting(
    name = "ios_arm64",
    values = {
59 60 61 62 63 64 65 66 67 68 69 70 71 72
        "ios_cpu": "arm64",
    },
)

IOS_ARM_COPTS = COPTS + [
    "-DOS_IOS",
    "-miphoneos-version-min=7.0",
    "-arch armv7",
    "-arch armv7s",
    "-arch arm64",
    "-D__thread=",
    "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/",
]

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
cc_library(
    name = "protobuf_lite",
    srcs = [
        # AUTOGEN(protobuf_lite_srcs)
        "src/google/protobuf/arena.cc",
        "src/google/protobuf/arenastring.cc",
        "src/google/protobuf/extension_set.cc",
        "src/google/protobuf/generated_message_util.cc",
        "src/google/protobuf/io/coded_stream.cc",
        "src/google/protobuf/io/zero_copy_stream.cc",
        "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
        "src/google/protobuf/message_lite.cc",
        "src/google/protobuf/repeated_field.cc",
        "src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
        "src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc",
88
        "src/google/protobuf/stubs/bytestream.cc",
89
        "src/google/protobuf/stubs/common.cc",
90
        "src/google/protobuf/stubs/int128.cc",
91
        "src/google/protobuf/stubs/once.cc",
92 93 94
        "src/google/protobuf/stubs/status.cc",
        "src/google/protobuf/stubs/statusor.cc",
        "src/google/protobuf/stubs/stringpiece.cc",
95
        "src/google/protobuf/stubs/stringprintf.cc",
96
        "src/google/protobuf/stubs/structurally_valid.cc",
97 98
        "src/google/protobuf/stubs/strutil.cc",
        "src/google/protobuf/stubs/time.cc",
99 100
        "src/google/protobuf/wire_format_lite.cc",
    ],
101
    hdrs = glob(["src/google/protobuf/**/*.h"]),
102
    copts = select({
103 104 105
        ":ios_armv7": IOS_ARM_COPTS,
        ":ios_armv7s": IOS_ARM_COPTS,
        ":ios_arm64": IOS_ARM_COPTS,
106 107
        "//conditions:default": COPTS,
    }),
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
)

cc_library(
    name = "protobuf",
    srcs = [
        # AUTOGEN(protobuf_srcs)
        "src/google/protobuf/any.cc",
        "src/google/protobuf/any.pb.cc",
        "src/google/protobuf/api.pb.cc",
        "src/google/protobuf/compiler/importer.cc",
        "src/google/protobuf/compiler/parser.cc",
        "src/google/protobuf/descriptor.cc",
        "src/google/protobuf/descriptor.pb.cc",
        "src/google/protobuf/descriptor_database.cc",
        "src/google/protobuf/duration.pb.cc",
        "src/google/protobuf/dynamic_message.cc",
        "src/google/protobuf/empty.pb.cc",
        "src/google/protobuf/extension_set_heavy.cc",
        "src/google/protobuf/field_mask.pb.cc",
        "src/google/protobuf/generated_message_reflection.cc",
        "src/google/protobuf/io/gzip_stream.cc",
        "src/google/protobuf/io/printer.cc",
        "src/google/protobuf/io/strtod.cc",
        "src/google/protobuf/io/tokenizer.cc",
        "src/google/protobuf/io/zero_copy_stream_impl.cc",
        "src/google/protobuf/map_field.cc",
        "src/google/protobuf/message.cc",
        "src/google/protobuf/reflection_ops.cc",
        "src/google/protobuf/service.cc",
        "src/google/protobuf/source_context.pb.cc",
        "src/google/protobuf/struct.pb.cc",
142
        "src/google/protobuf/stubs/mathlimits.cc",
143 144 145 146 147
        "src/google/protobuf/stubs/substitute.cc",
        "src/google/protobuf/text_format.cc",
        "src/google/protobuf/timestamp.pb.cc",
        "src/google/protobuf/type.pb.cc",
        "src/google/protobuf/unknown_field_set.cc",
148
        "src/google/protobuf/util/field_comparator.cc",
149
        "src/google/protobuf/util/field_mask_util.cc",
150 151 152 153 154 155 156 157
        "src/google/protobuf/util/internal/datapiece.cc",
        "src/google/protobuf/util/internal/default_value_objectwriter.cc",
        "src/google/protobuf/util/internal/error_listener.cc",
        "src/google/protobuf/util/internal/field_mask_utility.cc",
        "src/google/protobuf/util/internal/json_escaping.cc",
        "src/google/protobuf/util/internal/json_objectwriter.cc",
        "src/google/protobuf/util/internal/json_stream_parser.cc",
        "src/google/protobuf/util/internal/object_writer.cc",
Feng Xiao's avatar
Feng Xiao committed
158
        "src/google/protobuf/util/internal/proto_writer.cc",
159 160 161 162 163 164 165
        "src/google/protobuf/util/internal/protostream_objectsource.cc",
        "src/google/protobuf/util/internal/protostream_objectwriter.cc",
        "src/google/protobuf/util/internal/type_info.cc",
        "src/google/protobuf/util/internal/type_info_test_helper.cc",
        "src/google/protobuf/util/internal/utility.cc",
        "src/google/protobuf/util/json_util.cc",
        "src/google/protobuf/util/message_differencer.cc",
166
        "src/google/protobuf/util/time_util.cc",
167
        "src/google/protobuf/util/type_resolver_util.cc",
168 169 170
        "src/google/protobuf/wire_format.cc",
        "src/google/protobuf/wrappers.pb.cc",
    ],
Lukacs T. Berki's avatar
Lukacs T. Berki committed
171
    hdrs = glob(["src/**/*.h"]),
172
    copts = select({
173 174 175
        ":ios_armv7": IOS_ARM_COPTS,
        ":ios_armv7s": IOS_ARM_COPTS,
        ":ios_arm64": IOS_ARM_COPTS,
176 177
        "//conditions:default": COPTS,
    }),
178 179 180 181 182 183
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
    deps = [":protobuf_lite"],
)

Jisi Liu's avatar
Jisi Liu committed
184 185 186 187 188 189 190
objc_library(
    name = "protobuf_objc",
    hdrs = ["objectivec/GPBProtocolBuffers.h"],
    includes = ["objectivec"],
    non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
    visibility = ["//visibility:public"],
)
191

Jisi Liu's avatar
Jisi Liu committed
192
RELATIVE_WELL_KNOWN_PROTOS = [
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
    # AUTOGEN(well_known_protos)
    "google/protobuf/any.proto",
    "google/protobuf/api.proto",
    "google/protobuf/compiler/plugin.proto",
    "google/protobuf/descriptor.proto",
    "google/protobuf/duration.proto",
    "google/protobuf/empty.proto",
    "google/protobuf/field_mask.proto",
    "google/protobuf/source_context.proto",
    "google/protobuf/struct.proto",
    "google/protobuf/timestamp.proto",
    "google/protobuf/type.proto",
    "google/protobuf/wrappers.proto",
]

Jisi Liu's avatar
Jisi Liu committed
208 209
WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]

210 211 212 213 214 215
filegroup(
    name = "well_known_protos",
    srcs = WELL_KNOWN_PROTOS,
    visibility = ["//visibility:public"],
)

216 217
cc_proto_library(
    name = "cc_wkt_protos",
Jisi Liu's avatar
Jisi Liu committed
218
    srcs = WELL_KNOWN_PROTOS,
219
    include = "src",
220
    default_runtime = ":protobuf",
Jisi Liu's avatar
Jisi Liu committed
221
    internal_bootstrap_hack = 1,
222
    protoc = ":protoc",
223
    visibility = ["//visibility:public"],
224 225
)

226 227 228 229
################################################################################
# Protocol Buffers Compiler
################################################################################

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
cc_binary(
    name = "js_embed",
    srcs = ["src/google/protobuf/compiler/js/embed.cc"],
    visibility = ["//visibility:public"],
)

genrule(
    name = "generate_js_well_known_types_embed",
    srcs = [
        "src/google/protobuf/compiler/js/well_known_types/any.js",
        "src/google/protobuf/compiler/js/well_known_types/struct.js",
        "src/google/protobuf/compiler/js/well_known_types/timestamp.js",
    ],
    outs = ["src/google/protobuf/compiler/js/well_known_types_embed.cc"],
    cmd = "$(location :js_embed) $(SRCS) > $@",
    tools = [":js_embed"],
)

248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
cc_library(
    name = "protoc_lib",
    srcs = [
        # AUTOGEN(protoc_lib_srcs)
        "src/google/protobuf/compiler/code_generator.cc",
        "src/google/protobuf/compiler/command_line_interface.cc",
        "src/google/protobuf/compiler/cpp/cpp_enum.cc",
        "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_extension.cc",
        "src/google/protobuf/compiler/cpp/cpp_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_file.cc",
        "src/google/protobuf/compiler/cpp/cpp_generator.cc",
        "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
        "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_message.cc",
        "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
        "src/google/protobuf/compiler/cpp/cpp_service.cc",
        "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
267
        "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
268 269 270 271 272
        "src/google/protobuf/compiler/csharp/csharp_enum.cc",
        "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
        "src/google/protobuf/compiler/csharp/csharp_generator.cc",
        "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
273
        "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
274 275 276
        "src/google/protobuf/compiler/csharp/csharp_message.cc",
        "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
277
        "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
278 279 280 281
        "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
        "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
282
        "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
283 284 285 286 287
        "src/google/protobuf/compiler/java/java_context.cc",
        "src/google/protobuf/compiler/java/java_doc_comment.cc",
        "src/google/protobuf/compiler/java/java_enum.cc",
        "src/google/protobuf/compiler/java/java_enum_field.cc",
        "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
288
        "src/google/protobuf/compiler/java/java_enum_lite.cc",
289
        "src/google/protobuf/compiler/java/java_extension.cc",
290
        "src/google/protobuf/compiler/java/java_extension_lite.cc",
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
        "src/google/protobuf/compiler/java/java_field.cc",
        "src/google/protobuf/compiler/java/java_file.cc",
        "src/google/protobuf/compiler/java/java_generator.cc",
        "src/google/protobuf/compiler/java/java_generator_factory.cc",
        "src/google/protobuf/compiler/java/java_helpers.cc",
        "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
        "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
        "src/google/protobuf/compiler/java/java_map_field.cc",
        "src/google/protobuf/compiler/java/java_map_field_lite.cc",
        "src/google/protobuf/compiler/java/java_message.cc",
        "src/google/protobuf/compiler/java/java_message_builder.cc",
        "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
        "src/google/protobuf/compiler/java/java_message_field.cc",
        "src/google/protobuf/compiler/java/java_message_field_lite.cc",
        "src/google/protobuf/compiler/java/java_message_lite.cc",
        "src/google/protobuf/compiler/java/java_name_resolver.cc",
        "src/google/protobuf/compiler/java/java_primitive_field.cc",
        "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
        "src/google/protobuf/compiler/java/java_service.cc",
        "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
        "src/google/protobuf/compiler/java/java_string_field.cc",
        "src/google/protobuf/compiler/java/java_string_field_lite.cc",
        "src/google/protobuf/compiler/javanano/javanano_enum.cc",
        "src/google/protobuf/compiler/javanano/javanano_enum_field.cc",
        "src/google/protobuf/compiler/javanano/javanano_extension.cc",
        "src/google/protobuf/compiler/javanano/javanano_field.cc",
        "src/google/protobuf/compiler/javanano/javanano_file.cc",
        "src/google/protobuf/compiler/javanano/javanano_generator.cc",
        "src/google/protobuf/compiler/javanano/javanano_helpers.cc",
        "src/google/protobuf/compiler/javanano/javanano_map_field.cc",
        "src/google/protobuf/compiler/javanano/javanano_message.cc",
        "src/google/protobuf/compiler/javanano/javanano_message_field.cc",
        "src/google/protobuf/compiler/javanano/javanano_primitive_field.cc",
Feng Xiao's avatar
Feng Xiao committed
324
        "src/google/protobuf/compiler/js/js_generator.cc",
Jisi Liu's avatar
Jisi Liu committed
325
        "src/google/protobuf/compiler/js/well_known_types_embed.cc",
326 327 328 329 330 331 332 333 334 335 336 337
        "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
338
        "src/google/protobuf/compiler/php/php_generator.cc",
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
        "src/google/protobuf/compiler/plugin.cc",
        "src/google/protobuf/compiler/plugin.pb.cc",
        "src/google/protobuf/compiler/python/python_generator.cc",
        "src/google/protobuf/compiler/ruby/ruby_generator.cc",
        "src/google/protobuf/compiler/subprocess.cc",
        "src/google/protobuf/compiler/zip_writer.cc",
    ],
    copts = COPTS,
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
    deps = [":protobuf"],
)

cc_binary(
    name = "protoc",
    srcs = ["src/google/protobuf/compiler/main.cc"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
    deps = [":protoc_lib"],
)

################################################################################
# Tests
################################################################################

Jisi Liu's avatar
Jisi Liu committed
365
RELATIVE_LITE_TEST_PROTOS = [
366 367 368 369 370
    # AUTOGEN(lite_test_protos)
    "google/protobuf/map_lite_unittest.proto",
    "google/protobuf/unittest_import_lite.proto",
    "google/protobuf/unittest_import_public_lite.proto",
    "google/protobuf/unittest_lite.proto",
371
    "google/protobuf/unittest_no_arena_lite.proto",
372 373
]

Jisi Liu's avatar
Jisi Liu committed
374 375 376
LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]

RELATIVE_TEST_PROTOS = [
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
    # AUTOGEN(test_protos)
    "google/protobuf/any_test.proto",
    "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
    "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
    "google/protobuf/map_proto2_unittest.proto",
    "google/protobuf/map_unittest.proto",
    "google/protobuf/unittest.proto",
    "google/protobuf/unittest_arena.proto",
    "google/protobuf/unittest_custom_options.proto",
    "google/protobuf/unittest_drop_unknown_fields.proto",
    "google/protobuf/unittest_embed_optimize_for.proto",
    "google/protobuf/unittest_empty.proto",
    "google/protobuf/unittest_enormous_descriptor.proto",
    "google/protobuf/unittest_import.proto",
    "google/protobuf/unittest_import_public.proto",
    "google/protobuf/unittest_lite_imports_nonlite.proto",
    "google/protobuf/unittest_mset.proto",
394
    "google/protobuf/unittest_mset_wire_format.proto",
395 396 397 398 399 400 401 402
    "google/protobuf/unittest_no_arena.proto",
    "google/protobuf/unittest_no_arena_import.proto",
    "google/protobuf/unittest_no_field_presence.proto",
    "google/protobuf/unittest_no_generic_services.proto",
    "google/protobuf/unittest_optimize_for.proto",
    "google/protobuf/unittest_preserve_unknown_enum.proto",
    "google/protobuf/unittest_preserve_unknown_enum2.proto",
    "google/protobuf/unittest_proto3_arena.proto",
403 404
    "google/protobuf/unittest_proto3_arena_lite.proto",
    "google/protobuf/unittest_proto3_lite.proto",
405
    "google/protobuf/unittest_well_known_types.proto",
406 407 408 409 410 411
    "google/protobuf/util/internal/testdata/anys.proto",
    "google/protobuf/util/internal/testdata/books.proto",
    "google/protobuf/util/internal/testdata/default_value.proto",
    "google/protobuf/util/internal/testdata/default_value_test.proto",
    "google/protobuf/util/internal/testdata/field_mask.proto",
    "google/protobuf/util/internal/testdata/maps.proto",
412
    "google/protobuf/util/internal/testdata/oneofs.proto",
413
    "google/protobuf/util/internal/testdata/proto3.proto",
414 415
    "google/protobuf/util/internal/testdata/struct.proto",
    "google/protobuf/util/internal/testdata/timestamp_duration.proto",
416
    "google/protobuf/util/internal/testdata/wrappers.proto",
417
    "google/protobuf/util/json_format_proto3.proto",
Feng Xiao's avatar
Feng Xiao committed
418
    "google/protobuf/util/message_differencer_unittest.proto",
419 420
]

Jisi Liu's avatar
Jisi Liu committed
421 422
TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]

423 424
cc_proto_library(
    name = "cc_test_protos",
Jisi Liu's avatar
Jisi Liu committed
425
    srcs = LITE_TEST_PROTOS + TEST_PROTOS,
426
    include = "src",
427
    default_runtime = ":protobuf",
428
    protoc = ":protoc",
429
    deps = [":cc_wkt_protos"],
430 431 432 433 434 435 436 437 438 439 440
)

COMMON_TEST_SRCS = [
    # AUTOGEN(common_test_srcs)
    "src/google/protobuf/arena_test_util.cc",
    "src/google/protobuf/map_test_util.cc",
    "src/google/protobuf/test_util.cc",
    "src/google/protobuf/testing/file.cc",
    "src/google/protobuf/testing/googletest.cc",
]

441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
cc_binary(
    name = "test_plugin",
    srcs = [
        # AUTOGEN(test_plugin_srcs)
        "src/google/protobuf/compiler/mock_code_generator.cc",
        "src/google/protobuf/compiler/test_plugin.cc",
        "src/google/protobuf/testing/file.cc",
    ],
    deps = [
        ":protobuf",
        ":protoc_lib",
        "//external:gtest",
    ],
)

cc_test(
    name = "protobuf_test",
458
    srcs = COMMON_TEST_SRCS + [
459 460 461 462 463 464 465 466
        # AUTOGEN(test_srcs)
        "src/google/protobuf/any_test.cc",
        "src/google/protobuf/arena_unittest.cc",
        "src/google/protobuf/arenastring_unittest.cc",
        "src/google/protobuf/compiler/command_line_interface_unittest.cc",
        "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
        "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
        "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
467
        "src/google/protobuf/compiler/cpp/metadata_test.cc",
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
        "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
        "src/google/protobuf/compiler/importer_unittest.cc",
        "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
        "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
        "src/google/protobuf/compiler/mock_code_generator.cc",
        "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
        "src/google/protobuf/compiler/parser_unittest.cc",
        "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
        "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
        "src/google/protobuf/descriptor_database_unittest.cc",
        "src/google/protobuf/descriptor_unittest.cc",
        "src/google/protobuf/drop_unknown_fields_test.cc",
        "src/google/protobuf/dynamic_message_unittest.cc",
        "src/google/protobuf/extension_set_unittest.cc",
        "src/google/protobuf/generated_message_reflection_unittest.cc",
        "src/google/protobuf/io/coded_stream_unittest.cc",
        "src/google/protobuf/io/printer_unittest.cc",
        "src/google/protobuf/io/tokenizer_unittest.cc",
        "src/google/protobuf/io/zero_copy_stream_unittest.cc",
        "src/google/protobuf/map_field_test.cc",
        "src/google/protobuf/map_test.cc",
        "src/google/protobuf/message_unittest.cc",
        "src/google/protobuf/no_field_presence_test.cc",
        "src/google/protobuf/preserve_unknown_enum_test.cc",
492
        "src/google/protobuf/proto3_arena_lite_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
493
        "src/google/protobuf/proto3_arena_unittest.cc",
494
        "src/google/protobuf/proto3_lite_unittest.cc",
495 496 497 498 499
        "src/google/protobuf/reflection_ops_unittest.cc",
        "src/google/protobuf/repeated_field_reflection_unittest.cc",
        "src/google/protobuf/repeated_field_unittest.cc",
        "src/google/protobuf/stubs/bytestream_unittest.cc",
        "src/google/protobuf/stubs/common_unittest.cc",
500
        "src/google/protobuf/stubs/int128_unittest.cc",
501 502 503 504 505 506 507 508 509 510 511 512 513
        "src/google/protobuf/stubs/once_unittest.cc",
        "src/google/protobuf/stubs/status_test.cc",
        "src/google/protobuf/stubs/statusor_test.cc",
        "src/google/protobuf/stubs/stringpiece_unittest.cc",
        "src/google/protobuf/stubs/stringprintf_unittest.cc",
        "src/google/protobuf/stubs/structurally_valid_unittest.cc",
        "src/google/protobuf/stubs/strutil_unittest.cc",
        "src/google/protobuf/stubs/template_util_unittest.cc",
        "src/google/protobuf/stubs/time_test.cc",
        "src/google/protobuf/stubs/type_traits_unittest.cc",
        "src/google/protobuf/text_format_unittest.cc",
        "src/google/protobuf/unknown_field_set_unittest.cc",
        "src/google/protobuf/util/field_comparator_test.cc",
514
        "src/google/protobuf/util/field_mask_util_test.cc",
515 516 517 518 519 520 521
        "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
        "src/google/protobuf/util/internal/json_objectwriter_test.cc",
        "src/google/protobuf/util/internal/json_stream_parser_test.cc",
        "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
        "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
        "src/google/protobuf/util/internal/type_info_test_helper.cc",
        "src/google/protobuf/util/json_util_test.cc",
Feng Xiao's avatar
Feng Xiao committed
522
        "src/google/protobuf/util/message_differencer_unittest.cc",
523
        "src/google/protobuf/util/time_util_test.cc",
524 525 526 527 528 529 530
        "src/google/protobuf/util/type_resolver_util_test.cc",
        "src/google/protobuf/well_known_types_unittest.cc",
        "src/google/protobuf/wire_format_unittest.cc",
    ],
    copts = COPTS,
    data = [
        ":test_plugin",
531 532 533
    ] + glob([
        "src/google/protobuf/**/*",
    ]),
534 535 536 537 538
    includes = [
        "src/",
    ],
    linkopts = LINK_OPTS,
    deps = [
Jisi Liu's avatar
Jisi Liu committed
539
        ":cc_test_protos",
540 541 542 543 544
        ":protobuf",
        ":protoc_lib",
        "//external:gtest_main",
    ],
)
Jisi Liu's avatar
Jisi Liu committed
545 546 547 548

################################################################################
# Java support
################################################################################
549
internal_gen_well_known_protos_java(
Ming Zhao's avatar
Ming Zhao committed
550
    srcs = WELL_KNOWN_PROTOS,
Jisi Liu's avatar
Jisi Liu committed
551 552 553
)

java_library(
554
    name = "protobuf_java",
Jisi Liu's avatar
Jisi Liu committed
555
    srcs = glob([
Ming Zhao's avatar
Ming Zhao committed
556
        "java/core/src/main/java/com/google/protobuf/*.java",
Jisi Liu's avatar
Jisi Liu committed
557
    ]) + [
Ming Zhao's avatar
Ming Zhao committed
558
        ":gen_well_known_protos_java",
Jisi Liu's avatar
Jisi Liu committed
559 560 561 562
    ],
    visibility = ["//visibility:public"],
)

563 564 565 566 567 568
java_library(
    name = "protobuf_java_util",
    srcs = glob([
        "java/util/src/main/java/com/google/protobuf/util/*.java",
    ]),
    deps = [
569 570 571
        "protobuf_java",
        "//external:gson",
        "//external:guava",
572 573 574 575
    ],
    visibility = ["//visibility:public"],
)

Jisi Liu's avatar
Jisi Liu committed
576 577 578 579
################################################################################
# Python support
################################################################################

580
py_library(
Jisi Liu's avatar
Jisi Liu committed
581 582 583 584 585 586 587
    name = "python_srcs",
    srcs = glob(
        [
            "python/google/protobuf/*.py",
            "python/google/protobuf/**/*.py",
        ],
        exclude = [
588 589
            "python/google/protobuf/__init__.py",
            "python/google/protobuf/**/__init__.py",
Jisi Liu's avatar
Jisi Liu committed
590 591 592 593
            "python/google/protobuf/internal/*_test.py",
            "python/google/protobuf/internal/test_util.py",
        ],
    ),
594
    srcs_version = "PY2AND3",
595
    imports = ["python"],
Jisi Liu's avatar
Jisi Liu committed
596 597
)

598
cc_binary(
599
    name = "python/google/protobuf/internal/_api_implementation.so",
600 601 602 603 604 605
    srcs = ["python/google/protobuf/internal/api_implementation.cc"],
    copts = COPTS + [
        "-DPYTHON_PROTO2_CPP_IMPL_V2",
    ],
    linkshared = 1,
    linkstatic = 1,
606 607
    deps = select({
        "//conditions:default": [],
608
        ":use_fast_cpp_protos": ["//external:python_headers"],
609
    }),
610 611 612
)

cc_binary(
613
    name = "python/google/protobuf/pyext/_message.so",
614 615 616 617 618 619
    srcs = glob([
        "python/google/protobuf/pyext/*.cc",
        "python/google/protobuf/pyext/*.h",
    ]),
    copts = COPTS + [
        "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
620 621 622 623
    ] + select({
        "//conditions:default": [],
        ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
    }),
624 625 626 627 628 629
    includes = [
        "python/",
        "src/",
    ],
    linkshared = 1,
    linkstatic = 1,
630 631 632 633
    deps = [
        ":protobuf",
    ] + select({
        "//conditions:default": [],
634
        ":use_fast_cpp_protos": ["//external:python_headers"],
635 636 637 638 639 640 641 642
    }),
)

config_setting(
    name = "use_fast_cpp_protos",
    values = {
        "define": "use_fast_cpp_protos=true",
    },
643 644
)

645 646 647 648 649 650 651
config_setting(
    name = "allow_oversize_protos",
    values = {
        "define": "allow_oversize_protos=true",
    },
)

652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
# Copy the builtin proto files from src/google/protobuf to
# python/google/protobuf. This way, the generated Python sources will be in the
# same directory as the Python runtime sources. This is necessary for the
# modules to be imported correctly since they are all part of the same Python
# package.
internal_copied_filegroup(
    name = "protos_python",
    srcs = WELL_KNOWN_PROTOS,
    strip_prefix = "src",
    dest = "python",
)

# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
# which case we can simply add :protos_python in srcs.
COPIED_WELL_KNOWN_PROTOS = ["python/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]

Jisi Liu's avatar
Jisi Liu committed
668
py_proto_library(
669
    name = "protobuf_python",
670 671
    srcs = COPIED_WELL_KNOWN_PROTOS,
    include = "python",
672 673 674
    data = select({
        "//conditions:default": [],
        ":use_fast_cpp_protos": [
675 676
            ":python/google/protobuf/internal/_api_implementation.so",
            ":python/google/protobuf/pyext/_message.so",
677 678
        ],
    }),
679
    default_runtime = "",
680
    protoc = ":protoc",
681 682 683 684
    py_libs = [
        ":python_srcs",
        "//external:six"
    ],
685
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
686 687 688
    visibility = ["//visibility:public"],
)

689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
# Copy the test proto files from src/google/protobuf to
# python/google/protobuf. This way, the generated Python sources will be in the
# same directory as the Python runtime sources. This is necessary for the
# modules to be imported correctly by the tests since they are all part of the
# same Python package.
internal_copied_filegroup(
    name = "protos_python_test",
    srcs = LITE_TEST_PROTOS + TEST_PROTOS,
    strip_prefix = "src",
    dest = "python",
)

# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
# which case we can simply add :protos_python_test in srcs.
COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]

Jisi Liu's avatar
Jisi Liu committed
706 707
py_proto_library(
    name = "python_common_test_protos",
708 709
    srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
    include = "python",
710
    default_runtime = "",
711
    protoc = ":protoc",
712
    srcs_version = "PY2AND3",
713
    deps = [":protobuf_python"],
Jisi Liu's avatar
Jisi Liu committed
714 715 716 717
)

py_proto_library(
    name = "python_specific_test_protos",
718 719 720 721
    srcs = glob([
        "python/google/protobuf/internal/*.proto",
        "python/google/protobuf/internal/import_test_package/*.proto",
    ]),
Jisi Liu's avatar
Jisi Liu committed
722
    include = "python",
723
    default_runtime = ":protobuf_python",
724
    protoc = ":protoc",
725
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
726 727 728 729 730
    deps = [":python_common_test_protos"],
)

py_library(
    name = "python_tests",
731 732 733 734
    srcs = glob(
        [
            "python/google/protobuf/internal/*_test.py",
            "python/google/protobuf/internal/test_util.py",
735
            "python/google/protobuf/internal/import_test_package/__init__.py",
736 737 738
        ],
    ),
    imports = ["python"],
739
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
740
    deps = [
741
        ":protobuf_python",
742
        ":python_common_test_protos",
Jisi Liu's avatar
Jisi Liu committed
743 744 745 746 747
        ":python_specific_test_protos",
    ],
)

internal_protobuf_py_tests(
Jisi Liu's avatar
Jisi Liu committed
748
    name = "python_tests_batch",
749 750 751
    data = glob([
        "src/google/protobuf/**/*",
    ]),
Jisi Liu's avatar
Jisi Liu committed
752 753 754 755 756 757 758
    modules = [
        "descriptor_database_test",
        "descriptor_pool_test",
        "descriptor_test",
        "generator_test",
        "json_format_test",
        "message_factory_test",
759
        "message_test",
Jisi Liu's avatar
Jisi Liu committed
760
        "proto_builder_test",
761
        "reflection_test",
Jisi Liu's avatar
Jisi Liu committed
762 763 764
        "service_reflection_test",
        "symbol_database_test",
        "text_encoding_test",
765
        "text_format_test",
Jisi Liu's avatar
Jisi Liu committed
766 767 768 769 770
        "unknown_fields_test",
        "wire_format_test",
    ],
    deps = [":python_tests"],
)
771 772 773 774

proto_lang_toolchain(
  name = "cc_toolchain",
  command_line = "--cpp_out=$(OUT)",
775
  runtime = ":protobuf",
776 777
  visibility = ["//visibility:public"],
)
778 779 780 781 782 783 784

proto_lang_toolchain(
    name = "java_toolchain",
    command_line = "--java_out=$(OUT)",
    runtime = ":protobuf_java",
    visibility = ["//visibility:public"],
)