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

Using well_known_protos in C++ #44

Closed
seungryulchoisc opened this issue Nov 30, 2016 · 4 comments
Closed

Using well_known_protos in C++ #44

seungryulchoisc opened this issue Nov 30, 2016 · 4 comments

Comments

@seungryulchoisc
Copy link

Hi, I am building C++ code with protos using bazel. I'd like to use any.proto, one of @com_github_google_protobuf//:well_known_protos, but when I build it, I am getting the following error:
Import "google/protobuf/any.proto" was not found or had errors.

My cc_proto_library entry is:

cc_proto_library(
    name = "b_proto_cc",
    protos = [ "a/b.proto", ],
    imports = [
        "external/com_github_google_protobuf/src/",
    ],
    deps = [
        "@com_github_google_protobuf//:cc_wkt_protos",
    ],
)

Thanks.

@pcj
Copy link
Contributor

pcj commented Nov 30, 2016

Due to sandboxing, just declaring imports = ["external/com_github_google_protobuf/src/"] may not be enough. You can confirm if this is the problem by building with --spawn_strategy=standalone.

In that case, you will also need to tell bazel that the any.proto file needs to be available in the sandbox when the rule is executed. You can do this with the includes attribute, naming the :well_known_protos filegroup that has any.proto in it:

cc_proto_library(
    name = "b_proto_cc",
    protos = [ "a/b.proto", ],
    imports = [
        "external/com_github_google_protobuf/src/",
    ],
    includes = [
        "@com_github_google_protobuf//:well_known_protos",
    ],
    deps = [
        "@com_github_google_protobuf//:cc_wkt_protos",
    ],
)

In a future version of rules_protobuf I think it should be preferable to auto-detect the presence of :cc_wkt_protos (or similar) and just add in the import and include statements implicitly.

If this resolves the problem go ahead and close out the issue. If not, can you post the contents of a/b.proto?

@seungryulchoisc
Copy link
Author

I added includes lines, but it didn't work either.

I am using CC and Go, so I prefer pubref but I can try cc_proto_library in google/protobuf in this case. Thanks anyways.

@pcj
Copy link
Contributor

pcj commented Dec 1, 2016

OK, but I am interested in not leaving it unsolved. Any chance you can post your proto file? If you have a repo that repoduces it even better.

@seungryulchoisc
Copy link
Author

Thanks for your help. One way that I found is adding ../../. If you know a better solution, please let me know. Here are my files.

home/WORKSPACE has

git_repository(
    name = "org_pubref_rules_protobuf",
    remote = "https://github.com/pubref/rules_protobuf.git",
    tag = "v0.7.1",
)   

load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cpp_proto_repositories")
cpp_proto_repositories()

new_local_repository(
    name = "c",
    build_file = "BUILD.c",
    path = __workspace_dir__ + "/c/proto",
)

home/BUILD.c has

cc_proto_library(
    name = "b_proto_cc",
    protos = [ "a/b.proto", ],
    imports = [
        "../../external/com_github_google_protobuf/src/",
    ],  
    deps = [
        "@com_github_google_protobuf//:cc_wkt_protos",
    ],
)

home/c/proto/a/b.proto has

syntax = "proto3";
import "google/protobuf/any.proto";
  
message d {
  repeated google.protobuf.Any e = 1;
}

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