Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link conflict with isolate=True, go_proto_library and the grpc compiler #1990

Open
zecke opened this issue Nov 30, 2024 · 4 comments
Open

Link conflict with isolate=True, go_proto_library and the grpc compiler #1990

zecke opened this issue Nov 30, 2024 · 4 comments

Comments

@zecke
Copy link

zecke commented Nov 30, 2024

What version of gazelle are you using?

HEAD as of 30th of November 2024

What version of rules_go are you using?

0.50.1

What version of Bazel are you using?

7.4.1

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

Yes.

What operating system and processor architecture are you using?

Macos 14.7.1 on arm64

What did you do?

We have a go tool that is using gRPC, go_proto_library and load it from a bazel module that is using "isolate = True" to isolate the tools dependencies from the application.

We want to run the tool using:

bazel run @my_module//tool

What did you expect to see?

The tool to run

What did you see instead?

ERROR: /private/var/tmp/_bazel_ich/c0f651c55b5a6db13b7b6f55fed6bc48/external/test_dep~/BUILD.bazel:23:8: GoLink external/test_dep~/test_/test failed: (Exit 1): builder failed: error executing GoLink command (from target @@test_dep~//:test) bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_go~~go_sdk~gazelle_bcr_go_mod_tests__download_0/builder_reset/builder link -sdk ... (remaining 251 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
link: package conflict error: test_test: package imports google.golang.org/grpc/codes
	  was compiled with: @@gazelle~~_go_deps~test_dep~~go_deps~org_golang_google_grpc//codes:codes
	but was linked with: @@gazelle~~go_deps~org_golang_google_grpc//codes:codes
See https://github.com/bazelbuild/rules_go/issues/1877.
Use --verbose_failures to see the command lines of failed build steps.
% bazel query 'somepath(@test_dep//..., @@gazelle~~_go_deps~test_dep~~go_deps~org_golang_google_grpc//codes:codes)'
@test_dep//:test
@@gazelle~~_go_deps~test_dep~~go_deps~org_golang_google_grpc//codes:codes

% bazel query 'somepath(@test_dep//..., @@gazelle~~go_deps~org_golang_google_grpc//codes:codes)'                   
@test_dep//:dep_go_proto
@my_rules_go//proto:go_grpc
@@gazelle~~go_deps~org_golang_google_grpc//codes:go_default_library
@@gazelle~~go_deps~org_golang_google_grpc//codes:codes

(I modified the testcase we already have for the isolate test to have a protobuf with grpc in the isolated test_dep. See the attached commit)
0001-WIP.patch

@zecke
Copy link
Author

zecke commented Nov 30, 2024

Simply adding "google.golang.org/grpc" to the _SHARED_REPOS doesn't do the trick as the name is not available because the isolated module has a direct dependency on that go module and then use_repo will complain that no "org_golang_google_grpc" has been defined. In theory the same should happen when there is a dependency on google.golang.org/protobuf.

The work around of defining our own grpc proto compiler seems to work though.

In theory if we require --experimental_isolated_extension_usages for rules_go we could attempt to isolate the proto tooling from the rest.

It is probably easier to add grpc and dependencies (x/sys, x/net, x/text, google.golang.org/genproto/googleapis/rpc) to the shared repos.

@zecke
Copy link
Author

zecke commented Dec 2, 2024

Observations when attempting to put "google.golang.org/grpc" into _SHARED_REPOS.

  1. use_repo(go_deps, "org_golang_google_grpc") warns the repository is not defined. And that is correct as we skipped creating a go_repository for that name.
  2. Following bazel and dropping this from use_repo leads to the code not being able to resolve the name.

It seems that there is currently no primitive to import/alias "org_golang_google_grpc". In an act of desperation I tried to use inject_repo+use_repo and it doesn't have the desired effect.

@fmeum Any idea in which direction I should be looking at?

@fmeum
Copy link
Member

fmeum commented Dec 5, 2024

I tried to reproduce this with your patch applied to the current state of master, but bazel test //... on the go_mod test repo passes. Is there anything else I need to do to reproduce this failure?

@zecke
Copy link
Author

zecke commented Dec 5, 2024

bazel build @test_dep//... from within tests/bcr/go_mod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants