protoc-gen-validate icon indicating copy to clipboard operation
protoc-gen-validate copied to clipboard

Unable to install latest version of protoc-gen-validate using bazel

Open khanhtc1202 opened this issue 3 years ago • 6 comments

Bazel WORKSPACE configuration

git_repository(
    name = "com_github_envoyproxy_protoc_gen_validate",
    commit = "8c0f6372216272771488d63323787e86377aefe0",
    remote = "https://github.com/envoyproxy/protoc-gen-validate.git",
    shallow_since = "1560436592 +0000",
)

Returned error

(16:03:44) ERROR: /private/var/tmp/_bazel_xxx/8853970899baaeb63ca98792c8fae39a/external/com_github_envoyproxy_protoc_gen_validate/BUILD:15:11: no such package '@com_github_lyft_protoc_gen_star//lang/go': The repository '@com_github_lyft_protoc_gen_star' could not be resolved and referenced by '@com_github_envoyproxy_protoc_gen_validate//:go_default_library'

Looks like bazel can not find the way to fetch @com_github_lyft_protoc_gen_star as protoc-gen-validate dependency or maybe it's required to be installed in another way with a different bazel configuration but I can not find any guideline for that. Could someone please help?

khanhtc1202 avatar Nov 11 '21 07:11 khanhtc1202

I am having similar issue.

[build] ERROR: /private/var/tmp/_bazel_malmuzaini/c02ae12471039abbeac07c33d4ad7166/external/com_github_envoyproxy_protoc_gen_validate/BUILD:16:11: no such package '@com_github_envoyproxy_protoc_gen_validate//vendor/github.com/lyft/protoc-gen-star': BUILD file not found in directory 'vendor/github.com/lyft/protoc-gen-star' of external repository @com_github_envoyproxy_protoc_gen_validate. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_github_envoyproxy_protoc_gen_validate//:go_default_library'

Here is the workspace

oad("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "com_github_bazelbuild_buildtools",
    sha256 = "c28eef4d30ba1a195c6837acf6c75a4034981f5b4002dda3c5aa6e48ce023cf1",
    strip_prefix = "buildtools-4.0.1",
    urls = ["https://github.com/bazelbuild/buildtools/archive/4.0.1.tar.gz"],
)

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
    ],
)

http_archive(
    name = "bazel_gazelle",
    sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
        "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
    ],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

go_rules_dependencies()

http_archive(
    name = "com_google_protobuf",
    sha256 = "528927e398f4e290001886894dac17c5c6a2e5548f3fb68004cfb01af901b53a",
    strip_prefix = "protobuf-3.17.3",
    urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.17.3.zip"],
)

http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "1f4e59843b61981a96835dc4ac377ad4da9f8c334ebe5e0bb3f58f80c09735f4",
    strip_prefix = "rules_docker-0.19.0",
    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.19.0/rules_docker-v0.19.0.tar.gz"],
)

go_register_toolchains(
    go_version = "1.17.2",
    nogo = "@//:my_nogo",
)

mashail avatar Nov 15 '21 09:11 mashail

Hit the same issue, and ended up adopting the bazel rules from rules-proto-grpc. It works pretty well.

mindbergh avatar Dec 14 '21 19:12 mindbergh

@mindbergh could you clarify what you mean?

derekperkins avatar Dec 14 '21 19:12 derekperkins

We tried to use protoc-gen-validate in our proto repo which uses bazel as the building tool. However, directly referencing this repo and using the rule located in https://github.com/envoyproxy/protoc-gen-validate/blob/main/bazel/pgv_proto_library.bzl gave us the same error as above. So we ended up using the rules provided by rules-proto-grpc and it builds the validator go files without error.

mindbergh avatar Dec 22 '21 04:12 mindbergh

I faced the same error.

My workaround is loading dependencies of protoc-gen-validate explicitly like below:

git_repository(
    name = "protoc_gen_validate",
    commit = "8c0f6372216272771488d63323787e86377aefe0",
    remote = "https://github.com/envoyproxy/protoc-gen-validate",
)

load("@protoc_gen_validate//:dependencies.bzl", protoc_gen_validate_deps = "go_third_party")
protoc_gen_validate_deps()

It could be the wrong way, but generates expected pb.validate.go for me.

110y avatar Dec 29 '21 03:12 110y

@110y I tested this, works on Linux (ubuntu), but not on macOS 😅

dio avatar Jan 26 '22 11:01 dio

I have the same issue now. Gazelle generates the dependency as following in my project (deps.bzl):

    go_repository(
        name = "com_github_lyft_protoc_gen_star_v2",
        importpath = "github.com/lyft/protoc-gen-star/v2",
        sum = "h1:keaAo8hRuAT0O3DfJ/wM3rufbAjGeJ1lAtWZHDjKGB0=",
        version = "v2.0.1",
    )

But in protoc-gen-validate the name of the go_repository is com_github_lyft_protoc_gen_star without "v2". So this triggers the error when trying to build:

ERROR: /private/var/tmp/_bazel_alexandre.miziara/f7366cb40f218cae24698ffbd08f4bf3/external/com_envoyproxy_protoc_gen_validate/BUILD.bazel:18:11: no such package '@com_github_lyft_protoc_gen_star//': The repository '@com_github_lyft_protoc_gen_star' could not be resolved: Repository '@com_github_lyft_protoc_gen_star' is not defined and referenced by '@com_envoyproxy_protoc_gen_validate//:protoc-gen-validate_lib'

AFMiziara avatar Apr 11 '23 00:04 AFMiziara