simuons / rules_clojure

Clojure rules for Bazel
Apache License 2.0
34 stars 8 forks source link

Handle clojure + spec.alpha + core.specs.alpha circular dependencies #30

Closed bshepherdson closed 4 years ago

bshepherdson commented 4 years ago

I just tripped over this circular dependency, and found the workaround from @marplesoft in https://github.com/simuons/rules_clojure/issues/4#issuecomment-601916224_ (Huge thanks for that!)

I wanted to raise this as a separate issue - partly to give more direct visibility to this problem and workaround, in case anyone else trips over it, and partly to see if we can get it fixed.

This feels like it should be part of the toolchain, somehow. I'm not sure how to achieve that, since this is really a problem configuring the maven_install rules.

One thought: make dependency handling built-in, and we can specify Clojure deps more directly as:

load("@rules_clojure//:deps.bzl", "clojure_deps")
clojure_deps(
    deps = [
        "protojure:protojure:0.9.1",
    ],
)

and under the hood, rules_clojure depends on rules_jvm_external and calls maven_install. Just a thought, I'm sure there's other ways to mangle this.

simuons commented 4 years ago

@shepheb thanks for reporting this! WDYT about https://github.com/simuons/rules_clojure/pull/32 With this change you could specify default clojure classpath with your own loaders (rules_jvm_external in your case) Something like this in your own BUILD file

load("@rules_clojure//:toolchain.bzl", "clojure_toolchain")
clojure_toolchain(
    name = "my_clojure_toolchain_impl",
    classpath = ["my-clojure-classpath"],
)

toolchain(
    name = "my_clojure_toolchain",
    toolchain = ":my_clojure_toolchain_impl",
    toolchain_type = "@rules_clojure//rules:toolchain_type",
)

And then in WORKSPACE

register_toolchains("@my_repo//:my_clojure_toolchain")
bshepherdson commented 4 years ago

I guess that works, and it's better than what we have now. What would actually go in place of my-clojure-classpath, though? How does that connect to the :maven target?

This feels intuitively like it could be a parameter to clojure_runtime, so your WORKSPACE looks like

maven_install(
    name = "maven",
    artifacts = [
        "blah:blah:1.0.1", # Just my actual deps, no clojure.core or clojure.core.spec.alpha.
    ],
)

load("@rules_clojure//:runtime.bzl", "clojure_runtime")
clojure_runtime(
    classpath = [":maven"],
)
register_toolchains("@rules_clojure//rules:clojure_toolchain")

I don't know the internals well enough to know how practical that is; I might be way off the mark. I don't know if maven_install rules (and similar) have providers that can be used to get the classpath.