The command that the official grpc-web dependency specifies to generate the protobuf JS code is:
protoc -I . -I=$GOPATH/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis --js_out=import_style=closure,binary:. --grpc-web_out=import_style=closure,mode=grpcweb:. path/to/service.proto
See https://github.com/grpc/grpc-web?tab=readme-ov-file#client-configuration-options.
However, I am trying to accomplish this by encapsulating the logic in a Bazel rule. It seems I should be using ctx.actions.run() to run the protoc executable. However, I'm not familiar with Bazel and am not sure how to get a working bazel rule that successfully generates protobuf code to my bazel-bin/. Any guidance will be appreciated.
# ctx.actions.run(
# inputs = ctx.files.srcs,
# outputs = [ctx.outputs.out],
# executable = "//tools/protobuf:protoc",
# arguments = [
# "-I.",
# "-I=$GOPATH/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis",
# "--js_out=import_style=closure,binary:" + protoc_output.path,
# "--grpc-web_out=import_style=closure,mode=grpcweb:" + protoc_output.path,
# ] + [src.path for src in ctx.files.srcs],
# progress_message = "Generating protobuf JS Closure code for gRPC-Web",
# )
#
## ctx.actions.write(
## output = protoc_output,
## content = "Generated protoc output for " + ctx.label.name,
## )
I would expect this to generate the files and place them in bazel-bin/ for me to reference later. However, I'm not seeing any files generated