diff --git a/proto/BUILD.bazel b/proto/BUILD.bazel index f149b23863..38b699e049 100644 --- a/proto/BUILD.bazel +++ b/proto/BUILD.bazel @@ -3,6 +3,10 @@ load( "//proto:compiler.bzl", "go_proto_compiler", ) +load( + "//go/private/rules:transition.bzl", + "go_non_go_exec_reset_target", +) load( "//proto/wkt:well_known_types.bzl", "GOGO_WELL_KNOWN_TYPE_REMAPS", @@ -112,6 +116,12 @@ go_proto_compiler( ] + WELL_KNOWN_TYPE_RULES.values(), ) +go_non_go_exec_reset_target( + name = "protoc_reset_target_", + dep = "@com_google_protobuf//:protoc", + visibility = ["//visibility:public"], +) + filegroup( name = "all_rules", testonly = True, diff --git a/proto/compiler.bzl b/proto/compiler.bzl index a84e54dbcf..59880775cf 100644 --- a/proto/compiler.bzl +++ b/proto/compiler.bzl @@ -23,7 +23,7 @@ load( ) load( "//go/private/rules:transition.bzl", - "go_reset_target", + "go_exec_reset_target", ) GoProtoCompiler = provider( @@ -200,7 +200,7 @@ _go_proto_compiler = rule( "_protoc": attr.label( executable = True, cfg = "exec", - default = "@com_google_protobuf//:protoc", + default = "//proto:protoc_reset_target_", ), "_go_context_data": attr.label( default = "//:go_context_data", @@ -212,7 +212,7 @@ _go_proto_compiler = rule( def go_proto_compiler(name, **kwargs): plugin = kwargs.pop("plugin", "@com_github_golang_protobuf//protoc-gen-go") reset_plugin_name = name + "_reset_plugin_" - go_reset_target( + go_exec_reset_target( name = reset_plugin_name, dep = plugin, visibility = ["//visibility:private"], diff --git a/proto/def.bzl b/proto/def.bzl index a20459d6a5..8d6137b039 100644 --- a/proto/def.bzl +++ b/proto/def.bzl @@ -18,6 +18,10 @@ load( "GoSource", "go_context", ) +load( + "@bazel_skylib//lib:types.bzl", + "types", +) load( "//proto:compiler.bzl", "GoProtoCompiler", @@ -27,6 +31,10 @@ load( "//go/private:providers.bzl", "INFERRED_PATH", ) +load( + "//go/private/rules:transition.bzl", + "go_non_go_exec_reset_tool_transition", +) load( "@rules_proto//proto:defs.bzl", "ProtoInfo", @@ -37,8 +45,9 @@ GoProtoImports = provider() def get_imports(attr): proto_deps = [] - if hasattr(attr, "proto") and attr.proto and ProtoInfo in attr.proto: - proto_deps = [attr.proto] + # ctx.attr.proto is a one-element array since there is a Starlark transition attached to it. + if hasattr(attr, "proto") and attr.proto and types.is_list(attr.proto) and ProtoInfo in attr.proto[0]: + proto_deps = [attr.proto[0]] elif hasattr(attr, "protos"): proto_deps = [d for d in attr.protos if ProtoInfo in d] else: @@ -92,7 +101,9 @@ def _go_proto_library_impl(ctx): #TODO: print("DEPRECATED: proto attribute on {}, use protos instead".format(ctx.label)) if ctx.attr.protos: fail("Either proto or protos (non-empty) argument must be specified, but not both") - proto_deps = [ctx.attr.proto] + + # ctx.attr.proto is a one-element array since there is a Starlark transition attached to it. + proto_deps = [ctx.attr.proto[0]] else: if not ctx.attr.protos: fail("Either proto or protos (non-empty) argument must be specified") @@ -137,8 +148,12 @@ def _go_proto_library_impl(ctx): go_proto_library = rule( implementation = _go_proto_library_impl, attrs = { - "proto": attr.label(providers = [ProtoInfo]), + "proto": attr.label( + cfg = go_non_go_exec_reset_tool_transition, + providers = [ProtoInfo], + ), "protos": attr.label_list( + cfg = go_non_go_exec_reset_tool_transition, providers = [ProtoInfo], default = [], ), @@ -159,6 +174,9 @@ go_proto_library = rule( "_go_context_data": attr.label( default = "//:go_context_data", ), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, toolchains = ["@io_bazel_rules_go//go:toolchain"], )