|
|
|
# This BUILD file shows how to use protobuf with bazel. Before you can use
|
|
|
|
# proto_library/<lang>_proto_library rules in a BUILD file, you need to
|
|
|
|
# include protobuf repo as remote repositories in your WORKSPACE file. See
|
|
|
|
# the WORKSPACE file in the same directory with this BUILD file for an
|
|
|
|
# example.
|
|
|
|
|
|
|
|
load("@bazel_skylib//rules:build_test.bzl", "build_test")
|
|
|
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_proto_library")
|
|
|
|
load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
|
|
|
|
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
|
|
|
|
load("@rules_proto//proto:defs.bzl", "proto_library")
|
|
|
|
|
|
|
|
# For each .proto file, a proto_library target should be defined. This target
|
|
|
|
# is not bound to any particular language. Instead, it defines the dependency
|
|
|
|
# graph of the .proto files (i.e., proto imports) and serves as the provider
|
|
|
|
# of .proto source files to the protocol compiler.
|
|
|
|
#
|
|
|
|
# Remote repository "com_google_protobuf" must be defined to use this rule.
|
|
|
|
proto_library(
|
|
|
|
name = "addressbook_proto",
|
|
|
|
srcs = ["addressbook.proto"],
|
|
|
|
deps = ["@com_google_protobuf//:timestamp_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
# The cc_proto_library rule generates C++ code for a proto_library rule. It
|
|
|
|
# must have exactly one proto_library dependency. If you want to use multiple
|
|
|
|
# proto_library targets, create a separate cc_proto_library target for each
|
|
|
|
# of them.
|
|
|
|
#
|
|
|
|
# Remote repository "com_google_protobuf_cc" must be defined to use this rule.
|
|
|
|
cc_proto_library(
|
|
|
|
name = "addressbook_cc_proto",
|
|
|
|
deps = [":addressbook_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
# cc_library/cc_binary targets can depend on cc_proto_library targets.
|
|
|
|
cc_binary(
|
|
|
|
name = "add_person_cpp",
|
|
|
|
srcs = ["add_person.cc"],
|
|
|
|
deps = [
|
|
|
|
":addressbook_cc_proto",
|
|
|
|
"@com_google_protobuf//:protobuf",
|
Breaking change: make protobuf comply with the C++ layering check
This check enforces that each C++ build target has the correct dependencies for
all headers that it includes. We have many targets that were not correct with
respect to this check, so I fixed them up.
I also cleaned up the C++ targets related to the well-known types. I created a
cc_proto_library() target for each one and removed the :wkt_cc_protos target,
since this was necessary to satisfy the layering check. I deleted the
//src/google/protobuf:protobuf_nowkt target and deprecated :protobuf_nowkt,
because the distinction between the :protobuf and :protobuf_nowkt targets was
not really correct. Neither one exposed the headers for the well-known types in
a way that was valid with respect to the layering check, and the idea of
bundling all the well-known types together is not idiomatic in Bazel anyway.
This is a breaking change, because the //:protobuf target no longer bundles the
well-known types. From now on they should be accessed through the new
//:*_cc_proto aliases in our top-level package.
I renamed the :port_def target to :port, which simplifies things a bit by
matching our internal name.
The original motivation for this change was that to move utf8_range onto our CI
infrastructure, we needed to make its dependency rules_fuzzing compatible with
Bazel 6. The rules_fuzzing project builds with the layering check, and I found
that the process of upgrading it to Bazel 6 made it take a dependency on
protobuf, which caused it to break due to layering violations. I was able to
work around this, but it would still be nice to comply with the layering check
so that we don't have to worry about this kind of thing in the future.
PiperOrigin-RevId: 595516736
11 months ago
|
|
|
"@com_google_protobuf//src/google/protobuf/util:time_util",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
cc_binary(
|
|
|
|
name = "list_people_cpp",
|
|
|
|
srcs = ["list_people.cc"],
|
|
|
|
deps = [
|
|
|
|
":addressbook_cc_proto",
|
|
|
|
"@com_google_protobuf//:protobuf",
|
Breaking change: make protobuf comply with the C++ layering check
This check enforces that each C++ build target has the correct dependencies for
all headers that it includes. We have many targets that were not correct with
respect to this check, so I fixed them up.
I also cleaned up the C++ targets related to the well-known types. I created a
cc_proto_library() target for each one and removed the :wkt_cc_protos target,
since this was necessary to satisfy the layering check. I deleted the
//src/google/protobuf:protobuf_nowkt target and deprecated :protobuf_nowkt,
because the distinction between the :protobuf and :protobuf_nowkt targets was
not really correct. Neither one exposed the headers for the well-known types in
a way that was valid with respect to the layering check, and the idea of
bundling all the well-known types together is not idiomatic in Bazel anyway.
This is a breaking change, because the //:protobuf target no longer bundles the
well-known types. From now on they should be accessed through the new
//:*_cc_proto aliases in our top-level package.
I renamed the :port_def target to :port, which simplifies things a bit by
matching our internal name.
The original motivation for this change was that to move utf8_range onto our CI
infrastructure, we needed to make its dependency rules_fuzzing compatible with
Bazel 6. The rules_fuzzing project builds with the layering check, and I found
that the process of upgrading it to Bazel 6 made it take a dependency on
protobuf, which caused it to break due to layering violations. I was able to
work around this, but it would still be nice to comply with the layering check
so that we don't have to worry about this kind of thing in the future.
PiperOrigin-RevId: 595516736
11 months ago
|
|
|
"@com_google_protobuf//src/google/protobuf/util:time_util",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Similar to cc_proto_library but for Java.
|
|
|
|
#
|
|
|
|
# Remote repository "com_google_protobuf_java" must be defined to use this rule.
|
|
|
|
java_proto_library(
|
|
|
|
name = "addressbook_java_proto",
|
|
|
|
deps = [":addressbook_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
java_binary(
|
|
|
|
name = "add_person_java",
|
|
|
|
srcs = ["AddPerson.java"],
|
|
|
|
main_class = "AddPerson",
|
|
|
|
deps = [":addressbook_java_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
java_binary(
|
|
|
|
name = "list_people_java",
|
|
|
|
srcs = ["ListPeople.java"],
|
|
|
|
main_class = "ListPeople",
|
|
|
|
deps = [":addressbook_java_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Java lite.
|
|
|
|
#
|
|
|
|
# Remote repository "com_google_protobuf_javalite" must be defined to use this
|
|
|
|
# rule.
|
|
|
|
java_lite_proto_library(
|
|
|
|
name = "addressbook_java_lite_proto",
|
|
|
|
deps = [":addressbook_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Java lite API is a subset of the regular Java API so if you only uses this
|
|
|
|
# subset in your code, you can actually compile your code against both (i.e.,
|
|
|
|
# share code between server build and Android build).
|
|
|
|
#
|
|
|
|
# The lite version has a smaller code size, and you can see that by comparing
|
|
|
|
# the resulted .jar file:
|
|
|
|
#
|
|
|
|
# $ bazel build :add_person_java_deploy.jar :add_person_java_lite_deploy.jar
|
|
|
|
# $ ls -l bazel-bin/*_deploy.jar
|
|
|
|
# -r-xr-xr-x 1 xiaofeng eng 1230797 Sep 8 12:24 bazel-bin/add_person_java_deploy.jar
|
|
|
|
# -r-xr-xr-x 1 xiaofeng eng 236166 Sep 8 12:24 bazel-bin/add_person_java_lite_deploy.jar
|
|
|
|
#
|
|
|
|
# In the above example, the lite .jar file is 6 times smaller. With proper
|
|
|
|
# proguard inlining/stripping, the difference can be much more larger than
|
|
|
|
# that.
|
|
|
|
java_binary(
|
|
|
|
name = "add_person_java_lite",
|
|
|
|
srcs = ["AddPerson.java"],
|
|
|
|
main_class = "AddPerson",
|
|
|
|
deps = [":addressbook_java_lite_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
java_binary(
|
|
|
|
name = "list_people_java_lite",
|
|
|
|
srcs = ["ListPeople.java"],
|
|
|
|
main_class = "ListPeople",
|
|
|
|
deps = [":addressbook_java_lite_proto"],
|
|
|
|
)
|
|
|
|
|
|
|
|
build_test(
|
|
|
|
name = "test",
|
|
|
|
targets = [
|
|
|
|
":add_person_cpp",
|
|
|
|
":add_person_java",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Files included in all source distributions
|
|
|
|
pkg_files(
|
|
|
|
name = "dist_files",
|
|
|
|
srcs = [
|
|
|
|
"AddPerson.java",
|
|
|
|
"BUILD.bazel",
|
|
|
|
"CMakeLists.txt",
|
|
|
|
"ListPeople.java",
|
|
|
|
"Makefile",
|
|
|
|
"README.md",
|
|
|
|
"WORKSPACE",
|
|
|
|
"add_person.cc",
|
|
|
|
"add_person.dart",
|
|
|
|
"add_person.py",
|
|
|
|
"addressbook.proto",
|
|
|
|
"go/cmd/add_person/add_person.go",
|
|
|
|
"go/cmd/add_person/add_person_test.go",
|
|
|
|
"go/cmd/list_people/list_people.go",
|
|
|
|
"go/cmd/list_people/list_people_test.go",
|
|
|
|
"go/go.mod",
|
|
|
|
"go/go.sum",
|
|
|
|
"list_people.cc",
|
|
|
|
"list_people.dart",
|
|
|
|
"list_people.py",
|
|
|
|
"pubspec.yaml",
|
|
|
|
],
|
|
|
|
prefix = "examples/",
|
|
|
|
strip_prefix = strip_prefix.from_root(""),
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|