What is the Idiomatic way to build proto with dependency on `google/rpc/status.proto`

1,538 views
Skip to first unread message

Saurabh Mohan

unread,
Jan 23, 2018, 2:36:36 PM1/23/18
to bazel-...@googlegroups.com, Saurabh Mohan
Hello Bazel-discuss.
I have a proto definition which has `import "google/rpc/status.proto";`

What is the idiomatic/efficient/correct way for defining a Bazel `go_proto_library()` rule? Currently my **working** `BUILD` file is:

    load("@io_bazel_rules_go//go:def.bzl", "go_library")
    load("@org_pubref_rules_protobuf//go:rules.bzl", "go_proto_library", "GRPC_COMPILE_DEPS")

    go_proto_library(
        name = "protolib",
        protos = glob(["*.proto"]),
        verbose = 1,
        visibility = ["//visibility:public"],
        with_grpc = True,
    #
    # Used to define how the generate pb.go file will generate the
    # go import statement.
    #
    #
    #    importmap = {
    #       "google/rpc/status.proto":"google.golang.org/genproto/googleapis/rpc/status",
    #    },
    
    #
    # The --proto_path option of protoc compiler.
    # the external is-i think-the bazel magic of where the external .proto files are placed.
    #
        imports = [
            "external/com_google_protobuf/src",
            "external/googleapi",
        ],
    #
    # any.proto and google/rpc/status.proto inclusing in the .proto file.
    #
        inputs = [
            "@com_google_protobuf//:well_known_protos",
            "@googleapi//:rpc_status_protos_src",
        ],
    #
    # pb.go file dependencies
    #
        deps = [ "@org_golang_google_genproto//googleapis/rpc/status:go_default_library",
        ],
    )

The relevant pieces of the `WORKSPACE` file are:

     #
    # Needed for gathering the pb.go's dependency on gRPC status.pb.go
    #
    go_repository(
        name = "org_golang_google_genproto",
        importpath = "github.com/google/go-genproto",
    )

    ## Needed for including google/grpc/status.proto in a protobuf definition
    GOOGLEAPIS_SHA="5c6df0cd18c6a429eab739fb711c27f6e1393366" # May 14, 2017
    new_http_archive(
       name = "googleapi",
       strip_prefix = "googleapis-" + GOOGLEAPIS_SHA,
       urls = [
          "https://github.com/googleapis/googleapis/archive/" + GOOGLEAPIS_SHA + ".tar.gz",
       ],
       build_file_content = """
    load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
    
    filegroup(
        name = "rpc_status_protos_src",
        srcs = [
            "google/rpc/status.proto",
        ],
        visibility = ["//visibility:public"],
     )
    """
    )

Is there a better way to do the same? In my search for an answer the relevant answer I found was https://groups.google.com/forum/#!topic/bazel-discuss/vA504VqSiCw
I'd be very interested in finding an easier way to get this done.

Thanks
-Saurabh.
Reply all
Reply to author
Forward
0 new messages