bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.39k stars 664 forks source link

rules_go + protobufs + experimental_sibling_repository_layout fails to build #3947

Open ted-xie opened 6 months ago

ted-xie commented 6 months ago

What version of rules_go are you using?

0.48. The issue also reproduces at commit 354a98f4acf2333b7603ede50dd5fbc20ae315b1.

What version of gazelle are you using?

N/A

What version of Bazel are you using?

7.1.2

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

Yes

What operating system and processor architecture are you using?

Debian-based Linux variant, x86_64 architecture.

Any other potentially useful information about your toolchain?

N/A

What did you do?

See repro at https://github.com/ted-xie/rules_go_proto_bug. TL;DR building a go_proto_library rule that's part of an external dependency with --experimental_sibling_repository_layout fails. Failure message:

Could not find file in descriptor database: ../maybe_rules_go_proto_bug~/proto/foo.proto: No such file or directory

What did you expect to see?

I expected the build to succeed.

What did you see instead?

The build fails due to the go proto compiler not being able to find the proto definition.

/cc @ahumesky

fmeum commented 6 months ago

I looked into this and the root cause is that:

This looks like a bug in ProtoInfo, probably in this line https://github.com/bazelbuild/bazel/blob/3a1b336ec8250547651f6c148f79ba1ced2448f2/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl#L122

ahumesky commented 6 months ago

/cc @comius

arrdem commented 4 months ago

Just chiming in to say I got bitten by this today and that I wasn't able to find an obvious workaround on the rules_go side :/. It appears that the mentioning PR #3966 which seems to reorder the WORKSPACE to change which rules_proto wins and force an 6.0.0 upgrade isn't actually a fix. After applying the same upgrade I'm seeing the same behavior on Bazel 7.0.

I can't quite follow how this is supposed to be behaving but if folks can provide pointers I'd be happy to take a crack at fixing this since it has other knock-on consequences for us.

Specifically we encountered this in the buildozer build; sample sandbox error below.

``` ERROR: /private/var/tmp/_bazel_rmckenzie/91c8ca1d1d93ea92333230a8f066dbe4/external/com_github_bazelbuild_buildtools/api_proto/BUILD.bazel:18:17: Generating into bazel-out/com_github_bazelbuild_buildtools/darwin_arm64-fastbuild/bin/api_proto/api_proto_go_proto_/github.com/bazelbuild/buildtools/api_proto failed: (Exit 1): sandbox-exec failed: error executing GoProtocGen command (cd /private/var/tmp/_bazel_rmckenzie/91c8ca1d1d93ea92333230a8f066dbe4/sandbox/darwin-sandbox/279/execroot/abnormalsecurity && \ exec env - \ CGO_ENABLED=1 \ GOARCH=arm64 \ GOEXPERIMENT=nocoverageredesign \ GOOS=darwin \ GOPATH='' \ GOROOT=bazel-out/io_bazel_rules_go/darwin_arm64-fastbuild/bin/stdlib_ \ GOROOT_FINAL=GOROOT \ GOTOOLCHAIN=local \ PATH=../local_config_cc:/usr/bin:/bin \ TMPDIR=/var/folders/p9/q08xsds941xcsfj7rf311p8c0000gn/T/ \ ZERO_AR_DATE=1 \ /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_rmckenzie/91c8ca1d1d93ea92333230a8f066dbe4/sandbox/darwin-sandbox/279/sandbox.sb /var/tmp/_bazel_rmckenzie/install/c15aaa505bff3c1d2abdefcf159a3893/process-wrapper '--timeout=0' '--kill_delay=15' '--stats=/private/var/tmp/_bazel_rmckenzie/91c8ca1d1d93ea92333230a8f066dbe4/sandbox/darwin-sandbox/279/stats.out' bazel-out/io_bazel_rules_go/darwin_arm64-opt-exec-ST-a828a81199fe/bin/go/tools/builders/go-protoc/go-protoc-bin -protoc bazel-out/io_bazel_rules_go/darwin_arm64-opt-exec-ST-a828a81199fe/bin/proto/protoc/protoc -importpath github.com/bazelbuild/buildtools/api_proto -out_path bazel-out/com_github_bazelbuild_buildtools/darwin_arm64-fastbuild/bin/api_proto/api_proto_go_proto_/ -plugin bazel-out/io_bazel_rules_go/darwin_arm64-opt-exec-ST-a828a81199fe/bin/proto/go_proto_reset_plugin_/protoc-gen-go -descriptor_set bazel-out/com_github_bazelbuild_buildtools/darwin_arm64-fastbuild/bin/api_proto/api_proto_proto-descriptor-set.proto.bin -expected bazel-out/com_github_bazelbuild_buildtools/darwin_arm64-fastbuild/bin/api_proto/api_proto_go_proto_/github.com/bazelbuild/buildtools/api_proto/api.pb.go -import '../com_github_bazelbuild_buildtools/api_proto/api.proto=github.com/bazelbuild/buildtools/api_proto' ../com_github_bazelbuild_buildtools/api_proto/api.proto) ```