twitchtv / twirp

A simple RPC framework with protobuf service definitions
https://twitchtv.github.io/twirp/docs/intro.html
Apache License 2.0
7.21k stars 326 forks source link

Bazel Support #135

Closed johnpryan closed 5 years ago

johnpryan commented 6 years ago

Hi, thank you for making such a great tool.

I am trying to add Bazel support to Twirp here, but I don't quite know how to do it. It's difficult to see how the protoc-gen-twirp binary is being used by protoc (after installing the package using go get.)

I am currently trying to use protoc-gen-twirp as a go_proto_compiler rule:

load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
    name = "haberdasher_proto",
    srcs = [
        "service.proto",
    ],
    visibility = ["//visibility:public"],
    deps = [],
)

go_proto_library(
    name = "go_default_library",
    importpath = "github.com/johnpryan/go_dart_twirp_example/rpc/haberdasher",
    proto = ":haberdasher_proto",
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_twitchtv_twirp//protoc-gen-twirp:go_default_library",
    ],
    compilers = [
        "twirp_library",
    ],
)

go_proto_compiler(
    name = "twirp_library",
    plugin = "@com_github_twitchtv_twirp//protoc-gen-twirp:protoc-gen-twirp",
    visibility = ["//visibility:public"],
    options = [],
)

But I'm getting an error where the options go_proto_compiler sends to plugins don't match up with what protoc-gen-twirp expects:

2018/11/24 16:17:00 error:could not parse parameters passed to --twirp_out unknown parameter "import_path"

It seems like protoc-gen-twirp does not work the same way as gRPC, since it does not use the same Generator type defined in github.com/golang/protobuf/protoc-gen-go/generator?

gaffo commented 6 years ago

What versions of everything are you using? Specifically protocol, twirp, bazel, go, os

johnpryan commented 5 years ago

I believe I'm using the latest versions of everything. I think this has more to do with how I'm using the go_proto_compiler rule.

I suppose my question is if Twirp is a first-class protobuf plugin... or if anyone has an example of a project that is using twirp + bazel.

Thanks!

jtvjorge commented 5 years ago

I'm not very familiar with Bazel so providing support here is difficult, but it appears that protoc-gen-twirp is receiving the "import" parameter which is not supported (and deprecated in the protoc-gen-go generator.

From the documentation here: https://github.com/bazelbuild/rules_go/blob/master/proto/core.rst the one suggestion I might have for you is to try setting import_path_option to "False". I'm not sure if this will cause other problems with your configuration though.

jtvjorge commented 5 years ago

Closing this issue as it doesn't appear to necessarily be a bug in Twirp, and we haven't heard back. Please feel free to add a comment here if you have further questions.