Closed ob closed 3 years ago
Looking around I found this go_genrule()
in the kubernetes repository that is supposed to set up the Go toolchains so you can run them... Unfortunately it doesn't work either, I get:
ERROR: .../operator/api/v1alpha1/BUILD.bazel:31:11: error executing shell command: '/bin/bash -c bazel-out/host/bin/external/io_k8s_sigs_controller_tools/cmd/controller-gen/controller-gen_/controller-gen object paths=./...' failed (Exit 1) bash failed: error executing command /bin/bash -c 'bazel-out/host/bin/external/io_k8s_sigs_controller_tools/cmd/controller-gen/controller-gen_/controller-gen object paths=./...'
Use --sandbox_debug to see verbose messages from the sandbox
Error: go [-e -json -compiled=true -test=false -export=false -deps=true -find=false -tags ignore_autogenerated -- ./...]: exit status 2: go: GOPATH entry is relative; must be absolute path: "bazel-out/darwin-fastbuild/bin/operator/api/v1alpha1/gopath".
For more details see: 'go help gopath'
Sorry, this doesn't really seem like an issue with Gazelle or rules_go. The folks maintaining go_genrule
may be able to help more.
Every go
build command requires a build cache. The location of the cache is set with GOCACHE
, though it can be derived from HOME
if that's set. Neither is set by default for Bazel actions. In module mode, commands also require GOMODCACHE
, to be set; that can be derived from GOPATH
or HOME
.
If you can avoid invoking the go
command in a Bazel action that would be ideal. Having one build system shell out to another is always going to be a bit messy.
Also, consider writing a new Bazel rule instead. That will give you more control over the environment Feel free to open an issue in rules_go if you run into problems with that.
What version of gazelle are you using?
0.22.1
What version of rules_go are you using?
0.24.3
What version of Bazel are you using?
3.5.0
Does this issue reproduce with the latest releases of all the above?
Yes.
What operating system and processor architecture are you using?
Mac OS X 10.15.7 (19H2)
What did you do?
I'm trying to run
controller-gen
from Kubernetescontroller-tools
in agenrule
according to the defaultMakefile
generated bykubebuilder
.The Makefile has:
Where
$(CONTROLLER_GEN)
is the binary produced by compiling the Go code fromcontroller-tools
.I added
controller-tools
as ago_repository
in myWORKSPACE
file:and modified the
BUILD.bazel
file generated by Gazelle in myapi/v1alpha1
directory like so:What did you expect to see?
A successful build.
What did you see instead?
I have also tried adding some environment variables to the
genrule
'scmd
attribute, for instance:cmd = "GOCACHE=$(rootpath @go_sdk//:bin/go) $(location ...
which gives the error:and
cmd = "GOCACHE=/tmp/gocache $(location ...
which gives a lot of compilation errors like: