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

gRPC gateway Bazel build rules #66

Closed
achew22 opened this issue Nov 26, 2015 · 4 comments
Closed

gRPC gateway Bazel build rules #66

achew22 opened this issue Nov 26, 2015 · 4 comments

Comments

@achew22
Copy link
Collaborator

achew22 commented Nov 26, 2015

I'm using the normal bazel go rules (http://bazel.io/docs/be/go.html) and I've started looking into creating a build rule for Bazel so the output from grpc-gateway can be depended upon directly. I have a sneaking suspicion that you're using Bazel in some of your projects. Do you have any tricks/tips for getting everything set up in Bazel? Would you be willing to put a sample in the examples folder of how you're doing this?

@yugui
Copy link
Member

yugui commented Nov 27, 2015

@achew22 No, I don't have a good example since I am just trying Bazel in a small project which does not use grpc-gateway.
But I agree that it would be useful if we have a Skylark macro like grpc_gateway_library or grpc_gateway_binary

@ivucica
Copy link
Collaborator

ivucica commented Feb 26, 2016

The following is from a project that's not opensourced (yet), so I can't point to the exact rules. One limiting factor is that I also have custom Go rules (based on Kythe's rules) and haven't gotten around to reworking Bazel's Go rules (see bazelbuild/bazel#828). Because the build rule for //vendor:protoc-gen-gprc-gateway is too dependent on custom Go rules that are too fragile and messy to be shared, I'm not sharing them here.

Instead I'll try to describe my approach enough to get interested people started.

This is my genrule() in the BUILD file for the Bazel package containing file scheduler.proto:

genrule(
    name = "scheduler_pb_gw",
    srcs = [
        "scheduler.proto",
        "//vendor:github.com/gengo/grpc-gateway/third_party/googleapis/google/api/annotations.proto",
        "//vendor:github.com/gengo/grpc-gateway/third_party/googleapis/google/api/http.proto",
        "//vendor:github.com/gogo/protobuf/protobuf/google/protobuf/descriptor.proto"],
    outs = ["scheduler.pb.gw.go"],
    cmd = (
        "$(location @protobuf//:protoc) " +
        " --grpc-gateway_out=logtostderr=true:$$(dirname $@)" +
        " -I$$(dirname $$(dirname $$(dirname $(location //vendor:github.com/gengo/grpc-gateway/third_party/googleapis/google/api/annotations.proto)))):$$(dirname $$(dirname $$(dirname $(location //vendor:github.com/gogo/protobuf/protobuf/google/protobuf/descriptor.proto)))):." +
        " --plugin=protoc-gen-grpc-gateway=$(location //vendor:protoc-gen-grpc-gateway)" +
        " --proto_path=$$(dirname $(location scheduler.proto)):$$(dirname \"$@\")" +
        " $(location scheduler.proto); mv \"$$(dirname \"$@\")\"/scheduler/\"$$(basename \"$@\")\" \"$@\""),
    message = "Processing proto file with grpc-gateway",
    tools = [
        "@protobuf//:protoc",
        "//vendor:protoc-gen-grpc-gateway",
    ]
)

The WORKSPACE defines external repository protobuf. While ordinarily one would specify a git_repository() rule, I am already using vendoring + externals:

local_repository(
    name = "protobuf",
    path = __workspace_dir__ + "/vendor/github.com/google/protobuf",
)

I'm using a genrule() here because it was easier than writing a proper Skylark rule. Even this genrule() is quite hacky.

@yugui
Copy link
Member

yugui commented Feb 29, 2016

@ivucica Thank you for sharing that.

Although I'm not going to write the skylark rule by myself very soon, but it is definitely on my to-do list.
Also I'm happy to accept PRs for the rule. In both cases, your genrule will be quite helpful.

@pcj
Copy link
Contributor

pcj commented Aug 15, 2016

I've posted a preliminary implementation of grpc_gateway_proto_library in rules_protobuf that:

  • builds the grpc-gateway runtime and associated libraries,
  • builds the protoc-gen-grpc-gateway plugin,
  • invokes the plugin
  • compiles the *.pb.gw.go files into a go_library

Hopefully we can accomplish easy grpc-gateway support in bazel. Feedback or contributions welcome.

ithinker1991 pushed a commit to tronprotocol/grpc-gateway that referenced this issue Jun 20, 2018
adasari pushed a commit to adasari/grpc-gateway that referenced this issue Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants