0

I'm getting below error when compiling proto files from bazel as my proto file import some google api's protos. Can someone point out the issue?

Error

23:31:22  (18:01:22) ERROR: /tmp/bazel-build/external/model_monitoring_api/BUILD.bazel:3:14: no such target '@go_googleapis//google/api:resource_proto': target 'resource_proto' not declared in package 'google/api' (did you mean 'resource.proto'?) defined by /tmp/bazel-build/external/go_googleapis/google/api/BUILD.bazel and referenced by '@model_monitoring_api//:monitoring_api_proto'
23:31:22  (18:01:22) ERROR: /tmp/bazel-build/external/model_monitoring_api/BUILD.bazel:3:14: no such target '@go_googleapis//google/api:field_behavior_proto': target 'field_behavior_proto' not declared in package 'google/api' (did you mean 'field_behavior.proto'?) defined by /tmp/bazel-build/external/go_googleapis/google/api/BUILD.bazel and referenced by '@model_monitoring_api//:monitoring_api_proto'
23:31:22  (18:01:22) ERROR: /tmp/bazel-build/external/model_monitoring_api/BUILD.bazel:3:14: no such target '@go_googleapis//google/api:client_proto': target 'client_proto' not declared in package 'google/api' (did you mean 'client.proto'?) defined by /tmp/bazel-build/external/go_googleapis/google/api/BUILD.bazel and referenced by '@model_monitoring_api//:monitoring_api_proto'

imports in my proto files

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/field_mask.proto";

Bazel build file

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

proto_library(
    name = "monitoring_api_proto",
    srcs = glob(["v1/*.proto"]),
    visibility = ["//visibility:public"],
    deps = [
        "@com_google_protobuf//:any_proto",
        "@com_google_protobuf//:duration_proto",
        "@com_google_protobuf//:empty_proto",
        "@com_google_protobuf//:field_mask_proto",
        "@com_google_protobuf//:timestamp_proto",
        "@go_googleapis//google/api:annotations_proto",
        "@go_googleapis//google/api:client_proto",
        "@go_googleapis//google/api:field_behavior_proto",
        "@go_googleapis//google/api:resource_proto",
    ],
)

I tried directly import .proto files and that gives me some error related to google api's protos are not visible to my bazel target. Additionally, I can only include @go_googleapis//google/api:annotations_proto in deps and it doesn't give any importing error but my proto files are not compiling as those files need other google api dependencies.

1 Answers1

0

Even though client_proto, field_behavior_proto, and resource_proto have been used in proto definitions, it's only required to include @go_googleapis//google/api:annotations_proto as all other dependencies comes with this annotation_proto and we don't need explicitly define others.

One more additional thing, make sure to give your .proto file path correctly.