0.19.1
0.18.1
0.24.1
I was able to reproduce it using Bazel 0.28.1
macOS 10.14.5
Go 1.12.7
The setup we have is a bit unusual, but at a high level looks like the following:
rules_go.deps.bzl file with a load dependencies function.rules_go as one of the dependencies loaded by this function.I was just hoping that this would load successfully.
ERROR: Failed to load Starlark extension '@io_bazel_rules_go_compat//:compat.bzl'.
It usually happens when the repository is not defined prior to being used.
This could either mean you have to add the 'io_bazel_rules_go_compat' repository with a statement like `http_archive` in your WORKSPACE file (note that transitive dependencies are not added automatically), or the repository 'io_bazel_rules_go_compat' was defined too late in your WORKSPACE file.
ERROR: cycles detected during target parsing
It seems io_bazel_rules_go_compat is internal to rules_go and am not sure how to load this via a WORKSPACE file. Any help would be appreciated.
I just ran into this! It was super hard to figure out what went wrong. Turns out you need to change your load statement when you upgrade rules_go from 0.16 to > 0.17. You used to use:
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
but now you should use
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
Very subtle difference, but it should work after that. Best of luck!
Thanks for the reply @achew22.
I double checked (as you're right it is very subtle) and I am using deps.bzl to load go_rules_dependencies and go_register_toolchains.
I think the one (probably important thing) I forgot to mention is that I'm actually "wrapping" these functions with macros. I used this technique when leveraging rules_python so that projects that depend on mine only need to load from one location.
So for example, it would be something like this:
```python
load(
"@io_bazel_rules_go//go:deps.bzl",
_go_rules_dependencies = "go_rules_dependencies",
_go_register_toolchains = "go_register_toolchains",
)
def go_rules_dependencies(args, *kwargs):
_go_rules_dependencies(args, *kwargs)
def go_register_toolchains(args, *kwargs):
_go_register_toolchains(args, *kwargs)
```
I suspect this is my issue and may have to give up on this approach.
@cwaeland The issue you're seeing is very likely what @achew22 is described: def.bzl is loaded from WORKSPACE. It may have been loaded indirectly from another .bzl file. Unfortunately, this split was necessary to support different versions of Bazel with incompatible APIs. It's not really possible to add a reasonable error message for this either: the problem shows up as soon as def.bzl is loaded, before any code is executed.
If you can post a minimal reproducible example, I can help investigate.
@jayconrod
My apologies for not circling back on this sooner. It seems like it was related to the def.bzl split. Ultimately I was able to solve it by using a more fine grained approach to loading the dependencies for my project which let me better control the order that I imported things.
Thanks for your help.
Most helpful comment
I just ran into this! It was super hard to figure out what went wrong. Turns out you need to change your load statement when you upgrade
rules_gofrom0.16to >0.17. You used to use:but now you should use
Very subtle difference, but it should work after that. Best of luck!