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

dependency with proto file failed to build #1570

Closed
JohnnyQQQQ opened this issue Jun 22, 2018 · 2 comments
Closed

dependency with proto file failed to build #1570

JohnnyQQQQ opened this issue Jun 22, 2018 · 2 comments

Comments

@JohnnyQQQQ
Copy link

I have this go repository as a dependency in my project https://github.com/nats-io/go-nats-streaming

When building my project I got the following error:

ERROR: /home/jean-philippe/.cache/bazel/_bazel_jean-philippe/9311bf9c1e6a8c241086a78e85d9d27b/external/com_github_nats_io_go_nats_streaming/pb/BUILD.bazel:11:1: no such package '@com_github_nats_io_go_nats_streaming//github.com/gogo/protobuf/gogoproto': BUILD file not found on package path and referenced by '@com_github_nats_io_go_nats_streaming//pb:pb_go_proto'
ERROR: Analysis of target '//api/handler:go_default_test' failed; build aborted: no such package '@com_github_nats_io_go_nats_streaming//github.com/gogo/protobuf/gogoproto': BUILD file not found on package path
INFO: Elapsed time: 0.215s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

When I check the content of the BUILD.bazel file in the error message everything looks good to me

load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
    name = "pb_proto",
    srcs = ["protocol.proto"],
    visibility = ["//visibility:public"],
    deps = ["//github.com/gogo/protobuf/gogoproto:gogoproto_proto"],
)

go_proto_library(
    name = "pb_go_proto",
    importpath = "github.com/nats-io/go-nats-streaming/pb",
    proto = ":pb_proto",
    visibility = ["//visibility:public"],
    deps = ["//github.com/gogo/protobuf/gogoproto:go_default_library"],
)

go_library(
    name = "go_default_library",
    embed = [":pb_go_proto"],
    importpath = "github.com/nats-io/go-nats-streaming/pb",
    visibility = ["//visibility:public"],
)

As this file gets generated and I only added the dependency to the project I'm a bit lost what the issue might be here and I would like to sort out if it's an issue in my approach of doing things or perhaps a bug.

What seems a bit wrong to me is this import path in the error message @com_github_nats_io_go_nats_streaming//github.com/gogo/protobuf/gogoproto I'm not sure if this is right.

I imported all my dependencies and created the buildfiles using gazelle.

@jayconrod
Copy link
Contributor

The issue, as you pointed out, is the dependencies are wrong. protocol.proto imports github.com/gogo/protobuf/gogoproto/gogo.proto. Bazel interprets proto imports relative to repository roots (you can think of it passing -I<repo> for each repository). This won't work, since with gogo, you'll have gogoproto/gogo.proto, not github.com/gogo/protobuf/gogoproto/gogo.proto. So unfortunately, there's no correct way to express the dependency right now.

bazelbuild/bazel#3867 is a Bazel feature request to let proto_library set the root directory for imports. Ideally, we would have something like include_prefix and strip_include_prefix in cc_library.

Until then, I'd recommend using the pre-generated .pb.go files from this repository, rather than building proto files at run-time. You can do that in go_repository by setting build_file_proto_mode = "disable".

Note that there are a number of other issues with proto dependencies. #1548 is a plan to fix them.

@JohnnyQQQQ
Copy link
Author

@jayconrod thank you for your answer and detailed clarification in #1548. I build successfully my project by setting the proto mode to disable like you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants