bazel-contrib / bazel-contrib/rules_go

go_proto_library rule with protoc plugin in compilers generates action conflict error.

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

Description

### What version of rules_go are you using?

`v0.27.0`

### What version of gazelle are you using?

`v0.23.0`

### What version of Bazel are you using?

```
bazelisk version
Bazelisk version: v1.7.5
Build label: 4.0.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Jan 21 07:33:24 2021 (1611214404)
Build timestamp: 1611214404
Build timestamp as int: 1611214404
```

### Does this issue reproduce with the latest releases of all the above?

Yes

### What operating system and processor architecture are you using?

`Ubuntu 20.04.2 LTS (Focal Fossa)`, `x86_64`

### Any other potentially useful information about your toolchain?

### What did you do?

I am currently trying to use with this [protoc-gen-gotag](https://github.com/srikrsna/protoc-gen-gotag) `protoc` plugin using compilers in `go_proto_library` rule.

Proto and BUILD files look like this :

```
syntax = "proto3";

option go_package = "github.com/xxx/yyy/src/services/my_service";

package my_service;

import "github.com/srikrsna/protoc-gen-gotag/tagger/tagger.proto";

message my_message {
int64 ID = 1 [(tagger.tags) = "db:\"id\"" ];
}
```

```
proto_library(
name = "my_service_proto",
srcs = ["my_service.proto"],
visibility = ["//visibility:public"],
import_prefix = "github.com/xxx/yyy/src/services/my-service",
deps = ["@com_srikrsna_protoc_gen_gotag//tagger:tagger_proto"],
)

go_proto_library(
name = "my_service_go_proto",
compilers = [
"@io_bazel_rules_go//proto:go_grpc",
":protoc_gen_gotag", # keep
], importpath = "github.com/xxx/yyy/src/services/my_service",
proto = ":manager_proto",
visibility = ["//visibility:public"],
deps = [
"@com_srikrsna_protoc_gen_gotag//tagger:tagger_go_proto"],
)

go_proto_compiler(
name = "protoc_gen_gotag",
plugin = "@com_srikrsna_protoc_gen_gotag//:protoc-gen-gotag",
valid_archive = False,
visibility = ["//visibility:public"],
deps = PROTO_RUNTIME_DEPS + WELL_KNOWN_TYPE_RULES.values() + WELL_KNOWN_TYPES_APIV2,
)
```

### What did you expect to see?

Build works with no error and `.pb.go` file is generated with correct annotations.

### What did you see instead?

Build is returning conflicting action error :

```
ERROR: file 'src/services/my_service/manager_go_proto_/github.com/xxx/yyy/src/services/my_service/my_service.pb.go' is generated by these conflicting actions:
Label: //src/services/my_service:my_service_go_proto
RuleClass: go_proto_library rule
Configuration: 86d23d2b5aedbeecfc6e6954ea9486ec39e9e40bcbc4b17cec46a06eed198d11
Mnemonic: GoProtocGen
Action key: d32f0d8df3a01a8485635fa88f513c4736142202d008892b4ee852a42b34a0ca, eef33c3e38791364fb33937110c1a07a77cef7fa93b58502e674936d39bb586e
Progress message: Generating into bazel-out/k8-fastbuild/bin/src/services/my_service/my_service_go_proto_/github.com/xxx/yyy/src/services/my_service
PrimaryInput: File:[[]bazel-out/k8-fastbuild/bin]external/com_google_protobuf/descriptor_proto-descriptor-set.proto.bin
PrimaryOutput: File:[[]bazel-out/k8-fastbuild/bin]src/services/my_service/my_service_go_proto_/github.com/xxx/yyy/src/services/my_service/my_service.pb.go
Owner information: ConfiguredTargetKey{label=//src/services/my_service:my_service_go_proto, config=BuildConfigurationValue.Key[86d23d2b5aedbeecfc6e6954ea9486ec39e9e40bcbc4b17cec46a06eed198d11]}
MandatoryInputs: Attempted action contains artifacts not in previous action (first 5):
src/services/my_service/protoc_gen_gotag_reset_plugin_/protoc-gen-gotag
Previous action contains artifacts not in attempted action (first 5):
external/io_bazel_rules_go/proto/go_grpc_reset_plugin_/protoc-gen-go
Outputs: are equal
```

I am feeling that the error happen because the `gotag` plugin is trying to modify the same file outputed by `protoc-gen-go` ?
But that's actually what the plugin is supposed to do.

As far as I understand, `go_proto_library` is [calling the registered compilers one after the other](https://github.com/bazelbuild/rules_go/blob/707c634bf8f7ca5b57c2a923bec16fa62ced1fc7/proto/def.bzl#L104), resulting in one `protoc` call for each provider.
I would have expected the rule to do only one `protoc` execution, with all registered plugins (compilers) specified.

Am I missing something ? Thanks :pray:

Contributor guide

Open the contributing guide

Research direction

Reproduce the conflict with the supplied proto and BUILD definitions, then inspect proto/def.bzl at the linked compiler-handling code and the reported conflicting actions. Determine how multiple compilers affect the generated .pb.go output; done means the example builds successfully and generates the expected annotated file without an action conflict.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.