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

If an empty .proto is specified to closure_grpc_web_library() it will fail. #1076

Closed
psigen opened this issue May 2, 2021 · 3 comments
Closed

Comments

@psigen
Copy link

psigen commented May 2, 2021

It looks like the closure_grpc_web_library() bazel rule might not quite handle empty proto files correctly.

I have created a mostly empty .proto file like so:

order.proto

syntax = "proto3"
# No other content in this file.

BUILD.bazel

load("@com_github_grpc_grpc_web//bazel:defs.bzl", "closure_grpc_web_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

proto_library(
    name = "proto",
    srcs = ["order.proto"],
)

closure_grpc_web_library(
    name = "web",
    import_style = "es6",
    mode = "grpcwebtext",
    deps = [":proto"],
)

When I run this, I get the following output:

$ bazel build //:web --verbose_failures
INFO: Invocation ID: 0f8abf94-0dd8-4e27-9b06-1d39d9e85295
INFO: Analyzed target //:web (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
INFO: From Generating GRPC Web for //:web:
ERROR: /home/pras/testrepo/BUILD.bazel:40:25: output 'order_grpc_web_pb.js' was not created
ERROR: /home/pras/testrepo/BUILD.bazel:40:25: output 'order.pb.grpc-web.js' was not created
ERROR: /home/pras/testrepo/BUILD.bazel:40:25: Generating GRPC Web for //:web failed: not all outputs were created or valid
Target //:web failed to build
INFO: Elapsed time: 0.418s, Critical Path: 0.26s
INFO: 2 processes: 1 remote cache hit, 1 internal.
FAILED: Build did NOT complete successfully

I think this is because protoc does not create output for these blank files, but the bazel rule still declares them as a target. A simple solution might be to touch the files to create empty placeholders before running protoc.

@psigen
Copy link
Author

psigen commented May 2, 2021

An interesting indirectly related conversation about this topic on the python protoc generator.
grpc/grpc#14172

@psigen
Copy link
Author

psigen commented May 2, 2021

Here is the problem area of the code. Each source file gets actions.declare_file called, but the protoc call
is not guaranteed to generate files for every source file -- it appears the JS gRPC generator will omit generation of JS files for proto inputs that do not contain a service definition.

psigen added a commit to psigen/grpc-web that referenced this issue May 2, 2021
This adds a `ctx.actions.write` to each of the automatically generated source targets
that have been declared.  This prevents an issue if the source targets do not yield a
`.grpc.js` generated file because they do not contain an `rpc` definition (e.g. proto
files that only contain a `message`).

Resolves: grpc#1076
@sampajano
Copy link
Collaborator

Hi :) Closing due to being obsolescence — closure_grpc_web_library was cleaned up #1138. Thanks for the discussion :)

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