Skip to content

Commit bace06f

Browse files
authored
java_grpc_library: Add support for protobuf lite
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.
1 parent b1d91b9 commit bace06f

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

java_grpc_library.bzl

+5-4
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ def java_grpc_library(name, srcs, deps, flavor=None,
109109
added_deps = [
110110
"@io_grpc_grpc_java//core",
111111
"@io_grpc_grpc_java//stub",
112-
"@io_grpc_grpc_java//protobuf",
113112
"@com_google_guava_guava//jar",
114113
]
115114
if flavor == "normal":
116-
added_deps += ["@com_google_protobuf//:protobuf_java"]
115+
added_deps += [
116+
"@com_google_protobuf//:protobuf_java",
117+
"@io_grpc_grpc_java//protobuf",
118+
]
117119
elif flavor == "lite":
118-
# TODO: This is currently blocked on https://github.com/google/protobuf/issues/2762
119-
added_deps += ["@com_google_protobuf_java_lite//:protobuf_java_lite"]
120+
added_deps += ["@io_grpc_grpc_java//protobuf-lite"]
120121
else:
121122
fail("Unknown flavor type", "flavor")
122123

protobuf-lite/BUILD.bazel

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
java_library(
2-
name = "protobuf_lite",
2+
name = "protobuf-lite",
33
srcs = glob([
44
"src/main/java/**/*.java",
55
]),
6-
# TOOD(zdapeng): fix visibility and deps (https://github.com/google/protobuf/issues/2762)
7-
visibility = ["//protobuf:__pkg__"],
6+
visibility = ["//visibility:public"],
87
deps = [
98
"//core",
109
"@com_google_code_findbugs_jsr305//jar",
1110
"@com_google_guava_guava//jar",
12-
"@com_google_protobuf//:protobuf_java",
13-
],
11+
] + select({
12+
":android": ["@com_google_protobuf_javalite//:protobuf_java_lite"],
13+
"//conditions:default": ["@com_google_protobuf//:protobuf_java"],
14+
}),
15+
)
16+
17+
# This config is not fully-reliable. If it breaks, it is probably because you
18+
# are changing --android_crosstool_top. Instead of doing that, you can bind
19+
# your own toolchain on top of the default android/crosstool, as mentioned at
20+
# https://github.com/bazelbuild/bazel/issues/3924#issuecomment-338704582
21+
config_setting(
22+
name = "android",
23+
values = {
24+
"crosstool_top": "//external:android/crosstool",
25+
},
1426
)

protobuf/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ java_library(
66
visibility = ["//visibility:public"],
77
deps = [
88
"//core",
9-
"//protobuf-lite:protobuf_lite",
9+
"//protobuf-lite",
1010
"@com_google_api_grpc_proto_google_common_protos//jar",
1111
"@com_google_code_findbugs_jsr305//jar",
1212
"@com_google_guava_guava//jar",

repositories.bzl

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def grpc_java_repositories(
99
omit_com_google_guava=False,
1010
omit_com_google_protobuf=False,
1111
omit_com_google_protobuf_java=False,
12+
omit_com_google_protobuf_javalite=False,
1213
omit_com_google_protobuf_nano_protobuf_javanano=False,
1314
omit_com_google_truth_truth=False,
1415
omit_com_squareup_okhttp=False,
@@ -45,6 +46,8 @@ def grpc_java_repositories(
4546
com_google_protobuf()
4647
if omit_com_google_protobuf_java:
4748
fail("omit_com_google_protobuf_java is no longer supported and must be not be passed to grpc_java_repositories()")
49+
if not omit_com_google_protobuf_javalite:
50+
com_google_protobuf_javalite()
4851
if not omit_com_google_protobuf_nano_protobuf_javanano:
4952
com_google_protobuf_nano_protobuf_javanano()
5053
if not omit_com_google_truth_truth:
@@ -146,6 +149,15 @@ def com_google_protobuf():
146149
urls = ["https://github.com/google/protobuf/archive/v3.5.1.zip"],
147150
)
148151

152+
def com_google_protobuf_javalite():
153+
# java_lite_proto_library rules implicitly depend on @com_google_protobuf_javalite
154+
native.http_archive(
155+
name = "com_google_protobuf_javalite",
156+
sha256 = "d8a2fed3708781196f92e1e7e7e713cf66804bd2944894401057214aff4f468e",
157+
strip_prefix = "protobuf-5e8916e881c573c5d83980197a6f783c132d4276",
158+
urls = ["https://github.com/google/protobuf/archive/5e8916e881c573c5d83980197a6f783c132d4276.zip"],
159+
)
160+
149161
def com_google_protobuf_nano_protobuf_javanano():
150162
native.maven_jar(
151163
name = "com_google_protobuf_nano_protobuf_javanano",

0 commit comments

Comments
 (0)