diff --git a/language/go/generate.go b/language/go/generate.go index 269227a38..6e5baeaef 100644 --- a/language/go/generate.go +++ b/language/go/generate.go @@ -573,9 +573,9 @@ func (g *generator) maybePublishToolLib(lib *rule.Rule, pkg *goPackage) { } // maybeGenerateExtraLib generates extra equivalent library targets for -// certain protobuf libraries. These "_gen" targets depend on Well Known Types +// certain protobuf libraries. Historically, these "_gen" targets depend on Well Known Types // built with go_proto_library and are used together with go_proto_library. -// The original targets are used when proto rule generation is disabled. +// However, these are no longer needed and are kept as aliases to be backward-compatible func (g *generator) maybeGenerateExtraLib(lib *rule.Rule, pkg *goPackage) *rule.Rule { gc := getGoConfig(g.c) if gc.prefix != "github.com/golang/protobuf" || gc.prefixRel != "" { @@ -585,17 +585,9 @@ func (g *generator) maybeGenerateExtraLib(lib *rule.Rule, pkg *goPackage) *rule. var r *rule.Rule switch pkg.importPath { case "github.com/golang/protobuf/descriptor": - r = rule.NewRule("go_library", "go_default_library_gen") - r.SetAttr("srcs", pkg.library.sources.buildFlat()) - r.SetAttr("importpath", pkg.importPath) + r = rule.NewRule("alias", "go_default_library_gen") + r.SetAttr("actual", ":go_default_library") r.SetAttr("visibility", []string{"//visibility:public"}) - r.SetAttr("deps", []string{ - "//proto:go_default_library", - "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", - "@org_golang_google_protobuf//reflect/protodesc:go_default_library", - "@org_golang_google_protobuf//reflect/protoreflect:go_default_library", - "@org_golang_google_protobuf//runtime/protoimpl:go_default_library", - }) case "github.com/golang/protobuf/jsonpb": r = rule.NewRule("alias", "go_default_library_gen") @@ -603,30 +595,14 @@ func (g *generator) maybeGenerateExtraLib(lib *rule.Rule, pkg *goPackage) *rule. r.SetAttr("visibility", []string{"//visibility:public"}) case "github.com/golang/protobuf/protoc-gen-go/generator": - r = rule.NewRule("go_library", "go_default_library_gen") - r.SetAttr("srcs", pkg.library.sources.buildFlat()) - r.SetAttr("importpath", pkg.importPath) + r = rule.NewRule("alias", "go_default_library_gen") + r.SetAttr("actual", ":go_default_library") r.SetAttr("visibility", []string{"//visibility:public"}) - r.SetAttr("deps", []string{ - "//proto:go_default_library", - "//protoc-gen-go/generator/internal/remap:go_default_library", - "@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto", - "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", - }) case "github.com/golang/protobuf/ptypes": - r = rule.NewRule("go_library", "go_default_library_gen") - r.SetAttr("srcs", pkg.library.sources.buildFlat()) - r.SetAttr("importpath", pkg.importPath) + r = rule.NewRule("alias", "go_default_library_gen") + r.SetAttr("actual", ":go_default_library") r.SetAttr("visibility", []string{"//visibility:public"}) - r.SetAttr("deps", []string{ - "//proto:go_default_library", - "@io_bazel_rules_go//proto/wkt:any_go_proto", - "@io_bazel_rules_go//proto/wkt:duration_go_proto", - "@io_bazel_rules_go//proto/wkt:timestamp_go_proto", - "@org_golang_google_protobuf//reflect/protoreflect:go_default_library", - "@org_golang_google_protobuf//reflect/protoregistry:go_default_library", - }) } return r diff --git a/language/go/resolve_test.go b/language/go/resolve_test.go index 8c9d639f5..c489007a3 100644 --- a/language/go/resolve_test.go +++ b/language/go/resolve_test.go @@ -830,46 +830,18 @@ go_proto_library(name = "wkts_go_proto") go_library( name = "wkts_go_lib", deps = [ - "@com_github_golang_protobuf//protoc-gen-go/descriptor", - "@com_github_golang_protobuf//protoc-gen-go/plugin", - "@com_github_golang_protobuf//ptypes/any", - "@com_github_golang_protobuf//ptypes/duration", - "@com_github_golang_protobuf//ptypes/empty", - "@com_github_golang_protobuf//ptypes/struct", - "@com_github_golang_protobuf//ptypes/timestamp", - "@com_github_golang_protobuf//ptypes/wrappers", - "@org_golang_google_genproto//protobuf/api", - "@org_golang_google_genproto//protobuf/field_mask", - "@org_golang_google_genproto//protobuf/ptype", - "@org_golang_google_genproto//protobuf/source_context", - ], -) -`, - }, { - desc: "proto_special_cross_resolve", - old: buildFile{content: ` -go_library( - name = "go_default_library", - _imports = [ - "github.com/golang/protobuf/proto", - "github.com/golang/protobuf/jsonpb", - "github.com/golang/protobuf/descriptor", - "github.com/golang/protobuf/protoc-gen-go/generator", - "github.com/golang/protobuf/ptypes", - "google.golang.org/grpc", - ], -) -`}, - want: ` -go_library( - name = "go_default_library", - deps = [ - "@com_github_golang_protobuf//descriptor:go_default_library_gen", - "@com_github_golang_protobuf//jsonpb:go_default_library_gen", - "@com_github_golang_protobuf//proto:go_default_library", - "@com_github_golang_protobuf//protoc-gen-go/generator:go_default_library_gen", - "@com_github_golang_protobuf//ptypes:go_default_library_gen", - "@org_golang_google_grpc//:go_default_library", + "//vendor/github.com/golang/protobuf/protoc-gen-go/descriptor", + "//vendor/github.com/golang/protobuf/protoc-gen-go/plugin", + "//vendor/github.com/golang/protobuf/ptypes/any", + "//vendor/github.com/golang/protobuf/ptypes/duration", + "//vendor/github.com/golang/protobuf/ptypes/empty", + "//vendor/github.com/golang/protobuf/ptypes/struct", + "//vendor/github.com/golang/protobuf/ptypes/timestamp", + "//vendor/github.com/golang/protobuf/ptypes/wrappers", + "//vendor/google.golang.org/genproto/protobuf/api", + "//vendor/google.golang.org/genproto/protobuf/field_mask", + "//vendor/google.golang.org/genproto/protobuf/ptype", + "//vendor/google.golang.org/genproto/protobuf/source_context", ], ) `, diff --git a/language/proto/resolve.go b/language/proto/resolve.go index bf27dc150..d96cef615 100644 --- a/language/proto/resolve.go +++ b/language/proto/resolve.go @@ -176,30 +176,5 @@ func (*protoLang) CrossResolve(c *config.Config, ix *resolve.RuleIndex, imp reso return []resolve.FindResult{{Label: l}} } } - if imp.Lang == "go" && pc.Mode.ShouldUseKnownImports() { - // These are commonly used libraries that depend on Well Known Types. - // They depend on the generated versions of these protos to avoid conflicts. - // However, since protoc-gen-go depends on these libraries, we generate - // its rules in disable_global mode (to avoid cyclic dependency), so the - // "go_default_library" versions of these libraries depend on the - // pre-generated versions of the proto libraries. - switch imp.Imp { - case "github.com/golang/protobuf/proto": - return []resolve.FindResult{{Label: label.New("com_github_golang_protobuf", "proto", "go_default_library")}} - case "github.com/golang/protobuf/jsonpb": - return []resolve.FindResult{{Label: label.New("com_github_golang_protobuf", "jsonpb", "go_default_library_gen")}} - case "github.com/golang/protobuf/descriptor": - return []resolve.FindResult{{Label: label.New("com_github_golang_protobuf", "descriptor", "go_default_library_gen")}} - case "github.com/golang/protobuf/ptypes": - return []resolve.FindResult{{Label: label.New("com_github_golang_protobuf", "ptypes", "go_default_library_gen")}} - case "github.com/golang/protobuf/protoc-gen-go/generator": - return []resolve.FindResult{{Label: label.New("com_github_golang_protobuf", "protoc-gen-go/generator", "go_default_library_gen")}} - case "google.golang.org/grpc": - return []resolve.FindResult{{Label: label.New("org_golang_google_grpc", "", "go_default_library")}} - } - if l, ok := knownGoProtoImports[imp.Imp]; ok { - return []resolve.FindResult{{Label: l}} - } - } return nil } diff --git a/language/proto/resolve_test.go b/language/proto/resolve_test.go index b55ce5bae..ec9700e73 100644 --- a/language/proto/resolve_test.go +++ b/language/proto/resolve_test.go @@ -465,13 +465,6 @@ func TestCrossResolve(t *testing.T) { lang: "go", want: nil, }, - { - desc: "go known import", - protoMode: DefaultMode, - imp: resolve.ImportSpec{Lang: "go", Imp: "github.com/golang/protobuf/proto"}, - lang: "go", - want: []resolve.FindResult{{Label: label.New("com_github_golang_protobuf", "proto", "go_default_library")}}, - }, { desc: "go unknown import", protoMode: DefaultMode,