grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.57k stars 763 forks source link

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

Closed psigen closed 3 months ago

psigen commented 3 years ago

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 commented 3 years ago

An interesting indirectly related conversation about this topic on the python protoc generator. https://github.com/grpc/grpc/issues/14172

psigen commented 3 years ago

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.

sampajano commented 3 months ago

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