BUILD 47.9 KB
Newer Older
1
# Bazel (https://bazel.build/) BUILD file for Protobuf.
2

3
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library")
4 5
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
6
load("@rules_proto//proto/private:native.bzl", "native_proto_common")
7
load("@rules_python//python:defs.bzl", "py_library")
8
load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
9

10 11
licenses(["notice"])

12 13
exports_files(["LICENSE"])

14 15 16 17 18 19 20 21 22 23 24
################################################################################
# Java 9 configuration
################################################################################

config_setting(
    name = "jdk9",
    values = {
        "java_toolchain": "@bazel_tools//tools/jdk:toolchain_jdk9",
    },
)

25 26 27 28
################################################################################
# ZLIB configuration
################################################################################

29
ZLIB_DEPS = ["@zlib//:zlib"]
30

31 32 33 34
################################################################################
# Protobuf Runtime Library
################################################################################

35
MSVC_COPTS = [
36
    "/DHAVE_PTHREAD",
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    "/wd4018",  # -Wno-sign-compare
    "/wd4065",  # switch statement contains 'default' but no 'case' labels
    "/wd4146",  # unary minus operator applied to unsigned type, result still unsigned
    "/wd4244",  # 'conversion' conversion from 'type1' to 'type2', possible loss of data
    "/wd4251",  # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
    "/wd4267",  # 'var' : conversion from 'size_t' to 'type', possible loss of data
    "/wd4305",  # 'identifier' : truncation from 'type1' to 'type2'
    "/wd4307",  # 'operator' : integral constant overflow
    "/wd4309",  # 'conversion' : truncation of constant value
    "/wd4334",  # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
    "/wd4355",  # 'this' : used in base member initializer list
    "/wd4506",  # no definition for inline function 'function'
    "/wd4514",  # -Wno-unused-function
    "/wd4800",  # 'type' : forcing value to bool 'true' or 'false' (performance warning)
    "/wd4996",  # The compiler encountered a deprecated declaration.
52 53
]

54
COPTS = select({
55
    ":msvc": MSVC_COPTS,
56 57
    "//conditions:default": [
        "-DHAVE_PTHREAD",
58
        "-DHAVE_ZLIB",
59 60 61
        "-Woverloaded-virtual",
        "-Wno-sign-compare",
        "-Wno-unused-function",
62
        # Prevents ISO C++ const string assignment warnings for pyext sources.
63
        "-Wno-write-strings",
64
        "-Wno-deprecated-declarations",
65 66 67
    ],
})

68 69
load(":compiler_config_setting.bzl", "create_compiler_config_setting")

70
create_compiler_config_setting(
71
    name = "msvc",
72
    value = "msvc-cl",
73 74
)

75 76 77 78 79 80 81
config_setting(
    name = "android",
    values = {
        "crosstool_top": "//external:android/crosstool",
    },
)

82 83 84 85 86 87 88 89 90 91 92 93 94 95
config_setting(
    name = "android-libcpp",
    values = {
        "crosstool_top": "@androidndk//:toolchain-libcpp",
    },
)

config_setting(
    name = "android-gnu-libstdcpp",
    values = {
        "crosstool_top": "@androidndk//:toolchain-gnu-libstdcpp",
    },
)

96
# Android and MSVC builds do not need to link in a separate pthread library.
97
LINK_OPTS = select({
Andrew Harp's avatar
Andrew Harp committed
98
    ":android": [],
99 100
    ":android-libcpp": [],
    ":android-gnu-libstdcpp": [],
101
    ":msvc": [
102 103
        # Suppress linker warnings about files with no symbols defined.
        "-ignore:4221",
104
    ],
105 106 107 108
    "//conditions:default": [
        "-lpthread",
        "-lm",
    ],
109
})
110

111
load(
112
    ":protobuf.bzl",
113
    "cc_proto_library",
114
    "internal_copied_filegroup",
115
    "internal_gen_well_known_protos_java",
116
    "internal_protobuf_py_tests",
117
    "py_proto_library",
118
)
119

120 121 122 123
cc_library(
    name = "protobuf_lite",
    srcs = [
        # AUTOGEN(protobuf_lite_srcs)
124
        "src/google/protobuf/any_lite.cc",
125 126
        "src/google/protobuf/arena.cc",
        "src/google/protobuf/extension_set.cc",
127
        "src/google/protobuf/generated_enum_util.cc",
Jisi Liu's avatar
Jisi Liu committed
128
        "src/google/protobuf/generated_message_table_driven_lite.cc",
129
        "src/google/protobuf/generated_message_util.cc",
130
        "src/google/protobuf/implicit_weak_message.cc",
131
        "src/google/protobuf/io/coded_stream.cc",
132
        "src/google/protobuf/io/io_win32.cc",
133
        "src/google/protobuf/io/strtod.cc",
134
        "src/google/protobuf/io/zero_copy_stream.cc",
135
        "src/google/protobuf/io/zero_copy_stream_impl.cc",
136 137
        "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
        "src/google/protobuf/message_lite.cc",
138
        "src/google/protobuf/parse_context.cc",
139
        "src/google/protobuf/repeated_field.cc",
140
        "src/google/protobuf/stubs/bytestream.cc",
141
        "src/google/protobuf/stubs/common.cc",
142
        "src/google/protobuf/stubs/int128.cc",
143 144 145
        "src/google/protobuf/stubs/status.cc",
        "src/google/protobuf/stubs/statusor.cc",
        "src/google/protobuf/stubs/stringpiece.cc",
146
        "src/google/protobuf/stubs/stringprintf.cc",
147
        "src/google/protobuf/stubs/structurally_valid.cc",
148 149
        "src/google/protobuf/stubs/strutil.cc",
        "src/google/protobuf/stubs/time.cc",
150 151
        "src/google/protobuf/wire_format_lite.cc",
    ],
152 153 154 155
    hdrs = glob([
        "src/google/protobuf/**/*.h",
        "src/google/protobuf/**/*.inc",
    ]),
156
    copts = COPTS,
157 158 159 160 161
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
)

162 163 164 165 166
PROTOBUF_DEPS = select({
    ":msvc": [],
    "//conditions:default": ZLIB_DEPS,
})

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
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",
Jisi Liu's avatar
Jisi Liu committed
185
        "src/google/protobuf/generated_message_table_driven.cc",
186 187 188 189 190 191 192 193 194 195 196 197 198 199
        "src/google/protobuf/io/gzip_stream.cc",
        "src/google/protobuf/io/printer.cc",
        "src/google/protobuf/io/tokenizer.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",
        "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",
Bairen Yi's avatar
Bairen Yi committed
200
        "src/google/protobuf/util/delimited_message_util.cc",
201
        "src/google/protobuf/util/field_comparator.cc",
202
        "src/google/protobuf/util/field_mask_util.cc",
203 204 205 206 207 208 209 210
        "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
211
        "src/google/protobuf/util/internal/proto_writer.cc",
212 213 214 215 216 217 218
        "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",
219
        "src/google/protobuf/util/time_util.cc",
220
        "src/google/protobuf/util/type_resolver_util.cc",
221 222 223
        "src/google/protobuf/wire_format.cc",
        "src/google/protobuf/wrappers.pb.cc",
    ],
224 225 226 227
    hdrs = glob([
        "src/**/*.h",
        "src/**/*.inc",
    ]),
228
    copts = COPTS,
229 230 231
    includes = ["src/"],
    linkopts = LINK_OPTS,
    visibility = ["//visibility:public"],
232
    deps = [":protobuf_lite"] + PROTOBUF_DEPS,
233 234
)

235 236 237 238
# This provides just the header files for use in projects that need to build
# shared libraries for dynamic loading. This target is available until Bazel
# adds native support for such use cases.
# TODO(keveman): Remove this target once the support gets added to Bazel.
239 240
cc_library(
    name = "protobuf_headers",
241 242 243 244
    hdrs = glob([
        "src/**/*.h",
        "src/**/*.inc",
    ]),
245 246 247 248
    includes = ["src/"],
    visibility = ["//visibility:public"],
)

249 250 251
# Map of all well known protos.
# name => (include path, imports)
WELL_KNOWN_PROTO_MAP = {
252
    "any": ("src/google/protobuf/any.proto", []),
253
    "api": (
254
        "src/google/protobuf/api.proto",
255 256 257 258 259 260
        [
            "source_context",
            "type",
        ],
    ),
    "compiler_plugin": (
261
        "src/google/protobuf/compiler/plugin.proto",
262 263
        ["descriptor"],
    ),
264 265 266 267 268 269 270
    "descriptor": ("src/google/protobuf/descriptor.proto", []),
    "duration": ("src/google/protobuf/duration.proto", []),
    "empty": ("src/google/protobuf/empty.proto", []),
    "field_mask": ("src/google/protobuf/field_mask.proto", []),
    "source_context": ("src/google/protobuf/source_context.proto", []),
    "struct": ("src/google/protobuf/struct.proto", []),
    "timestamp": ("src/google/protobuf/timestamp.proto", []),
271
    "type": (
272
        "src/google/protobuf/type.proto",
273 274 275 276 277
        [
            "any",
            "source_context",
        ],
    ),
278
    "wrappers": ("src/google/protobuf/wrappers.proto", []),
279 280
}

281
WELL_KNOWN_PROTOS = [value[0] for value in WELL_KNOWN_PROTO_MAP.values()]
Jisi Liu's avatar
Jisi Liu committed
282

283 284 285 286 287 288
filegroup(
    name = "well_known_protos",
    srcs = WELL_KNOWN_PROTOS,
    visibility = ["//visibility:public"],
)

289 290
cc_proto_library(
    name = "cc_wkt_protos",
Jisi Liu's avatar
Jisi Liu committed
291
    srcs = WELL_KNOWN_PROTOS,
292
    include = "src",
293
    default_runtime = ":protobuf",
Jisi Liu's avatar
Jisi Liu committed
294
    internal_bootstrap_hack = 1,
295
    protoc = ":protoc",
296
    visibility = ["//visibility:public"],
297 298
)

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
################################################################################
# Well Known Types Proto Library Rules
#
# These proto_library rules can be used with one of the language specific proto
# library rules i.e. java_proto_library:
#
# java_proto_library(
#   name = "any_java_proto",
#   deps = ["@com_google_protobuf//:any_proto],
# )
################################################################################

[proto_library(
    name = proto[0] + "_proto",
    srcs = [proto[1][0]],
314
    strip_import_prefix = "src",
315
    visibility = ["//visibility:public"],
316 317
    deps = [dep + "_proto" for dep in proto[1][1]],
) for proto in WELL_KNOWN_PROTO_MAP.items()]
318

319 320 321 322 323 324 325 326 327 328 329
[native_cc_proto_library(
    name = proto + "_cc_proto",
    deps = [proto + "_proto"],
    visibility = ["//visibility:private"],
) for proto in WELL_KNOWN_PROTO_MAP.keys()]

cc_proto_blacklist_test(
    name = "cc_proto_blacklist_test",
    deps = [proto + "_cc_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()]
)

330 331 332 333
################################################################################
# Protocol Buffers Compiler
################################################################################

334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
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",
350
        "src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
351 352 353
        "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",
354
        "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
355 356 357 358 359
        "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",
360
        "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
361 362 363
        "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",
364
        "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
365 366 367 368
        "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",
369
        "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
370 371 372 373 374
        "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",
375
        "src/google/protobuf/compiler/java/java_enum_lite.cc",
376
        "src/google/protobuf/compiler/java/java_extension.cc",
377
        "src/google/protobuf/compiler/java/java_extension_lite.cc",
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
        "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_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",
Feng Xiao's avatar
Feng Xiao committed
398
        "src/google/protobuf/compiler/js/js_generator.cc",
Jisi Liu's avatar
Jisi Liu committed
399
        "src/google/protobuf/compiler/js/well_known_types_embed.cc",
400 401 402 403 404 405 406 407 408 409 410 411
        "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",
412
        "src/google/protobuf/compiler/php/php_generator.cc",
413
        "src/google/protobuf/compiler/plugin.cc",
414
        "src/google/protobuf/compiler/plugin.pb.cc",
415 416 417 418 419 420 421
        "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/"],
422
    linkopts = LINK_OPTS,
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
    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
439
RELATIVE_LITE_TEST_PROTOS = [
440 441 442 443 444
    # 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",
445
    "google/protobuf/unittest_no_arena_lite.proto",
446 447
]

Jisi Liu's avatar
Jisi Liu committed
448 449 450
LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]

RELATIVE_TEST_PROTOS = [
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
    # 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",
466 467 468
    "google/protobuf/unittest_lazy_dependencies.proto",
    "google/protobuf/unittest_lazy_dependencies_custom_option.proto",
    "google/protobuf/unittest_lazy_dependencies_enum.proto",
469 470
    "google/protobuf/unittest_lite_imports_nonlite.proto",
    "google/protobuf/unittest_mset.proto",
471
    "google/protobuf/unittest_mset_wire_format.proto",
472 473 474 475 476 477 478
    "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",
Feng Xiao's avatar
Feng Xiao committed
479
    "google/protobuf/unittest_proto3.proto",
480
    "google/protobuf/unittest_proto3_arena.proto",
481 482
    "google/protobuf/unittest_proto3_arena_lite.proto",
    "google/protobuf/unittest_proto3_lite.proto",
483
    "google/protobuf/unittest_well_known_types.proto",
484 485 486 487 488 489
    "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",
490
    "google/protobuf/util/internal/testdata/oneofs.proto",
491
    "google/protobuf/util/internal/testdata/proto3.proto",
492 493
    "google/protobuf/util/internal/testdata/struct.proto",
    "google/protobuf/util/internal/testdata/timestamp_duration.proto",
494
    "google/protobuf/util/internal/testdata/wrappers.proto",
Feng Xiao's avatar
Feng Xiao committed
495
    "google/protobuf/util/json_format.proto",
496
    "google/protobuf/util/json_format_proto3.proto",
Feng Xiao's avatar
Feng Xiao committed
497
    "google/protobuf/util/message_differencer_unittest.proto",
498 499
]

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

502 503
cc_proto_library(
    name = "cc_test_protos",
Jisi Liu's avatar
Jisi Liu committed
504
    srcs = LITE_TEST_PROTOS + TEST_PROTOS,
505
    include = "src",
506
    default_runtime = ":protobuf",
507
    protoc = ":protoc",
508
    deps = [":cc_wkt_protos"],
509 510 511 512 513
)

COMMON_TEST_SRCS = [
    # AUTOGEN(common_test_srcs)
    "src/google/protobuf/arena_test_util.cc",
514
    "src/google/protobuf/map_test_util.inc",
515
    "src/google/protobuf/test_util.cc",
516
    "src/google/protobuf/test_util.inc",
517 518 519 520
    "src/google/protobuf/testing/file.cc",
    "src/google/protobuf/testing/googletest.cc",
]

521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
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",
    ],
)

Jisi Liu's avatar
Jisi Liu committed
536 537
cc_test(
    name = "win32_test",
538
    srcs = ["src/google/protobuf/io/io_win32_unittest.cc"],
539 540 541 542
    tags = [
        "manual",
        "windows",
    ],
Jisi Liu's avatar
Jisi Liu committed
543 544 545 546 547 548
    deps = [
        ":protobuf_lite",
        "//external:gtest_main",
    ],
)

549 550
cc_test(
    name = "protobuf_test",
551
    srcs = COMMON_TEST_SRCS + [
552 553 554 555
        # AUTOGEN(test_srcs)
        "src/google/protobuf/any_test.cc",
        "src/google/protobuf/arena_unittest.cc",
        "src/google/protobuf/arenastring_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
556
        "src/google/protobuf/compiler/annotation_test_util.cc",
557
        "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
558
        "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc",
559 560
        "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
        "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
561
        "src/google/protobuf/compiler/cpp/cpp_unittest.inc",
562
        "src/google/protobuf/compiler/cpp/metadata_test.cc",
563
        "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc",
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
        "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",
580
        "src/google/protobuf/io/io_win32_unittest.cc",
581 582 583 584 585 586
        "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",
587
        "src/google/protobuf/message_unittest.inc",
588 589
        "src/google/protobuf/no_field_presence_test.cc",
        "src/google/protobuf/preserve_unknown_enum_test.cc",
590
        "src/google/protobuf/proto3_arena_lite_unittest.cc",
Jisi Liu's avatar
Jisi Liu committed
591
        "src/google/protobuf/proto3_arena_unittest.cc",
592
        "src/google/protobuf/proto3_lite_unittest.cc",
Feng Xiao's avatar
Feng Xiao committed
593
        "src/google/protobuf/proto3_lite_unittest.inc",
594 595 596 597 598
        "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",
599
        "src/google/protobuf/stubs/int128_unittest.cc",
600 601 602 603 604 605 606 607 608 609
        "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/text_format_unittest.cc",
        "src/google/protobuf/unknown_field_set_unittest.cc",
610
        "src/google/protobuf/util/delimited_message_util_test.cc",
611
        "src/google/protobuf/util/field_comparator_test.cc",
612
        "src/google/protobuf/util/field_mask_util_test.cc",
613 614 615 616 617 618 619
        "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
620
        "src/google/protobuf/util/message_differencer_unittest.cc",
621
        "src/google/protobuf/util/time_util_test.cc",
622 623 624
        "src/google/protobuf/util/type_resolver_util_test.cc",
        "src/google/protobuf/well_known_types_unittest.cc",
        "src/google/protobuf/wire_format_unittest.cc",
625
    ] + select({
626
        "//conditions:default": [
627
            # AUTOGEN(non_msvc_test_srcs)
628 629
            "src/google/protobuf/compiler/command_line_interface_unittest.cc",
        ],
630
        ":msvc": [],
631
    }),
632 633 634
    copts = COPTS,
    data = [
        ":test_plugin",
635 636
    ] + glob([
        "src/google/protobuf/**/*",
637 638 639
        # Files for csharp_bootstrap_unittest.cc.
        "conformance/**/*",
        "csharp/src/**/*",
640
    ]),
641 642 643 644 645
    includes = [
        "src/",
    ],
    linkopts = LINK_OPTS,
    deps = [
Jisi Liu's avatar
Jisi Liu committed
646
        ":cc_test_protos",
647 648 649
        ":protobuf",
        ":protoc_lib",
        "//external:gtest_main",
650
    ] + PROTOBUF_DEPS,
651
)
Jisi Liu's avatar
Jisi Liu committed
652 653 654 655

################################################################################
# Java support
################################################################################
656
internal_gen_well_known_protos_java(
Ming Zhao's avatar
Ming Zhao committed
657
    srcs = WELL_KNOWN_PROTOS,
Jisi Liu's avatar
Jisi Liu committed
658 659 660
)

java_library(
661
    name = "protobuf_java",
Jisi Liu's avatar
Jisi Liu committed
662
    srcs = glob([
Ming Zhao's avatar
Ming Zhao committed
663
        "java/core/src/main/java/com/google/protobuf/*.java",
Jisi Liu's avatar
Jisi Liu committed
664
    ]) + [
Ming Zhao's avatar
Ming Zhao committed
665
        ":gen_well_known_protos_java",
Jisi Liu's avatar
Jisi Liu committed
666
    ],
667
    javacopts = select({
668 669 670 671 672
        "//:jdk9": ["--add-modules=jdk.unsupported"],
        "//conditions:default": [
            "-source 7",
            "-target 7",
        ],
673
    }),
Jisi Liu's avatar
Jisi Liu committed
674 675 676
    visibility = ["//visibility:public"],
)

677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
java_library(
    name = "protobuf_javalite",
    srcs = [
        # Keep in sync with java/lite/pom.xml
        "java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java",
        "java/core/src/main/java/com/google/protobuf/AbstractParser.java",
        "java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java",
        "java/core/src/main/java/com/google/protobuf/AllocatedBuffer.java",
        "java/core/src/main/java/com/google/protobuf/Android.java",
        "java/core/src/main/java/com/google/protobuf/ArrayDecoders.java",
        "java/core/src/main/java/com/google/protobuf/BinaryReader.java",
        "java/core/src/main/java/com/google/protobuf/BinaryWriter.java",
        "java/core/src/main/java/com/google/protobuf/BooleanArrayList.java",
        "java/core/src/main/java/com/google/protobuf/BufferAllocator.java",
        "java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java",
        "java/core/src/main/java/com/google/protobuf/ByteOutput.java",
        "java/core/src/main/java/com/google/protobuf/ByteString.java",
        "java/core/src/main/java/com/google/protobuf/CodedInputStream.java",
        "java/core/src/main/java/com/google/protobuf/CodedInputStreamReader.java",
        "java/core/src/main/java/com/google/protobuf/CodedOutputStream.java",
        "java/core/src/main/java/com/google/protobuf/CodedOutputStreamWriter.java",
        "java/core/src/main/java/com/google/protobuf/DoubleArrayList.java",
        "java/core/src/main/java/com/google/protobuf/ExperimentalApi.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionLite.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionSchema.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionSchemaLite.java",
        "java/core/src/main/java/com/google/protobuf/ExtensionSchemas.java",
        "java/core/src/main/java/com/google/protobuf/FieldInfo.java",
        "java/core/src/main/java/com/google/protobuf/FieldSet.java",
        "java/core/src/main/java/com/google/protobuf/FieldType.java",
        "java/core/src/main/java/com/google/protobuf/FloatArrayList.java",
        "java/core/src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java",
        "java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java",
        "java/core/src/main/java/com/google/protobuf/IntArrayList.java",
        "java/core/src/main/java/com/google/protobuf/Internal.java",
        "java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java",
        "java/core/src/main/java/com/google/protobuf/IterableByteBufferInputStream.java",
        "java/core/src/main/java/com/google/protobuf/JavaType.java",
        "java/core/src/main/java/com/google/protobuf/LazyField.java",
        "java/core/src/main/java/com/google/protobuf/LazyFieldLite.java",
        "java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java",
        "java/core/src/main/java/com/google/protobuf/LazyStringList.java",
        "java/core/src/main/java/com/google/protobuf/ListFieldSchema.java",
        "java/core/src/main/java/com/google/protobuf/LongArrayList.java",
        "java/core/src/main/java/com/google/protobuf/ManifestSchemaFactory.java",
        "java/core/src/main/java/com/google/protobuf/MapEntryLite.java",
        "java/core/src/main/java/com/google/protobuf/MapFieldLite.java",
        "java/core/src/main/java/com/google/protobuf/MapFieldSchema.java",
        "java/core/src/main/java/com/google/protobuf/MapFieldSchemaLite.java",
        "java/core/src/main/java/com/google/protobuf/MapFieldSchemas.java",
        "java/core/src/main/java/com/google/protobuf/MessageInfo.java",
        "java/core/src/main/java/com/google/protobuf/MessageInfoFactory.java",
        "java/core/src/main/java/com/google/protobuf/MessageLite.java",
        "java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java",
        "java/core/src/main/java/com/google/protobuf/MessageLiteToString.java",
        "java/core/src/main/java/com/google/protobuf/MessageSchema.java",
        "java/core/src/main/java/com/google/protobuf/MessageSetSchema.java",
        "java/core/src/main/java/com/google/protobuf/MutabilityOracle.java",
        "java/core/src/main/java/com/google/protobuf/NewInstanceSchema.java",
        "java/core/src/main/java/com/google/protobuf/NewInstanceSchemaLite.java",
        "java/core/src/main/java/com/google/protobuf/NewInstanceSchemas.java",
        "java/core/src/main/java/com/google/protobuf/NioByteString.java",
        "java/core/src/main/java/com/google/protobuf/OneofInfo.java",
        "java/core/src/main/java/com/google/protobuf/Parser.java",
        "java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java",
        "java/core/src/main/java/com/google/protobuf/ProtoSyntax.java",
        "java/core/src/main/java/com/google/protobuf/Protobuf.java",
        "java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java",
        "java/core/src/main/java/com/google/protobuf/ProtobufLists.java",
        "java/core/src/main/java/com/google/protobuf/ProtocolStringList.java",
        "java/core/src/main/java/com/google/protobuf/RawMessageInfo.java",
        "java/core/src/main/java/com/google/protobuf/Reader.java",
        "java/core/src/main/java/com/google/protobuf/RopeByteString.java",
        "java/core/src/main/java/com/google/protobuf/Schema.java",
        "java/core/src/main/java/com/google/protobuf/SchemaFactory.java",
        "java/core/src/main/java/com/google/protobuf/SchemaUtil.java",
        "java/core/src/main/java/com/google/protobuf/SmallSortedMap.java",
        "java/core/src/main/java/com/google/protobuf/StructuralMessageInfo.java",
        "java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java",
        "java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java",
        "java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java",
        "java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java",
        "java/core/src/main/java/com/google/protobuf/UnknownFieldSetLiteSchema.java",
        "java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java",
        "java/core/src/main/java/com/google/protobuf/UnsafeUtil.java",
        "java/core/src/main/java/com/google/protobuf/Utf8.java",
        "java/core/src/main/java/com/google/protobuf/WireFormat.java",
        "java/core/src/main/java/com/google/protobuf/Writer.java",
    ],
    javacopts = select({
        "//:jdk9": ["--add-modules=jdk.unsupported"],
        "//conditions:default": [
            "-source 7",
            "-target 7",
        ],
774
    }),
Jisi Liu's avatar
Jisi Liu committed
775 776 777
    visibility = ["//visibility:public"],
)

778 779 780 781 782
java_library(
    name = "protobuf_java_util",
    srcs = glob([
        "java/util/src/main/java/com/google/protobuf/util/*.java",
    ]),
783 784 785 786
    javacopts = [
        "-source 7",
        "-target 7",
    ],
787
    visibility = ["//visibility:public"],
788
    deps = [
789
        "protobuf_java",
790
        "//external:error_prone_annotations",
791 792
        "//external:gson",
        "//external:guava",
793 794 795
    ],
)

Jisi Liu's avatar
Jisi Liu committed
796 797 798 799
################################################################################
# Python support
################################################################################

800
py_library(
Jisi Liu's avatar
Jisi Liu committed
801 802 803
    name = "python_srcs",
    srcs = glob(
        [
804
            "python/google/**/*.py",
Jisi Liu's avatar
Jisi Liu committed
805 806
        ],
        exclude = [
807
            "python/google/protobuf/**/__init__.py",
Jisi Liu's avatar
Jisi Liu committed
808 809 810 811
            "python/google/protobuf/internal/*_test.py",
            "python/google/protobuf/internal/test_util.py",
        ],
    ),
812
    imports = ["python"],
813
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
814 815
)

816
cc_binary(
817
    name = "python/google/protobuf/internal/_api_implementation.so",
818 819 820 821 822 823
    srcs = ["python/google/protobuf/internal/api_implementation.cc"],
    copts = COPTS + [
        "-DPYTHON_PROTO2_CPP_IMPL_V2",
    ],
    linkshared = 1,
    linkstatic = 1,
824 825
    deps = select({
        "//conditions:default": [],
826
        ":use_fast_cpp_protos": ["//external:python_headers"],
827
    }),
828 829 830
)

cc_binary(
831
    name = "python/google/protobuf/pyext/_message.so",
832 833 834 835 836 837
    srcs = glob([
        "python/google/protobuf/pyext/*.cc",
        "python/google/protobuf/pyext/*.h",
    ]),
    copts = COPTS + [
        "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
838 839 840 841
    ] + select({
        "//conditions:default": [],
        ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
    }),
842 843 844 845 846 847
    includes = [
        "python/",
        "src/",
    ],
    linkshared = 1,
    linkstatic = 1,
848 849
    deps = [
        ":protobuf",
850
        ":proto_api",
851 852
    ] + select({
        "//conditions:default": [],
853
        ":use_fast_cpp_protos": ["//external:python_headers"],
854 855 856 857 858 859 860 861
    }),
)

config_setting(
    name = "use_fast_cpp_protos",
    values = {
        "define": "use_fast_cpp_protos=true",
    },
862 863
)

864 865 866 867 868 869 870
config_setting(
    name = "allow_oversize_protos",
    values = {
        "define": "allow_oversize_protos=true",
    },
)

871 872 873 874 875 876 877 878 879
# 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,
    dest = "python",
880
    strip_prefix = "src",
881 882 883 884
)

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

Jisi Liu's avatar
Jisi Liu committed
887
py_proto_library(
888
    name = "protobuf_python",
889 890
    srcs = COPIED_WELL_KNOWN_PROTOS,
    include = "python",
891 892 893
    data = select({
        "//conditions:default": [],
        ":use_fast_cpp_protos": [
894 895
            ":python/google/protobuf/internal/_api_implementation.so",
            ":python/google/protobuf/pyext/_message.so",
896 897
        ],
    }),
898
    default_runtime = "",
899
    protoc = ":protoc",
900
    py_extra_srcs = glob(["python/**/__init__.py"]),
901 902
    py_libs = [
        ":python_srcs",
903
        "@six//:six",
904
    ],
905
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
906 907 908
    visibility = ["//visibility:public"],
)

909 910 911 912 913 914 915 916 917
# 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,
    dest = "python",
918
    strip_prefix = "src",
919 920 921 922 923
)

# 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]
924

925 926
COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]

Jisi Liu's avatar
Jisi Liu committed
927 928
py_proto_library(
    name = "python_common_test_protos",
929 930
    srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
    include = "python",
931
    default_runtime = "",
932
    protoc = ":protoc",
933
    srcs_version = "PY2AND3",
934
    deps = [":protobuf_python"],
Jisi Liu's avatar
Jisi Liu committed
935 936 937 938
)

py_proto_library(
    name = "python_specific_test_protos",
939 940 941 942
    srcs = glob([
        "python/google/protobuf/internal/*.proto",
        "python/google/protobuf/internal/import_test_package/*.proto",
    ]),
Jisi Liu's avatar
Jisi Liu committed
943
    include = "python",
944
    default_runtime = ":protobuf_python",
945
    protoc = ":protoc",
946
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
947 948 949 950 951
    deps = [":python_common_test_protos"],
)

py_library(
    name = "python_tests",
952 953 954 955
    srcs = glob(
        [
            "python/google/protobuf/internal/*_test.py",
            "python/google/protobuf/internal/test_util.py",
956
            "python/google/protobuf/internal/import_test_package/__init__.py",
957 958 959
        ],
    ),
    imports = ["python"],
960
    srcs_version = "PY2AND3",
Jisi Liu's avatar
Jisi Liu committed
961
    deps = [
962
        ":protobuf_python",
963
        ":python_common_test_protos",
Jisi Liu's avatar
Jisi Liu committed
964 965 966 967 968
        ":python_specific_test_protos",
    ],
)

internal_protobuf_py_tests(
Jisi Liu's avatar
Jisi Liu committed
969
    name = "python_tests_batch",
970 971 972
    data = glob([
        "src/google/protobuf/**/*",
    ]),
Jisi Liu's avatar
Jisi Liu committed
973 974 975 976 977 978 979
    modules = [
        "descriptor_database_test",
        "descriptor_pool_test",
        "descriptor_test",
        "generator_test",
        "json_format_test",
        "message_factory_test",
980
        "message_test",
Jisi Liu's avatar
Jisi Liu committed
981
        "proto_builder_test",
982
        "reflection_test",
Jisi Liu's avatar
Jisi Liu committed
983 984 985
        "service_reflection_test",
        "symbol_database_test",
        "text_encoding_test",
986
        "text_format_test",
Jisi Liu's avatar
Jisi Liu committed
987 988 989 990 991
        "unknown_fields_test",
        "wire_format_test",
    ],
    deps = [":python_tests"],
)
992

993 994 995
cc_library(
    name = "proto_api",
    hdrs = ["python/google/protobuf/proto_api.h"],
996
    visibility = ["//visibility:public"],
997 998 999 1000 1001
    deps = [
        "//external:python_headers",
    ],
)

1002 1003
# Note: We use `native_proto_common` here because we depend on an implementation-detail of
# `proto_lang_toolchain`, which may not be available on `proto_common`.
1004
reject_blacklisted_files = hasattr(native_proto_common, "proto_lang_toolchain_rejects_files_do_not_use_or_we_will_break_you_without_mercy")
1005
cc_toolchain_blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()] if reject_blacklisted_files else [":well_known_protos"]
1006
proto_lang_toolchain(
1007
    name = "cc_toolchain",
1008
    blacklisted_protos = cc_toolchain_blacklisted_protos,
1009 1010 1011
    command_line = "--cpp_out=$(OUT)",
    runtime = ":protobuf",
    visibility = ["//visibility:public"],
1012
)
1013 1014 1015 1016 1017 1018 1019

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

1021 1022 1023 1024 1025 1026 1027
proto_lang_toolchain(
    name = "javalite_toolchain",
    command_line = "--java_out=lite:$(OUT)",
    runtime = ":protobuf_javalite",
    visibility = ["//visibility:public"],
)

1028 1029 1030 1031 1032
alias(
    name = "objectivec",
    actual = ":protobuf_objc",
    visibility = ["//visibility:public"],
)
1033 1034

objc_library(
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
    name = "protobuf_objc",
    hdrs = [
        "objectivec/GPBArray.h",
        "objectivec/GPBBootstrap.h",
        "objectivec/GPBCodedInputStream.h",
        "objectivec/GPBCodedOutputStream.h",
        "objectivec/GPBDescriptor.h",
        "objectivec/GPBDictionary.h",
        "objectivec/GPBExtensionInternals.h",
        "objectivec/GPBExtensionRegistry.h",
        "objectivec/GPBMessage.h",
        "objectivec/GPBProtocolBuffers.h",
        "objectivec/GPBProtocolBuffers_RuntimeSupport.h",
        "objectivec/GPBRootObject.h",
        "objectivec/GPBRuntimeTypes.h",
        "objectivec/GPBUnknownField.h",
        "objectivec/GPBUnknownFieldSet.h",
        "objectivec/GPBUtilities.h",
        "objectivec/GPBWellKnownTypes.h",
        "objectivec/GPBWireFormat.h",
        "objectivec/google/protobuf/Any.pbobjc.h",
        "objectivec/google/protobuf/Api.pbobjc.h",
        "objectivec/google/protobuf/Duration.pbobjc.h",
        "objectivec/google/protobuf/Empty.pbobjc.h",
        "objectivec/google/protobuf/FieldMask.pbobjc.h",
        "objectivec/google/protobuf/SourceContext.pbobjc.h",
        "objectivec/google/protobuf/Struct.pbobjc.h",
        "objectivec/google/protobuf/Timestamp.pbobjc.h",
        "objectivec/google/protobuf/Type.pbobjc.h",
        "objectivec/google/protobuf/Wrappers.pbobjc.h",
        # Package private headers, but exposed because the generated sources
        # need to use them.
        "objectivec/GPBArray_PackagePrivate.h",
        "objectivec/GPBCodedInputStream_PackagePrivate.h",
        "objectivec/GPBCodedOutputStream_PackagePrivate.h",
        "objectivec/GPBDescriptor_PackagePrivate.h",
        "objectivec/GPBDictionary_PackagePrivate.h",
        "objectivec/GPBMessage_PackagePrivate.h",
        "objectivec/GPBRootObject_PackagePrivate.h",
        "objectivec/GPBUnknownFieldSet_PackagePrivate.h",
        "objectivec/GPBUnknownField_PackagePrivate.h",
        "objectivec/GPBUtilities_PackagePrivate.h",
    ],
1078 1079 1080
    copts = [
        "-Wno-vla",
    ],
1081 1082 1083
    includes = [
        "objectivec",
    ],
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
    non_arc_srcs = [
        "objectivec/GPBArray.m",
        "objectivec/GPBCodedInputStream.m",
        "objectivec/GPBCodedOutputStream.m",
        "objectivec/GPBDescriptor.m",
        "objectivec/GPBDictionary.m",
        "objectivec/GPBExtensionInternals.m",
        "objectivec/GPBExtensionRegistry.m",
        "objectivec/GPBMessage.m",
        "objectivec/GPBRootObject.m",
        "objectivec/GPBUnknownField.m",
        "objectivec/GPBUnknownFieldSet.m",
        "objectivec/GPBUtilities.m",
        "objectivec/GPBWellKnownTypes.m",
        "objectivec/GPBWireFormat.m",
        "objectivec/google/protobuf/Any.pbobjc.m",
        "objectivec/google/protobuf/Api.pbobjc.m",
        "objectivec/google/protobuf/Duration.pbobjc.m",
        "objectivec/google/protobuf/Empty.pbobjc.m",
        "objectivec/google/protobuf/FieldMask.pbobjc.m",
        "objectivec/google/protobuf/SourceContext.pbobjc.m",
        "objectivec/google/protobuf/Struct.pbobjc.m",
        "objectivec/google/protobuf/Timestamp.pbobjc.m",
        "objectivec/google/protobuf/Type.pbobjc.m",
        "objectivec/google/protobuf/Wrappers.pbobjc.m",
    ],
1110 1111
    visibility = ["//visibility:public"],
)
1112 1113 1114 1115 1116 1117 1118 1119 1120

################################################################################
# Test generated proto support
################################################################################

genrule(
    name = "generated_protos",
    srcs = ["src/google/protobuf/unittest_import.proto"],
    outs = ["unittest_gen.proto"],
1121
    cmd = "cat $(SRCS) | sed 's|google/|src/google/|' >  $(OUTS)",
1122 1123 1124 1125
)

proto_library(
    name = "generated_protos_proto",
1126 1127
    srcs = [
        "src/google/protobuf/unittest_import_public.proto",
1128
        "unittest_gen.proto",
1129
    ],
1130 1131 1132 1133 1134 1135
)

py_proto_library(
    name = "generated_protos_py",
    srcs = [
        "src/google/protobuf/unittest_import_public.proto",
1136
        "unittest_gen.proto",
1137 1138 1139 1140
    ],
    default_runtime = "",
    protoc = ":protoc",
)
1141 1142 1143 1144 1145 1146 1147

################################################################################
# Conformance tests
################################################################################

proto_library(
    name = "test_messages_proto2_proto",
1148
    srcs = ["src/google/protobuf/test_messages_proto2.proto"],
Josh Haberman's avatar
Josh Haberman committed
1149
    visibility = ["//visibility:public"],
1150 1151 1152 1153
)

proto_library(
    name = "test_messages_proto3_proto",
1154
    srcs = ["src/google/protobuf/test_messages_proto3.proto"],
1155
    visibility = ["//visibility:public"],
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
    deps = [
        ":any_proto",
        ":duration_proto",
        ":field_mask_proto",
        ":struct_proto",
        ":timestamp_proto",
        ":wrappers_proto",
    ],
)

cc_proto_library(
    name = "test_messages_proto2_proto_cc",
1168
    srcs = ["src/google/protobuf/test_messages_proto2.proto"],
1169 1170 1171 1172
)

cc_proto_library(
    name = "test_messages_proto3_proto_cc",
1173
    srcs = ["src/google/protobuf/test_messages_proto3.proto"],
1174 1175 1176 1177 1178 1179 1180
    deps = [
        ":cc_wkt_protos",
    ],
)

proto_library(
    name = "conformance_proto",
1181
    srcs = ["conformance/conformance.proto"],
Josh Haberman's avatar
Josh Haberman committed
1182
    visibility = ["//visibility:public"],
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
)

cc_proto_library(
    name = "conformance_proto_cc",
    srcs = ["conformance/conformance.proto"],
)

cc_library(
    name = "jsoncpp",
    srcs = ["conformance/third_party/jsoncpp/jsoncpp.cpp"],
1193
    hdrs = ["conformance/third_party/jsoncpp/json.h"],
1194 1195 1196 1197 1198 1199 1200
    includes = ["conformance"],
)

cc_library(
    name = "conformance_test",
    srcs = [
        "conformance/conformance_test.cc",
1201
        "conformance/conformance_test_runner.cc",
1202 1203 1204 1205
    ],
    hdrs = [
        "conformance/conformance_test.h",
    ],
1206 1207 1208 1209
    includes = [
        "conformance",
        "src",
    ],
1210 1211 1212 1213 1214 1215 1216
    deps = [":conformance_proto_cc"],
)

cc_library(
    name = "binary_json_conformance_suite",
    srcs = ["conformance/binary_json_conformance_suite.cc"],
    hdrs = ["conformance/binary_json_conformance_suite.h"],
1217
    deps = [
1218
        ":conformance_test",
1219 1220 1221 1222 1223 1224
        ":jsoncpp",
        ":test_messages_proto2_proto_cc",
        ":test_messages_proto3_proto_cc",
    ],
)

1225 1226 1227 1228 1229 1230 1231 1232
cc_library(
    name = "text_format_conformance_suite",
    srcs = ["conformance/text_format_conformance_suite.cc"],
    hdrs = ["conformance/text_format_conformance_suite.h"],
    deps = [
        ":conformance_test",
        ":test_messages_proto2_proto_cc",
        ":test_messages_proto3_proto_cc",
1233
    ],
1234 1235
)

1236
cc_binary(
1237 1238
    name = "conformance_test_runner",
    srcs = ["conformance/conformance_test_main.cc"],
1239
    visibility = ["//visibility:public"],
1240
    deps = [
1241
        ":binary_json_conformance_suite",
1242
        ":conformance_test",
1243
        ":text_format_conformance_suite",
Josh Haberman's avatar
Josh Haberman committed
1244
    ],
1245
)
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262

sh_test(
    name = "build_files_updated_unittest",
    srcs = [
        "build_files_updated_unittest.sh",
    ],
    data = [
        "BUILD",
        "cmake/extract_includes.bat.in",
        "cmake/libprotobuf.cmake",
        "cmake/libprotobuf-lite.cmake",
        "cmake/libprotoc.cmake",
        "cmake/tests.cmake",
        "src/Makefile.am",
        "update_file_lists.sh",
    ],
)