Skip to content

Commit

Permalink
java_grpc_library: Add support for protobuf lite
Browse files Browse the repository at this point in the history
gRPC's protobuf-lite auto-selects between full and lite protobuf based on the
value of crosstool_top. If the user is specifying their own
--android_crosstool_top, then it will not auto-detect correctly. One day,
platforms will fix problems like this, but for the moment it seems we get to
live with it.
  • Loading branch information
ejona86 committed Mar 31, 2018
1 parent c1de4e6 commit 88b80c6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
9 changes: 5 additions & 4 deletions java_grpc_library.bzl
Expand Up @@ -109,14 +109,15 @@ def java_grpc_library(name, srcs, deps, flavor=None,
added_deps = [
"@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//stub",
"@io_grpc_grpc_java//protobuf",
"@com_google_guava_guava//jar",
]
if flavor == "normal":
added_deps += ["@com_google_protobuf//:protobuf_java"]
added_deps += [
"@com_google_protobuf//:protobuf_java",
"@io_grpc_grpc_java//protobuf",
]
elif flavor == "lite":
# TODO: This is currently blocked on https://github.com/google/protobuf/issues/2762
added_deps += ["@com_google_protobuf_java_lite//:protobuf_java_lite"]
added_deps += ["@io_grpc_grpc_java//protobuf-lite"]
else:
fail("Unknown flavor type", "flavor")

Expand Down
22 changes: 17 additions & 5 deletions protobuf-lite/BUILD.bazel
@@ -1,14 +1,26 @@
java_library(
name = "protobuf_lite",
name = "protobuf-lite",
srcs = glob([
"src/main/java/**/*.java",
]),
# TOOD(zdapeng): fix visibility and deps (https://github.com/google/protobuf/issues/2762)
visibility = ["//protobuf:__pkg__"],
visibility = ["//visibility:public"],
deps = [
"//core",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
],
] + select({
":android": ["@com_google_protobuf_javalite//:protobuf_java_lite"],
"//conditions:default": ["@com_google_protobuf//:protobuf_java"],
}),
)

# This config is not fully-reliable. If it breaks, it is probably because you
# are changing --android_crosstool_top. Instead of doing that, you can bind
# your own toolchain on top of the default android/closstool, as mentioned at
# https://github.com/bazelbuild/bazel/issues/3924#issuecomment-338704582
config_setting(
name = "android",
values = {
"crosstool_top": "//external:android/crosstool",
},
)
2 changes: 1 addition & 1 deletion protobuf/BUILD.bazel
Expand Up @@ -6,7 +6,7 @@ java_library(
visibility = ["//visibility:public"],
deps = [
"//core",
"//protobuf-lite:protobuf_lite",
"//protobuf-lite",
"@com_google_api_grpc_proto_google_common_protos//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
Expand Down
12 changes: 12 additions & 0 deletions repositories.bzl
Expand Up @@ -9,6 +9,7 @@ def grpc_java_repositories(
omit_com_google_guava=False,
omit_com_google_protobuf=False,
omit_com_google_protobuf_java=False,
omit_com_google_protobuf_javalite=False,
omit_com_google_protobuf_nano_protobuf_javanano=False,
omit_com_google_truth_truth=False,
omit_com_squareup_okhttp=False,
Expand Down Expand Up @@ -45,6 +46,8 @@ def grpc_java_repositories(
com_google_protobuf()
if omit_com_google_protobuf_java:
fail("omit_com_google_protobuf_java is no longer supported and must be not be passed to grpc_java_repositories()")
if not omit_com_google_protobuf_javalite:
com_google_protobuf_javalite()
if not omit_com_google_protobuf_nano_protobuf_javanano:
com_google_protobuf_nano_protobuf_javanano()
if not omit_com_google_truth_truth:
Expand Down Expand Up @@ -146,6 +149,15 @@ def com_google_protobuf():
urls = ["https://github.com/google/protobuf/archive/v3.5.1.zip"],
)

def com_google_protobuf_javalite():
# java_lite_proto_library rules implicitly depend on @com_google_protobuf_javalite
native.http_archive(
name = "com_google_protobuf_javalite",
sha256 = "d8a2fed3708781196f92e1e7e7e713cf66804bd2944894401057214aff4f468e",
strip_prefix = "protobuf-5e8916e881c573c5d83980197a6f783c132d4276",
urls = ["https://github.com/google/protobuf/archive/5e8916e881c573c5d83980197a6f783c132d4276.zip"],
)

def com_google_protobuf_nano_protobuf_javanano():
native.maven_jar(
name = "com_google_protobuf_nano_protobuf_javanano",
Expand Down

0 comments on commit 88b80c6

Please sign in to comment.