bazelbuild / rules_kotlin

Bazel rules for Kotlin
Apache License 2.0
334 stars 211 forks source link

`//kotlin:dependencies.bzl` does not load all required dependencies #1230

Open shs96c opened 1 month ago

shs96c commented 1 month ago

Apply the following patch to rules_kotlin in order to make the production deps be loaded before the dev ones. This should be a safe operation since the production deps contain everything that rules_kotlin needs at runtime:

diff --git a/WORKSPACE.dev.bazel b/WORKSPACE.dev.bazel
index c282275..d184a6e 100644
--- a/WORKSPACE.dev.bazel
+++ b/WORKSPACE.dev.bazel
@@ -13,14 +13,14 @@
 # limitations under the License.
 workspace(name = "rules_kotlin")

-load("//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
-
-kt_download_local_dev_dependencies()
-
 load("//kotlin:repositories.bzl", "kotlin_repositories")

 kotlin_repositories()

+load("//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
+
+kt_download_local_dev_dependencies()
+
 register_toolchains("@rules_kotlin//kotlin/internal:default_toolchain")

 android_sdk_repository(name = "androidsdk")

Now run bazel sync --noenable_bzlmod and the following error is reported:

ERROR: ErrorInfo{exception=null, cycles=[[] -> [[/Volumes/Dev/src/github.com/bazelbuild/rules_kotlin]/[WORKSPACE], 2, KeyForWorkspace{label=//kotlin:repositories.bzl, isBuildPrelude=false}, KeyForWorkspace{label=//src/main/starlark/core/repositories:initialize.bzl, isBuildPrelude=false}, KeyForWorkspace{label=//src/main/starlark/core/repositories:setup.bzl, isBuildPrelude=false}, KeyForWorkspace{label=@@rules_proto//proto:repositories.bzl, isBuildPrelude=false}, CONTAINING_PACKAGE_LOOKUP:@@rules_proto//proto, PACKAGE_LOOKUP:@@rules_proto//proto, REPOSITORY_DIRECTORY:@@rules_proto]], isCatastrophic=false, isDirectlyTransient=false, isTransitivelyTransient=false}

From this, it's clear that there is a chain of load statements from repositories.bzl to setup.bzl (and from there to @rules_proto).

shs96c commented 1 month ago

The way that I've "solved" this before is manually "unwind" the dependencies of my ruleset's transitive deps in the dependencies.bzl file so that setup.bzl can call the various setup functions that those rulesets provide. It's most unsatisfactory.

restingbull commented 1 month ago

rules_proto. How I love thee.