-
Notifications
You must be signed in to change notification settings - Fork 4k
Adopt proto_lang_toolchain for java_grpc_library() #12994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
18c1fb9
fa8710e
c427419
091d318
cc9151d
00f4e70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 | ||
|
|
||
| common:skip_android --deleted_packages=android,binder | ||
| common:skip_android --deleted_packages=android,binder |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| """Build rule for java_grpc_library.""" | ||
|
AgraVator marked this conversation as resolved.
|
||
|
|
||
| load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") | ||
| load("@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo") | ||
| load("@rules_java//java:defs.bzl", "JavaInfo", "JavaPluginInfo", "java_common") | ||
| load("@rules_proto//proto:defs.bzl", "proto_common") | ||
|
|
||
| _JavaRpcToolchainInfo = provider( | ||
| fields = [ | ||
|
|
@@ -122,6 +122,41 @@ def _java_rpc_library_impl(ctx): | |
|
|
||
| return [java_info] | ||
|
|
||
| def _java_grpc_library_impl(ctx): | ||
|
AgraVator marked this conversation as resolved.
Outdated
|
||
| if len(ctx.attr.srcs) != 1: | ||
| fail("Exactly one src value supported", "srcs") | ||
| if ctx.attr.srcs[0].label.package != ctx.label.package: | ||
| print(("in srcs attribute of {0}: Proto source with label {1} should be in " + | ||
| "same package as consuming rule").format(ctx.label, ctx.attr.srcs[0].label)) | ||
|
|
||
| toolchain = ctx.attr._toolchain[ProtoLangToolchainInfo] | ||
| srcs = ctx.attr.srcs[0][ProtoInfo] | ||
|
|
||
| srcjar = ctx.actions.declare_file("%s-proto-gensrc.jar" % ctx.label.name) | ||
|
|
||
| proto_common.compile( | ||
| actions = ctx.actions, | ||
| proto_info = srcs, | ||
| proto_lang_toolchain_info = toolchain, | ||
| generated_files = [srcjar], | ||
| plugin_output = srcjar.path, | ||
| ) | ||
|
|
||
| deps_java_info = java_common.merge([dep[JavaInfo] for dep in ctx.attr.deps]) | ||
|
|
||
| java_info = java_common.compile( | ||
| ctx, | ||
| java_toolchain = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"].java, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised to see a literal being passed here. Is that not defined somewhere?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bazel does not expose an importable constant for this toolchain type, so using the literal string as was being done at https://github.com/protocolbuffers/protobuf/blob/main/bazel/private/java_proto_support.bzl#L43 |
||
| source_jars = [srcjar], | ||
| output = ctx.outputs.jar, | ||
| output_source_jar = ctx.outputs.srcjar, | ||
| deps = [ | ||
| java_common.make_non_strict(deps_java_info), | ||
| ] + ([toolchain.runtime[JavaInfo]] if toolchain.runtime else []), | ||
| ) | ||
|
|
||
| return [java_info] | ||
|
|
||
| _java_grpc_library = rule( | ||
| attrs = { | ||
| "srcs": attr.label_list( | ||
|
|
@@ -136,6 +171,7 @@ _java_grpc_library = rule( | |
| ), | ||
| "_toolchain": attr.label( | ||
| default = Label("//compiler:java_grpc_library_toolchain"), | ||
| providers = [ProtoLangToolchainInfo], | ||
| ), | ||
| }, | ||
| toolchains = ["@bazel_tools//tools/jdk:toolchain_type"], | ||
|
|
@@ -145,7 +181,7 @@ _java_grpc_library = rule( | |
| "srcjar": "lib%{name}-src.jar", | ||
| }, | ||
| provides = [JavaInfo], | ||
| implementation = _java_rpc_library_impl, | ||
| implementation = _java_grpc_library_impl, | ||
|
AgraVator marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| # A copy of _java_grpc_library, except with a neverlink=1 _toolchain | ||
|
|
@@ -163,6 +199,7 @@ INTERNAL_java_grpc_library_for_xds = rule( | |
| ), | ||
| "_toolchain": attr.label( | ||
| default = Label("//xds:java_grpc_library_toolchain"), | ||
| providers = [ProtoLangToolchainInfo], | ||
| ), | ||
| }, | ||
| toolchains = ["@bazel_tools//tools/jdk:toolchain_type"], | ||
|
|
@@ -172,7 +209,7 @@ INTERNAL_java_grpc_library_for_xds = rule( | |
| "srcjar": "lib%{name}-src.jar", | ||
| }, | ||
| provides = [JavaInfo], | ||
| implementation = _java_rpc_library_impl, | ||
| implementation = _java_grpc_library_impl, | ||
| ) | ||
|
|
||
| _java_lite_grpc_library = rule( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.