Bazel usage is broken with v0.6.8
Following up on #622 - when using pgv with Bazel and Go>=1.16 (I tried patching v0.6.7 with Go 1.16, which gives a similar error), building it as a dependency in a Bazel workspace fails:
ERROR: /root/.cache/bazel/_bazel_root/433e348f76cbac3cc1ad104fee035fb1/external/com_github_lyft_protoc_gen_star/BUILD.bazel:3:11: GoCompilePkg external/com_github_lyft_protoc_gen_star/protoc-gen-star.a [for host] failed: (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src external/com_github_lyft_protoc_gen_star/artifact.go -src ... (remaining 79 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
compilepkg: missing strict dependencies:
/root/.cache/bazel/_bazel_root/433e348f76cbac3cc1ad104fee035fb1/sandbox/linux-sandbox/113/execroot/fr_enoent/external/com_github_lyft_protoc_gen_star/init_option.go: import of "github.com/spf13/afero"
/root/.cache/bazel/_bazel_root/433e348f76cbac3cc1ad104fee035fb1/sandbox/linux-sandbox/113/execroot/fr_enoent/external/com_github_lyft_protoc_gen_star/persister.go: import of "github.com/spf13/afero"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.
Hi @Kernald, thanks for raising this... to help us troubleshoot this a bit further, can you share how you're attempting to include PGV in your workspace?
Sure - I have in my WORKSPACE:
http_archive(
name = "com_envoyproxy_protoc_gen_validate",
sha256 = "4c692c62e16c168049bca2b2972b0a25222870cf53e61be30b50d761e58728bd",
strip_prefix = "protoc-gen-validate-{}".format("0.6.8"),
urls = ["https://github.com/envoyproxy/protoc-gen-validate/archive/v{}.tar.gz".format("0.6.8")],
)
load("@com_envoyproxy_protoc_gen_validate//bazel:repositories.bzl", "pgv_dependencies")
pgv_dependencies()
load("@com_envoyproxy_protoc_gen_validate//:dependencies.bzl", "go_third_party")
load("@com_envoyproxy_protoc_gen_validate//bazel:dependency_imports.bzl", "pgv_dependency_imports")
pgv_dependency_imports()
I believe this is enough to trigger the issue. I then use @com_envoyproxy_protoc_gen_validate//validate:validate_proto as a dep on proto_library targets, as well as PGV's own pgv_java_proto_library (loaded from @com_envoyproxy_protoc_gen_validate//bazel:pgv_proto_library.bzl).
I don't have an easy access to a computer to do so right now, but if that's not enough, I'll try making a small repro repo next week!
If you’re including the PGV repo directly as a bazel dependency, it doesn’t supply the gazelle rule with the macro it needs. This thing is telling bazel that when it generates build files for dependencies, it should add deps fields based on the import path -> build rule mapping in dependencies.bzl%go_third_party.
In summary, if you want to depend on PGV you need to also tell gazelle what PGV depends on. Thats why your error references the transitive dependency github.com/spf13/afero found in protoc-gen-star
Does that mean I need to maintain a file like e.g. this?
Also:
If you’re including the PGV repo directly as a bazel dependency,
Is there any other, maybe simpler way to use PGV with Bazel? The only parts I'm after are the Java library (which I guess I could pull from Maven) and the protoc plugin, I'm not using anything Go related (although I'm aware the protoc plugin is implemented in Go).
Does that mean I need to maintain a file like e.g. this?
Yes, but my understanding is gazelle will handle all of it for you
Is there any other, maybe simpler way to use PGV with Bazel? The only parts I'm after are the Java library (which I guess I could pull from Maven) and the protoc plugin, I'm not using anything Go related (although I'm aware the protoc plugin is implemented in Go).
Considering you're not doing anything Go related, depending on the executables makes a lot more sense to me otherwise you'll need to play with gazelle as bazel doesnt play nicely with go modules