Protocol Buffers - Google's data interchange format (grpc依赖) https://developers.google.com/protocol-buffers/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

522 lines
14 KiB

# Bazel (https://bazel.build/) BUILD file for Protobuf.
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "cc_test")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
load(":protobuf.bzl", "py_proto_library")
licenses(["notice"])
exports_files(["LICENSE"])
################################################################################
# Well Known Types Proto Library Rules
#
# https://developers.google.com/protocol-buffers/docs/reference/google.protobuf
################################################################################
# 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],
# )
################################################################################
alias(
name = "any_proto",
actual = "//src/google/protobuf:any_proto",
visibility = ["//visibility:public"],
)
alias(
name = "api_proto",
actual = "//src/google/protobuf:api_proto",
visibility = ["//visibility:public"],
)
alias(
name = "duration_proto",
actual = "//src/google/protobuf:duration_proto",
visibility = ["//visibility:public"],
)
alias(
name = "empty_proto",
actual = "//src/google/protobuf:empty_proto",
visibility = ["//visibility:public"],
)
alias(
name = "field_mask_proto",
actual = "//src/google/protobuf:field_mask_proto",
visibility = ["//visibility:public"],
)
alias(
name = "source_context_proto",
actual = "//src/google/protobuf:source_context_proto",
visibility = ["//visibility:public"],
)
alias(
name = "struct_proto",
actual = "//src/google/protobuf:struct_proto",
visibility = ["//visibility:public"],
)
alias(
name = "timestamp_proto",
actual = "//src/google/protobuf:timestamp_proto",
visibility = ["//visibility:public"],
)
alias(
name = "type_proto",
actual = "//src/google/protobuf:type_proto",
visibility = ["//visibility:public"],
)
alias(
name = "wrappers_proto",
actual = "//src/google/protobuf:wrappers_proto",
visibility = ["//visibility:public"],
)
# Source files: these are aliases to a filegroup, not a `proto_library`.
#
# (This is _probably_ not what you want.)
alias(
name = "lite_well_known_protos",
actual = "//src/google/protobuf:well_known_type_protos", # filegroup
visibility = ["//visibility:public"],
)
alias(
name = "well_known_type_protos",
actual = "//src/google/protobuf:well_known_type_protos", # filegroup
visibility = ["//visibility:public"],
)
# Built-in runtime protos: these are part of protobuf's internal
# implementation, but are not Well-Known Types.
alias(
name = "descriptor_proto",
actual = "//src/google/protobuf:descriptor_proto", # proto_library
visibility = ["//visibility:public"],
)
alias(
name = "descriptor_proto_srcs",
actual = "//src/google/protobuf:descriptor_proto_srcs", # filegroup
visibility = ["//visibility:public"],
)
alias(
name = "compiler_plugin_proto",
actual = "//src/google/protobuf/compiler:plugin_proto", # proto_library
visibility = ["//visibility:public"],
)
cc_library(
name = "cc_wkt_protos",
deprecation = "Only for backward compatibility. Do not use.",
visibility = ["//visibility:public"],
)
# Source protos that are typically part of the protobuf runtime.
#
# DEPRECATED: Prefer :well_known_type_protos for the Well-Known Types
# (https://developers.google.com/protocol-buffers/docs/reference/google.protobuf)
# or :descriptor_proto(_srcs) for descriptor.proto (source), or
# :compiler_plugin_proto for compiler/plugin.proto.
filegroup(
name = "well_known_protos",
srcs = [
":descriptor_proto_srcs",
":well_known_type_protos",
"//src/google/protobuf/compiler:plugin.proto",
],
deprecation = "Prefer :well_known_type_protos instead.",
visibility = ["//visibility:public"],
)
################################################################################
# Protocol Buffers Compiler
################################################################################
cc_binary(
name = "protoc",
linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
visibility = ["//visibility:public"],
deps = ["//src/google/protobuf/compiler:protoc_lib"],
)
################################################################################
# C++ runtime
################################################################################
# The "lite" runtime works for .proto files that specify the option:
# optimize_for = LITE_RUNTIME;
#
# The lite runtime does not include the `Reflection` APIs (including
# `Descriptor` and related types) or Well-Known Types.
#
# See also:
# https://developers.google.com/protocol-buffers/docs/reference/cpp-generated#message
# https://developers.google.com/protocol-buffers/docs/reference/google.protobuf
alias(
name = "protobuf_lite",
actual = "//src/google/protobuf:protobuf_lite",
visibility = ["//visibility:public"],
)
cc_library(
name = "protobuf",
hdrs = glob([
"src/**/*.h",
"src/**/*.inc",
]),
copts = COPTS,
include_prefix = "google/protobuf/io",
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = [
"//src/google/protobuf",
"//src/google/protobuf/compiler:importer",
"//src/google/protobuf/util:delimited_message_util",
"//src/google/protobuf/util:differencer",
"//src/google/protobuf/util:field_mask_util",
"//src/google/protobuf/util:json_util",
"//src/google/protobuf/util:time_util",
"//src/google/protobuf/util:type_resolver_util",
],
)
# 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.
alias(
name = "protobuf_headers",
actual = "//src/google/protobuf:protobuf_headers",
visibility = ["//visibility:public"],
)
################################################################################
# Java support
################################################################################
alias(
name = "protobuf_java",
actual = "//java/core",
visibility = ["//visibility:public"],
)
alias(
name = "protobuf_javalite",
actual = "//java/lite",
visibility = ["//visibility:public"],
)
alias(
name = "protobuf_java_util",
actual = "//java/util",
visibility = ["//visibility:public"],
)
alias(
name = "java_toolchain",
actual = "//java/core:toolchain",
visibility = ["//visibility:public"],
)
alias(
name = "javalite_toolchain",
actual = "//java/lite:toolchain",
visibility = ["//visibility:public"],
)
################################################################################
# Python support
################################################################################
alias(
name = "protobuf_python",
actual = "//python:protobuf_python",
visibility = ["//visibility:public"],
)
alias(
name = "python_srcs",
actual = "//python:python_srcs",
visibility = ["@upb//:__subpackages__"],
)
alias(
name = "python_test_srcs",
actual = "//python:python_test_srcs",
visibility = ["@upb//:__subpackages__"],
)
alias(
name = "well_known_types_py_pb2",
actual = "//python:well_known_types_py_pb2",
visibility = ["@upb//:__subpackages__"],
)
alias(
name = "python_common_test_protos",
actual = "//python:python_common_test_protos",
visibility = ["//visibility:public"],
)
alias(
name = "python_specific_test_protos",
actual = "//python:python_specific_test_protos",
visibility = ["//visibility:public"],
)
proto_lang_toolchain(
name = "cc_toolchain",
blacklisted_protos = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:api_proto",
"@com_google_protobuf//:compiler_plugin_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:field_mask_proto",
"@com_google_protobuf//:source_context_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:type_proto",
"@com_google_protobuf//:wrappers_proto",
],
command_line = "--cpp_out=$(OUT)",
runtime = ":protobuf",
visibility = ["//visibility:public"],
)
alias(
name = "objectivec",
actual = "//objectivec",
tags = ["manual"],
visibility = ["//visibility:public"],
)
alias(
name = "protobuf_objc",
actual = "//objectivec",
tags = ["manual"],
visibility = ["//visibility:public"],
)
################################################################################
# Test protos
################################################################################
alias(
name = "lite_test_protos",
actual = "//src/google/protobuf:lite_test_protos", # proto_library
visibility = ["//:__subpackages__"],
)
alias(
name = "test_proto_srcs",
actual = "//src/google/protobuf:test_proto_srcs", # filegroup
visibility = ["//:__subpackages__"],
)
alias(
name = "test_protos",
actual = "//src/google/protobuf:test_protos", # proto_library
visibility = ["//:__subpackages__"],
)
# Validate generated proto source inputs:
genrule(
name = "generated_protos",
testonly = 1,
srcs = ["//src/google/protobuf:test_proto_srcs"],
outs = ["unittest_gen_import.proto"],
cmd = "cat src/google/protobuf/unittest_import.proto > $@",
)
proto_library(
name = "generated_protos_proto",
testonly = 1,
srcs = [":generated_protos"],
deps = ["//src/google/protobuf:generic_test_protos"],
)
py_proto_library(
name = "generated_protos_py",
testonly = 1,
srcs = [":generated_protos"],
default_runtime = "",
protoc = ":protoc",
deps = ["//python:python_common_test_protos"],
)
################################################################################
# Conformance tests
################################################################################
alias(
name = "conformance_test_runner",
actual = "//conformance:conformance_test_runner",
visibility = ["//visibility:public"],
)
alias(
name = "test_messages_proto2_proto",
actual = "//src/google/protobuf:test_messages_proto2_proto", # proto_library
visibility = ["//visibility:public"],
)
alias(
name = "test_messages_proto3_proto",
actual = "//src/google/protobuf:test_messages_proto3_proto", # proto_library
visibility = ["//visibility:public"],
)
# TODO: re-enable this test if appropriate, or replace with something that
# uses the new setup.
# 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",
# ],
# )
java_proto_library(
name = "test_messages_proto2_java_proto",
visibility = [
"//conformance:__pkg__",
"//java:__subpackages__",
],
deps = [":test_messages_proto2_proto"],
)
java_proto_library(
name = "test_messages_proto3_java_proto",
visibility = [
"//conformance:__pkg__",
"//java:__subpackages__",
],
deps = [":test_messages_proto3_proto"],
)
java_lite_proto_library(
name = "test_messages_proto2_java_proto_lite",
visibility = [
"//conformance:__pkg__",
"//java:__subpackages__",
],
deps = [":test_messages_proto2_proto"],
)
java_lite_proto_library(
name = "test_messages_proto3_java_proto_lite",
visibility = [
"//conformance:__pkg__",
"//java:__subpackages__",
],
deps = [":test_messages_proto3_proto"],
)
filegroup(
name = "bzl_srcs",
srcs = glob(["**/*.bzl"]),
visibility = ["//visibility:public"],
)
################################################################################
# Packaging rules
################################################################################
# Files included in all source distributions
pkg_files(
name = "common_dist_files",
srcs = glob(
[
"*.bzl",
"cmake/*.cmake",
"cmake/*.in",
"editors/*",
# Several of these files are generated by autogen.sh, so using
# glob() lets us ignore them if they are missing. (This is not good
# practice, though.)
"Makefile.in",
"aclocal.m4",
"ar-lib",
"compile",
"config*",
"depcomp",
"install-sh",
"ltmain.sh",
"m4/*.m4",
"missing",
"protobuf*.pc.in",
"test-driver",
],
allow_empty = True,
) + [
"BUILD.bazel",
"CHANGES.txt",
"CMakeLists.txt",
"CONTRIBUTORS.txt",
"LICENSE",
"Makefile.am",
"README.md",
"WORKSPACE",
"autogen.sh",
"build_files_updated_unittest.sh",
"cmake/CMakeLists.txt",
"cmake/README.md",
"generate_descriptor_proto.sh",
"maven_install.json",
"update_file_lists.sh",
"//third_party:BUILD.bazel",
"//third_party:zlib.BUILD",
"//util/python:BUILD.bazel",
],
strip_prefix = strip_prefix.from_root(""),
visibility = ["//pkg:__pkg__"],
)
# Additional files for C#
pkg_files(
name = "csharp_dist_files",
srcs = [
"global.json",
],
visibility = ["//pkg:__pkg__"],
)
# Additional files for ObjC
pkg_files(
name = "objectivec_dist_files",
srcs = [
"Protobuf.podspec",
],
visibility = ["//pkg:__pkg__"],
)