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

Bazel 6 compat issues #1158

Open
brocollie08 opened this issue Apr 9, 2024 · 4 comments
Open

Bazel 6 compat issues #1158

brocollie08 opened this issue Apr 9, 2024 · 4 comments

Comments

@brocollie08
Copy link

I'm in the middle of migrating a repo full of rules and macros from bazel 5 to 6, and I noticed that there are some problems pulling in rules_kotlin via bzlmod

If I just have the following:

bazel_dep(name = "rules_kotlin", version = "1.9.1", repo_name = "io_bazel_rules_kotlin")

I notice that the first error I get is this

ERROR: Failed to load Starlark extension '@rules_java//java:defs.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.
The following chain of repository dependencies lead to the missing definition.
 - @rules_java

I tried to include that as well manually

bazel_dep(name = "rules_java", version = "6.5.2")

I get another similar error

ERROR: Failed to load Starlark extension '@com_github_jetbrains_kotlin//:capabilities.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.
The following chain of repository dependencies lead to the missing definition.
 - @com_github_jetbrains_kotlin

I believe both of these are from the rules_kotlin repo.

The behaviour can be observed here by running bazel build //kotlin/...


However, I've found that the WORKSPACE.bzlmod works just fine, but I noticed that bazel 6 seems to have issues with non-module dependencies being used transitively.
e.g. repo A uses the macros defined in B, but B uses rules_kotlin through WORKSPACE.bzlmod instead of MODULE.bazel, then A will error with @rules_kotlin not being defined in the context of B upon trying to execute the macro.

I've verified that this doesn't seem to be a problem with module deps (tested with rules_jvm_external), which suggests incremental adoption isn't really an option for kotlin rules, forcing me pull it through bzlmod and leading me to the issue in description.

@Bencodes
Copy link
Collaborator

Bencodes commented Apr 9, 2024

I could be wrong but I think this is a WORKSPACE error and not a Bzlmod error. At least I'm yet to see this one from Bzlmod. Do you have an example workspace and module file that can be used to repro this?

@brocollie08
Copy link
Author

Yea! You should be able to see it here if you remove the declaration chunk from WORKSPACE.bzlmod and put the equivalent bazel_dep in MODULE.bazel

I was just about to try to fork the rules kotlin repo and use git override to see if I can do something about this locally, but please let me know if I've missed something in my set up

@brocollie08
Copy link
Author

This seems to be only a problem with my existing WORKSPACE.bzlmod, which I think is necessary since it loads in things that are non-bzlmod dependencies as a means to support incremental upgrades alongside bzlmod..

@brocollie08
Copy link
Author

okay 1 more update on this, I don't actually think this is a general problem for Kotlin rules and WORKSPACE.bzlmod, I was able to load some other stuff through WORKSPACE.bzlmod okay.

This problem came up with the content in that WORKSPACE.bzlmod file at that commit, which, all it was doing was trying to download things from Maven.

I've moved those to maven.install in the MODULE.bazel and deleted the lines in WORKSPACE.bzlmod, so I've worked around it for now.

So the current conclusion is that Kotlin rules error out with its deps when I try to download other maven deps in WORKSPACE.bzlmod? Weird edge case behaviour

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