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

Can not use both rules_proto_grpc_python and rules_proto_grpc_java in the same project #341

Open
vudaoanhtuan opened this issue Aug 2, 2024 · 6 comments
Labels
blocked-external Waiting on external issue/release bug Something isn't working

Comments

@vudaoanhtuan
Copy link

Issue Description

I'm migrating my project to from WORKSPACE to MODULE.bazel, my project includes some grpc services written by both java and python, and I am using rules_proto_grpc v4.1.1, every work well. After migrating to bzlmod, I use rules_proto_grpc v5.0.0, first I use rules_proto_grpc_python for python services and they work, then I use rules_proto_grpc_java for java services but I got error:

ERROR: Analysis of target '//:java_binary' failed; 
build aborted: in tag at https://bcr.bazel.build/modules/grpc-java/1.62.2/MODULE.bazel:89:15: 
no repository visible as '@com_google_protobuf_javalite' to the repository '@@grpc-java~', 
but referenced by label '@com_google_protobuf_javalite//:protobuf_javalite' in attribute 'target' of tag 'override'. 
Is the module 'grpc-java' missing a bazel_dep or use_repo(..., "com_google_protobuf_javalite")?

I notice that when I disable one of them, the other will work without any error, but when I enable both rules, I got above error message again

Here is my simple setup to reproduce the error: test_bazel.zip

bazel run //:python_binary works but bazel run //:java_binary throw error message

Log Output

ERROR: Analysis of target '//:java_binary' failed; build aborted: in tag at https://bcr.bazel.build/modules/grpc-java/1.62.2/MODULE.bazel:89:15: no repository visible as '@com_google_protobuf_javalite' to the repository '@@grpc-java~', but referenced by label '@com_google_protobuf_javalite//:protobuf_javalite' in attribute 'target' of tag 'override'. Is the module 'grpc-java' missing a bazel_dep or use_repo(..., "com_google_protobuf_javalite")?
INFO: Elapsed time: 2.157s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
FAILED: 
    Fetching module extension maven in @@rules_jvm_external~//:extensions.bzl; starting

rules_proto_grpc Version

5.0.0

Bazel Version

7.2.1

OS

MacOS

Link to Demo Repo

No response

MODULE.bazel or WORKSPACE Content

bazel_dep(name = "rules_python", version = "0.34.0")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")

python.toolchain(python_version = "3.11", is_default = True)

bazel_dep(name = "protobuf", version = "27.2")
bazel_dep(name = "rules_proto_grpc", version = "5.0.0")
bazel_dep(name = "rules_proto_grpc_python", version = "5.0.0")
bazel_dep(name = "rules_proto_grpc_java", version = "5.0.0")

BUILD Content

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_proto_grpc_python//:defs.bzl", "python_grpc_library")
load("@rules_proto_grpc_java//:defs.bzl", "java_grpc_library")

load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_java//java:defs.bzl", "java_binary")

proto_library(
    name = "thing_proto",
    srcs = ["thing.proto"],
    deps = ["@protobuf//:any_proto"],
)

python_grpc_library(
    name = "thing_python_grpc",
    protos = [":thing_proto"],
)

py_binary(
    name = "python_binary",
    main = "main.py",
    srcs = ["main.py"],
    deps = [
        ":thing_python_grpc"
    ]
)

java_grpc_library(
    name = "thing_java_grpc",
    protos = [":thing_proto"],
)

java_binary(
    name = "java_binary",
    main_class = "Main",
    srcs = ["Main.java"],
    deps = [
        ":thing_java_grpc"
    ]
)

Proto Content

syntax = "proto3";

package examples.proto;

import "google/protobuf/any.proto";

message Thing {
  string name = 1;
  google.protobuf.Any payload = 2;
}

Any Other Content

No response

@vudaoanhtuan vudaoanhtuan added the bug Something isn't working label Aug 2, 2024
@aaliddell
Copy link
Member

This is due to a bug in a released version of grpc-java: grpc/grpc-java#11275

This project doesn't directly ever use the grpc-java repo, but it gets pulled transitively through googleapis -> grpc. Whilst there is a new version released that fixes this, you end up pulling the broken version due to googleapis not being updated to the fixed version.

A temporary fix is to use a single_version_override in your MODULE.bazel to force the fixed version, but a real fix needs to be done in one of those other repos sadly...

single_version_override(
    module_name = "grpc-java",
    version = "1.64.0",
)

@aaliddell aaliddell added the blocked-external Waiting on external issue/release label Aug 2, 2024
@vudaoanhtuan
Copy link
Author

I added single_version_override but I got another error:

ERROR: no such package '@@[unknown repo 'maven' requested from @@protobuf~]//': The repository '@@[unknown repo 'maven' requested from @@protobuf~]' could not be resolved: No repository visible as '@maven' from repository '@@protobuf~'
ERROR: /private/var/tmp/_bazel_user/691169fb99f8988cdeecf9ebf10cdc9f/external/protobuf~/java/util/BUILD.bazel:8:13: no such package '@@[unknown repo 'maven' requested from @@protobuf~]//': The repository '@@[unknown repo 'maven' requested from @@protobuf~]' could not be resolved: No repository visible as '@maven' from repository '@@protobuf~' and referenced by '@@protobuf~//java/util:util'
ERROR: Analysis of target '//:java_binary' failed; build aborted: Analysis failed

@aaliddell
Copy link
Member

aaliddell commented Aug 3, 2024

Gah, I see this too. This is a different bug in yet another upstream dependency: protocolbuffers/protobuf#17176

This one has no simple workaround, as there is no fixed protobuf release available (let alone available in BCR)...

@vudaoanhtuan
Copy link
Author

I see that protocolbuffers/protobuf#17176 is resolved by PR protocolbuffers/protobuf#17402, that PR is merged into main branch, so I tried to override protobuf by using git_override rule, but it produces another error, perhaps I should wait for them to release a new version

@nagelal
Copy link

nagelal commented Oct 10, 2024

Is there a known workaround for using both rules_proto_grpc_python and rules_proto_grpc_java in the same project (even if it means only using WORKSPACE instead of MODULE.bazel)?

@nagelal
Copy link

nagelal commented Oct 11, 2024

I found an example usage that solves it:

https://github.com/aalyria/api/blob/222064761c4a056cab59d45ca6006c6b2f403ed8/MODULE.bazel

It uses several archive_override calls to ensure protobuf-28.0-rc3 is used, which includes fancy patches to protobuf, toolchains_proto, and rules_proto_grpc_python. There's also a call to single_version_override on grpc-java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked-external Waiting on external issue/release bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants