1# Bazel (https://bazel.build/) BUILD file for Protobuf. 2 3load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") 4load("@rules_license//rules:license.bzl", "license") 5load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") 6load("//bazel:cc_proto_library.bzl", "cc_proto_library") 7load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library") 8load("//bazel:java_proto_library.bzl", "java_proto_library") 9load("//bazel:proto_library.bzl", "proto_library") 10load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain") 11load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS") 12load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library") 13 14licenses(["notice"]) 15 16exports_files([ 17 "LICENSE", 18 "PrivacyInfo.xcprivacy", 19]) 20 21license( 22 name = "license", 23 package_name = "protobuf", 24 license_text = ":LICENSE", 25) 26 27################################################################################ 28# Well Known Types Proto Library Rules 29# 30# https://developers.google.com/protocol-buffers/docs/reference/google.protobuf 31################################################################################ 32# These proto_library rules can be used with one of the language specific proto 33# library rules i.e. java_proto_library: 34# 35# java_proto_library( 36# name = "any_java_proto", 37# deps = ["@protobuf//:any_proto"], 38# ) 39################################################################################ 40 41alias( 42 name = "any_proto", 43 actual = "//src/google/protobuf:any_proto", 44 visibility = ["//visibility:public"], 45) 46 47alias( 48 name = "api_proto", 49 actual = "//src/google/protobuf:api_proto", 50 visibility = ["//visibility:public"], 51) 52 53alias( 54 name = "duration_proto", 55 actual = "//src/google/protobuf:duration_proto", 56 visibility = ["//visibility:public"], 57) 58 59alias( 60 name = "empty_proto", 61 actual = "//src/google/protobuf:empty_proto", 62 visibility = ["//visibility:public"], 63) 64 65alias( 66 name = "field_mask_proto", 67 actual = "//src/google/protobuf:field_mask_proto", 68 visibility = ["//visibility:public"], 69) 70 71alias( 72 name = "source_context_proto", 73 actual = "//src/google/protobuf:source_context_proto", 74 visibility = ["//visibility:public"], 75) 76 77alias( 78 name = "struct_proto", 79 actual = "//src/google/protobuf:struct_proto", 80 visibility = ["//visibility:public"], 81) 82 83alias( 84 name = "timestamp_proto", 85 actual = "//src/google/protobuf:timestamp_proto", 86 visibility = ["//visibility:public"], 87) 88 89alias( 90 name = "type_proto", 91 actual = "//src/google/protobuf:type_proto", 92 visibility = ["//visibility:public"], 93) 94 95alias( 96 name = "wrappers_proto", 97 actual = "//src/google/protobuf:wrappers_proto", 98 visibility = ["//visibility:public"], 99) 100 101# C++ targets for the well-known types 102 103alias( 104 name = "any_cc_proto", 105 actual = "//src/google/protobuf:any_cc_proto", 106 visibility = ["//visibility:public"], 107) 108 109alias( 110 name = "api_cc_proto", 111 actual = "//src/google/protobuf:api_cc_proto", 112 visibility = ["//visibility:public"], 113) 114 115alias( 116 name = "duration_cc_proto", 117 actual = "//src/google/protobuf:duration_cc_proto", 118 visibility = ["//visibility:public"], 119) 120 121alias( 122 name = "empty_cc_proto", 123 actual = "//src/google/protobuf:empty_cc_proto", 124 visibility = ["//visibility:public"], 125) 126 127alias( 128 name = "field_mask_cc_proto", 129 actual = "//src/google/protobuf:field_mask_cc_proto", 130 visibility = ["//visibility:public"], 131) 132 133alias( 134 name = "source_context_cc_proto", 135 actual = "//src/google/protobuf:source_context_cc_proto", 136 visibility = ["//visibility:public"], 137) 138 139alias( 140 name = "struct_cc_proto", 141 actual = "//src/google/protobuf:struct_cc_proto", 142 visibility = ["//visibility:public"], 143) 144 145alias( 146 name = "timestamp_cc_proto", 147 actual = "//src/google/protobuf:timestamp_cc_proto", 148 visibility = ["//visibility:public"], 149) 150 151alias( 152 name = "type_cc_proto", 153 actual = "//src/google/protobuf:type_cc_proto", 154 visibility = ["//visibility:public"], 155) 156 157alias( 158 name = "wrappers_cc_proto", 159 actual = "//src/google/protobuf:wrappers_cc_proto", 160 visibility = ["//visibility:public"], 161) 162 163# Source files: these are aliases to a filegroup, not a `proto_library`. 164# 165# (This is _probably_ not what you want.) 166alias( 167 name = "lite_well_known_protos", 168 actual = "//src/google/protobuf:well_known_type_protos", # filegroup 169 visibility = ["//visibility:public"], 170) 171 172alias( 173 name = "well_known_type_protos", 174 actual = "//src/google/protobuf:well_known_type_protos", # filegroup 175 visibility = ["//visibility:public"], 176) 177 178# Built-in runtime protos: these are part of protobuf's internal 179# implementation, but are not Well-Known Types. 180 181alias( 182 name = "descriptor_proto", 183 actual = "//src/google/protobuf:descriptor_proto", # proto_library 184 visibility = ["//visibility:public"], 185) 186 187alias( 188 name = "descriptor_proto_srcs", 189 actual = "//src/google/protobuf:descriptor_proto_srcs", # filegroup 190 visibility = ["//visibility:public"], 191) 192 193alias( 194 name = "compiler_plugin_proto", 195 actual = "//src/google/protobuf/compiler:plugin_proto", # proto_library 196 visibility = ["//visibility:public"], 197) 198 199cc_library( 200 name = "cc_wkt_protos", 201 deprecation = "Only for backward compatibility. Do not use.", 202 visibility = ["//visibility:public"], 203) 204 205# Source protos that are typically part of the protobuf runtime. 206# 207# DEPRECATED: Prefer :well_known_type_protos for the Well-Known Types 208# (https://developers.google.com/protocol-buffers/docs/reference/google.protobuf) 209# or :descriptor_proto(_srcs) for descriptor.proto (source), or 210# :compiler_plugin_proto for compiler/plugin.proto. 211filegroup( 212 name = "well_known_protos", 213 srcs = [ 214 ":descriptor_proto_srcs", 215 ":well_known_type_protos", 216 "//src/google/protobuf/compiler:plugin.proto", 217 ], 218 deprecation = "Prefer :well_known_type_protos instead.", 219 visibility = ["//visibility:public"], 220) 221 222################################################################################ 223# Protocol Buffers Compiler 224################################################################################ 225 226alias( 227 name = "protoc_lib", 228 actual = "//src/google/protobuf/compiler:protoc_lib", 229 visibility = ["//visibility:public"], 230) 231 232cc_binary( 233 name = "protoc", 234 copts = COPTS, 235 linkopts = LINK_OPTS, 236 visibility = ["//visibility:public"], 237 deps = ["//src/google/protobuf/compiler:protoc_lib"], 238) 239 240cc_binary( 241 name = "protoc_static", 242 copts = COPTS, 243 features = select({ 244 # This isn't possible on mac because there is no static library for lcrt0.o 245 "@platforms//os:osx": [], 246 "//build_defs:config_osx": [], 247 # When cross-compiling we need to statically link all C++ libraries. 248 "//conditions:default": ["fully_static_link"], 249 }), 250 linkopts = LINK_OPTS, 251 visibility = ["//visibility:public"], 252 deps = ["//src/google/protobuf/compiler:protoc_lib"], 253) 254 255################################################################################ 256# C++ runtime 257################################################################################ 258 259# Expose the runtime for the proto_lang_toolchain so that it can also be used in 260# a user-defined proto_lang_toolchain. 261alias( 262 name = "protobuf", 263 actual = "//src/google/protobuf:protobuf_layering_check_legacy", 264 visibility = ["//visibility:public"], 265) 266 267alias( 268 name = "protobuf_nowkt", 269 actual = "//src/google/protobuf", 270 deprecation = "Use //:protobuf instead", 271 visibility = ["//visibility:public"], 272) 273 274# The "lite" runtime works for .proto files that specify the option: 275# optimize_for = LITE_RUNTIME; 276# 277# The lite runtime does not include the `Reflection` APIs (including 278# `Descriptor` and related types) or Well-Known Types. 279# 280# See also: 281# https://developers.google.com/protocol-buffers/docs/reference/cpp-generated#message 282# https://developers.google.com/protocol-buffers/docs/reference/google.protobuf 283alias( 284 name = "protobuf_lite", 285 actual = "//src/google/protobuf:protobuf_lite", 286 visibility = ["//visibility:public"], 287) 288 289# This provides just the header files for use in projects that need to build 290# shared libraries for dynamic loading. This target is available until Bazel 291# adds native support for such use cases. 292# TODO: Remove this target once the support gets added to Bazel. 293alias( 294 name = "protobuf_headers", 295 actual = "//src/google/protobuf:protobuf_headers", 296 visibility = ["//visibility:public"], 297) 298 299alias( 300 name = "json", 301 actual = "//src/google/protobuf/json", 302 visibility = ["//visibility:public"], 303) 304 305alias( 306 name = "delimited_message_util", 307 actual = "//src/google/protobuf/util:delimited_message_util", 308 visibility = ["//visibility:public"], 309) 310 311alias( 312 name = "differencer", 313 actual = "//src/google/protobuf/util:differencer", 314 visibility = ["//visibility:public"], 315) 316 317alias( 318 name = "field_mask_util", 319 actual = "//src/google/protobuf/util:field_mask_util", 320 visibility = ["//visibility:public"], 321) 322 323alias( 324 name = "json_util", 325 actual = "//src/google/protobuf/util:json_util", 326 visibility = ["//visibility:public"], 327) 328 329alias( 330 name = "time_util", 331 actual = "//src/google/protobuf/util:time_util", 332 visibility = ["//visibility:public"], 333) 334 335alias( 336 name = "type_resolver", 337 actual = "//src/google/protobuf/util:type_resolver", 338 visibility = ["//visibility:public"], 339) 340 341alias( 342 name = "cpp_features_proto", 343 actual = "//src/google/protobuf:cpp_features_proto", # proto_library 344 visibility = ["//visibility:public"], 345) 346 347################################################################################ 348# Java support 349################################################################################ 350 351alias( 352 name = "protobuf_java", 353 actual = "//java/core", 354 visibility = ["//visibility:public"], 355) 356 357alias( 358 name = "protobuf_javalite", 359 actual = "//java/lite", 360 visibility = ["//visibility:public"], 361) 362 363alias( 364 name = "protobuf_java_util", 365 actual = "//java/util", 366 visibility = ["//visibility:public"], 367) 368 369alias( 370 name = "java_toolchain", 371 actual = "//java/core:toolchain", 372 visibility = ["//visibility:public"], 373) 374 375alias( 376 name = "javalite_toolchain", 377 actual = "//java/lite:toolchain", 378 visibility = ["//visibility:public"], 379) 380 381alias( 382 name = "java_features_proto", 383 actual = "//java/core:java_features_proto", # proto_library 384 visibility = ["//visibility:public"], 385) 386 387################################################################################ 388# Python support 389################################################################################ 390 391alias( 392 name = "protobuf_python", 393 actual = "//python:protobuf_python", 394 visibility = ["//visibility:public"], 395) 396 397alias( 398 name = "python_srcs", 399 actual = "//python:python_srcs", 400 visibility = ["//python:__subpackages__"], 401) 402 403alias( 404 name = "python_test_srcs", 405 actual = "//python:python_test_srcs", 406 visibility = ["//python:__subpackages__"], 407) 408 409alias( 410 name = "well_known_types_py_pb2", 411 actual = "//python:well_known_types_py_pb2", 412 visibility = ["//visibility:public"], 413) 414 415alias( 416 name = "python_common_test_protos", 417 actual = "//python:python_common_test_protos", 418 visibility = ["//visibility:public"], 419) 420 421alias( 422 name = "python_specific_test_protos", 423 actual = "//python:python_specific_test_protos", 424 visibility = ["//visibility:public"], 425) 426 427proto_lang_toolchain( 428 name = "cc_toolchain", 429 blacklisted_protos = [ 430 "//:compiler_plugin_proto", 431 "//:cpp_features_proto", 432 "//:descriptor_proto", 433 ], 434 command_line = "--cpp_out=$(OUT)", 435 runtime = "//src/google/protobuf", 436 visibility = ["//visibility:public"], 437) 438 439################################################################################ 440# Objective-C support 441################################################################################ 442 443alias( 444 name = "objectivec", 445 actual = "//objectivec", 446 tags = ["manual"], 447 visibility = ["//visibility:public"], 448) 449 450alias( 451 name = "protobuf_objc", 452 actual = "//objectivec", 453 tags = ["manual"], 454 visibility = ["//visibility:public"], 455) 456 457################################################################################ 458# Rust support 459################################################################################ 460 461alias( 462 name = "protobuf_rust", 463 actual = "//rust:protobuf", 464 visibility = ["//visibility:public"], 465) 466 467################################################################################ 468# Test protos 469################################################################################ 470 471alias( 472 name = "lite_test_proto_srcs", 473 actual = "//src/google/protobuf:lite_test_proto_srcs", # proto_library 474 visibility = ["//:__subpackages__"], 475) 476 477alias( 478 name = "lite_test_protos", 479 actual = "//src/google/protobuf:lite_test_protos", # proto_library 480 visibility = ["//:__subpackages__"], 481) 482 483alias( 484 name = "test_proto_srcs", 485 actual = "//src/google/protobuf:test_proto_srcs", # filegroup 486 visibility = ["//:__subpackages__"], 487) 488 489alias( 490 name = "test_proto_editions_srcs", 491 actual = "//src/google/protobuf:test_proto_editions_srcs", # filegroup 492 visibility = ["//:__subpackages__"], 493) 494 495alias( 496 name = "test_protos", 497 actual = "//src/google/protobuf:test_protos", # proto_library 498 visibility = ["//:__subpackages__"], 499) 500 501# Validate generated proto source inputs: 502 503genrule( 504 name = "generated_protos", 505 testonly = 1, 506 srcs = ["//src/google/protobuf:test_proto_srcs"], 507 outs = ["unittest_gen_import.proto"], 508 cmd = "cat src/google/protobuf/unittest_import.proto > $@", 509) 510 511proto_library( 512 name = "generated_protos_proto", 513 testonly = 1, 514 srcs = [":generated_protos"], 515 deps = ["//src/google/protobuf:generic_test_protos"], 516) 517 518internal_py_proto_library( 519 name = "generated_protos_py", 520 testonly = 1, 521 srcs = [":generated_protos"], 522 default_runtime = "", 523 protoc = ":protoc", 524 deps = ["//python:python_common_test_protos"], 525) 526 527################################################################################ 528# Conformance tests 529################################################################################ 530 531cc_proto_library( 532 name = "test_messages_proto2_cc_proto", 533 visibility = [ 534 "//conformance:__pkg__", 535 "//src:__subpackages__", 536 ], 537 deps = ["//src/google/protobuf:test_messages_proto2_proto"], 538) 539 540cc_proto_library( 541 name = "test_messages_proto3_cc_proto", 542 visibility = [ 543 "//conformance:__pkg__", 544 "//src:__subpackages__", 545 ], 546 deps = ["//src/google/protobuf:test_messages_proto3_proto"], 547) 548 549java_proto_library( 550 name = "test_messages_proto2_java_proto", 551 visibility = [ 552 "//conformance:__pkg__", 553 "//java:__subpackages__", 554 ], 555 deps = ["//src/google/protobuf:test_messages_proto2_proto"], 556) 557 558java_proto_library( 559 name = "test_messages_proto3_java_proto", 560 visibility = [ 561 "//conformance:__pkg__", 562 "//java:__subpackages__", 563 ], 564 deps = ["//src/google/protobuf:test_messages_proto3_proto"], 565) 566 567java_lite_proto_library( 568 name = "test_messages_proto2_java_proto_lite", 569 visibility = [ 570 "//conformance:__pkg__", 571 "//java:__subpackages__", 572 ], 573 deps = ["//src/google/protobuf:test_messages_proto2_proto"], 574) 575 576java_lite_proto_library( 577 name = "test_messages_proto3_java_proto_lite", 578 visibility = [ 579 "//conformance:__pkg__", 580 "//java:__subpackages__", 581 ], 582 deps = ["//src/google/protobuf:test_messages_proto3_proto"], 583) 584 585internal_objc_proto_library( 586 name = "test_messages_proto2_objc_proto", 587 testonly = 1, 588 srcs = ["//src/google/protobuf:test_messages_proto2.proto"], 589 includes = ["src/google/protobuf"], 590 visibility = [ 591 "//conformance:__pkg__", 592 "//objectivec:__subpackages__", 593 ], 594) 595 596internal_objc_proto_library( 597 name = "test_messages_proto3_objc_proto", 598 testonly = 1, 599 srcs = ["//src/google/protobuf:test_messages_proto3.proto"], 600 includes = [ 601 "src/google/protobuf", 602 # The above must come first. 603 "src", 604 ], 605 proto_deps = [":well_known_protos"], 606 visibility = [ 607 "//conformance:__pkg__", 608 "//objectivec:__subpackages__", 609 ], 610) 611 612internal_php_proto_library( 613 name = "test_messages_proto3_php_proto", 614 testonly = 1, 615 srcs = ["//src/google/protobuf:test_messages_proto3.proto"], 616 outs = [ 617 "GPBMetadata/TestMessagesProto3.php", 618 "Protobuf_test_messages/Proto3/EnumOnlyProto3.php", 619 "Protobuf_test_messages/Proto3/EnumOnlyProto3/PBBool.php", 620 "Protobuf_test_messages/Proto3/ForeignEnum.php", 621 "Protobuf_test_messages/Proto3/ForeignMessage.php", 622 "Protobuf_test_messages/Proto3/NullHypothesisProto3.php", 623 "Protobuf_test_messages/Proto3/TestAllTypesProto3.php", 624 "Protobuf_test_messages/Proto3/TestAllTypesProto3/AliasedEnum.php", 625 "Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php", 626 "Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php", 627 ], 628 includes = [ 629 "src/google/protobuf", 630 # The above must come first. 631 "src", 632 ], 633 proto_deps = [":well_known_protos"], 634 visibility = [ 635 "//conformance:__pkg__", 636 "//php:__subpackages__", 637 ], 638) 639 640filegroup( 641 name = "bzl_srcs", 642 srcs = glob(["**/*.bzl"]), 643 visibility = ["//visibility:public"], 644) 645 646################################################################################ 647# Packaging rules 648################################################################################ 649 650# Files included in all source distributions 651pkg_files( 652 name = "common_dist_files", 653 srcs = glob( 654 [ 655 "*.bzl", 656 "cmake/*.cmake", 657 "cmake/*.in", 658 "editors/*", 659 ], 660 allow_empty = True, 661 ) + [ 662 "BUILD.bazel", 663 "CMakeLists.txt", 664 "CONTRIBUTORS.txt", 665 "LICENSE", 666 "README.md", 667 "WORKSPACE", 668 "cmake/README.md", 669 "generate_descriptor_proto.sh", 670 "maven_install.json", 671 "//third_party:BUILD.bazel", 672 "//third_party:zlib.BUILD", 673 ], 674 strip_prefix = strip_prefix.from_root(""), 675 visibility = ["//pkg:__pkg__"], 676) 677 678# Additional files for C# 679pkg_files( 680 name = "csharp_dist_files", 681 srcs = [ 682 "global.json", 683 ], 684 visibility = ["//pkg:__pkg__"], 685) 686 687# Additional files for ObjC 688pkg_files( 689 name = "objectivec_dist_files", 690 srcs = [ 691 "Protobuf.podspec", 692 ], 693 visibility = ["//pkg:__pkg__"], 694) 695