bazel-contrib / bazel-contrib/rules_go

go_proto_library deps leading to undefined message errors.

Open
#1,702 1 comment 0 reactions 0 assignees View on GitHub
proto question
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

So, I have been trying to use the deps field on go_proto_library and not succeeding.

Here is a simple set of examples:
```
simple.proto:
syntax = "proto3";
package src.proto;
option go_package = "src/proto";
message Simple {
string simple = 1;
}
```

imports_simple.proto:
```
syntax = "proto3";
package src.proto;
option go_package = "src/proto";
import "src/proto/simple.proto";
message ImportSimple {
Simple simple = 1;
}
```

BUILD:
```
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
proto_library(
name = "simple_proto",
srcs = ["simple.proto"],
)
proto_library(
name = "import_simple_proto",
srcs = ["import_simple.proto"],
deps = [":simple_proto"],
)
go_proto_library(
name = "simple_go_proto",
importpath = "src/proto",
proto = ":simple_proto",
)
go_proto_library(
name = "import_simple_go_proto",
importpath = "src/proto",
proto = ":import_simple_proto",
deps = [
":simple_go_proto",
]
)
```

The following commands work fine:
`bazel build :simple_proto`
`bazel build :import_simple_proto`
`bazel build :simple_go_proto`

However, when I run the following:
`bazel build :import_simple_go_proto`
I get an error message saying that the "Simple" message is undefined:
```
src/proto/BUILD:35:1: GoCompile src/proto/darwin_amd64_stripped/import_simple_go_proto%/src/proto.a failed (Exit 1)
/private/var/tmp/_bazel_pj.mcnerney/bf92313fe2a9872de78dbd711b456207/sandbox/darwin-sandbox/1/execroot/__main__/bazel-out/darwin-fastbuild/bin/src/proto/darwin_amd64_stripped/import_simple_go_proto%/src/proto/import_simple.pb.go:22:24: undefined: Simple
GoCompile: error running subcommand: exit status 2
```

Now, I could use embed instead to:
```go_proto_library(
name = "import_simple_go_proto",
importpath = "src/proto",
proto = ":import_simple_proto",
embed = [
":simple_go_proto",
]
)
```

and that compiles fine. However, that leads to problems later on (i.e. classic diamond inheritance pattern) when I try to scale that.

I'm mostly convinced that I'm likely just doing something wrong, but, having used other Bazel rules with deps in the past, the behavior here is super unclear to me.

Is there a go specific thing that needs to be done for deps?

Thank you in advance.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the shown simple.proto, imports_simple.proto, and BUILD targets, then compare bazel build :import_simple_go_proto using deps with the working embed form. Done means the deps form compiles without the undefined Simple error while preserving dependency behavior that avoids the reported diamond inheritance problem.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.