if you import a different version of github.com/gogo/protobuf than what rules_go natively includes, you can no longer compile gogo protobufs.
reproduction:
hello.proto:
syntax = "proto3";
import "google/protobuf/any.proto";
message Foo {
};
WORKSPACE:
http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.10.1/rules_go-0.10.1.tar.gz",
sha256 = "4b14d8dd31c6dbaf3ff871adcd03f28c3274e42abc855cb8fb4d01233c0154dc",
)
load("@io_bazel_rules_go//go:def.bzl", "go_repository", "go_rules_dependencies", "go_register_toolchains")
go_repository(
name="com_github_gogo_protobuf",
commit="1adfc126b41513cc696b209667c8656ea7aac67c",
importpath="github.com/gogo/protobuf"
)
go_rules_dependencies()
go_register_toolchains()
(note this is even the same version as the one that rules_go natively includes, but also reproducible with other versions)
BUILD.bazel:
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
proto_library(
name = "hello_proto",
srcs = ["hello.proto"],
visibility = ["//visibility:public"],
deps = ["@com_google_protobuf//:any_proto"],
)
go_proto_library(
name = "hello_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogo_proto"],
importpath = "example.com/repo",
proto = ":hello_proto",
visibility = ["//visibility:public"],
)
$ bazel build //...
INFO: Analysed 2 targets (56 packages loaded).
INFO: Found 2 targets...
ERROR: /private/var/tmp/_bazel_kevinrosendahl/938430ea243630148906fc2cce0e7852/external/com_github_gogo_protobuf/gogoproto/BUILD.bazel:19:1: GoCompile external/com_github_gogo_protobuf/gogoproto/darwin_amd64_stripped/go_default_library~/github.com/gogo/protobuf/gogoproto.a failed (Exit 1)
external/com_github_gogo_protobuf/gogoproto/helper.go:35:37: cannot use E_Embed (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetBoolExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:39:37: cannot use E_Nullable (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetBoolExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:43:37: cannot use E_Stdtime (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetBoolExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:47:37: cannot use E_Stdduration (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetBoolExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:94:36: cannot use E_Enumdecl (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetBoolExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:94:85: cannot use E_EnumdeclAll (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetBoolExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:98:39: cannot use E_Typedecl (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetBoolExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:98:88: cannot use E_TypedeclAll (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetBoolExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:106:37: cannot use E_Customtype (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:119:37: cannot use E_Casttype (type *"github.com/golang/protobuf/proto".ExtensionDesc) as type *"github.com/gogo/protobuf/proto".ExtensionDesc in argument to "github.com/gogo/protobuf/proto".GetExtension
external/com_github_gogo_protobuf/gogoproto/helper.go:119:37: too many errors
2018/03/24 18:17:17 error running compiler: exit status 1
INFO: Elapsed time: 32.263s, Critical Path: 2.50s
FAILED: Build did NOT complete successfully
com_github_gogo_protobuf needs some special handling. They have Makefiles that run protoc with some additional flags when generating their .pb.go files. Gazelle (and go_repository) won't be able to figure that out automatically.
I'd recommend using the .pb.go files they have checked in rather than regenerating them with Bazel. Just add build_file_proto_mode = "disable" to the go_repository rule. That will skip generating go_proto_library rules and will treat .pb.go files like normal Go source files.
go_repository(
name="com_github_gogo_protobuf",
commit="1adfc126b41513cc696b209667c8656ea7aac67c",
importpath="github.com/gogo/protobuf",
build_file_proto_mode = "disable",
)
makes sense, thanks. you can feel free to close this