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

Error when building with bazel #113

Open
ittus opened this issue Oct 4, 2021 · 1 comment
Open

Error when building with bazel #113

ittus opened this issue Oct 4, 2021 · 1 comment

Comments

@ittus
Copy link

ittus commented Oct 4, 2021

I'm using bazel 4.1.0 to build to project.
Current set up:

go.mod file

    ...
    github.com/mwitkow/go-proto-validators v0.3.2 // indirect
    ...

WORKSPACE file

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

load("//:repositories.bzl", "go_repositories")


go_repositories()

in repositories.blz file

   ...
    go_repository(
        name = "com_github_mwitkow_go_proto_validators",
        importpath = "github.com/mwitkow/go-proto-validators",
        sum = "h1:qRlmpTzm2pstMKKzTdvwPCF5QfBNURSlAgN/R+qbKos=",
        version = "v0.3.2",
    )
  ....

in students/api.v1/api.proto file

import "google/api/annotations.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto"; 

after running bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=repositories.bzl%go_repositories -prune=true and bazel run //:gazelle

it generate students/api.v1/BUILD.bazel file

proto_library(
    name = "api_proto",
    srcs = ["api.proto"],
    visibility = ["//visibility:public"],
    deps = [
        "//github.com/mwitkow/go-proto-validators:validators_proto",
        "@go_googleapis//google/api:annotations_proto",
    ],
)

go_proto_library(
    name = "api_go_proto",
    compilers = ["@io_bazel_rules_go//proto:go_grpc"],
    importpath = "students/generated/api",
    proto = ":api_proto",
    visibility = ["//visibility:public"],
    deps = [
        "//github.com/mwitkow/go-proto-validators:validator_proto",
        "@go_googleapis//google/api:annotations_go_proto",
    ],
)

When I run bazel build //..., it produces an error

ERROR: /my-app/students/api.v1/BUILD.bazel:15:17: no such package 'github.com/mwitkow/go-proto-validators': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /my-app/github.com/mwitkow/go-proto-validators and referenced by '/students/api.v1:api_go_proto'
ERROR: Analysis of target '//students/api.v1:api' failed; build aborted: Analysis failed

I would like to make the build work without error. Thank you very much for your help.
I think in BUILD.bazel file, //github.com/mwitkow/go-proto-validators:validators_proto should be @github.com/mwitkow/go-proto-validators:validators_proto, like @go_googleapis//google/api:annotations_proto but it's just a vague idea.

@TheHiddenLayer
Copy link

Late reply here, but if you're using Gazelle, you can workaround this by doing

# gazelle:resolve go github.com/mwitkow/go-proto-validators @com_github_mwitkow_go_proto_validators//:validators_golang

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