Skip to content

How can I pass protoc flags to go_proto_library? #2645

@veganafro

Description

@veganafro

What version of rules_go are you using?

0.24.1

What version of gazelle are you using?

0.22.0

What version of Bazel are you using?

Build label: 3.5.0-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Sep 3 00:54:35 2020 (1599094475)
Build timestamp: 1599094475
Build timestamp as int: 1599094475

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

$ echo $MACHTYPE
x86_64-apple-darwin19

Any other potentially useful information about your toolchain?

No

What did you do?

I have the following directory structure where server is a top level directory in a github repository called repo:

server
├── cmd
│   └── dummy
│       └── main.go
├── idl
│   └── dummy
│       └── dummy.proto
├── pkg
│   └── dummy_gen
│       └── dummy.pb.go
├── go.mod
└── go.sum

dummy.pb.go is generated from the following .proto file

syntax = "proto3";

package dummy_gen;

option go_package = "github.com/veganafro/repo/pkg/dummy_gen";

service DummyService {
    rpc GetDummy(DummyRequest) returns (DummyResponse) {}
}

message DummyRequest {
    string msg = 1;
}

message DummyResponse {
    string rsp = 1;
}

using this protoc command that's executed from the root of the repository.

protoc --proto_path=server/idl \
        server/idl/dummy/dummy.proto \
        --go_out=plugins=grpc:server \
        --go_opt=module=github.com/veganafro/repo

I'm attempting to migrate from Make to Bazel and so far I've added the following BUILD file at the same location as my dummy.proto file:

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
    name = "dummy_proto",
    srcs = ["dummy.proto"],
    visibility = ["//visibility:public"],
)

go_proto_library(
    name = "dummy_go_proto",
    compilers = ["@io_bazel_rules_go//proto:go_grpc"],
    importpath = "github.com/veganafro/repo/pkg/dummy_gen",
    proto = ":dummy_proto",
    visibility = ["//visibility:public"],
)

After running bazel build //idl/dummy:dummy_go_proto, I'm seeing that the dummy.pb.go is generated, but it's placed in a subdirectory of bazel-bin.

How can I reproduce the behavior specified by the --go_out=plugins=grpc:server and --go_opt=module=github.com/veganafro/repo flags using Bazel? Specifically, how can I direct Bazel to place the generated dummy.pb.go file in the dummy_gen directory?

What did you expect to see?

I expected to see the generated .pb.go files placed in the directory specified by the go_package option in dummy.proto.

What did you see instead?

I see the .pb.go files placed in a subdirectory of bazel-bin that follows the pattern in importpath.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions