Skip to content

Conversation

jamesreprise
Copy link
Member

@jamesreprise jamesreprise commented May 21, 2025

Added support for bzlmod. This allows bringing in rules_clojure via a MODULE.bazel file rather than through WORKSPACE.bazel, Bazel's support for which is planned to be removed "late 2025".

Usage

bazel_dep(name = "rules_clojure")
git_override(
    module_name = "rules_clojure",
    commit = "471f7b87b9752943412f3b358f8addf2feba8f4e",
    remote = "https://github.com/jamesreprise/rules_clojure.git",
)

clojure_tools_deps = use_repo_rule("@rules_clojure//rules:tools_deps.bzl", "clojure_tools_deps")

clojure_tools_deps(
    name = "deps",
    aliases = ["nrepl"],
    deps_edn = "//:deps.edn",
)

Todo

  • Arrive on a satisfying approach for clojure_tools_deps referencing of the rules_clojure repository for running rules-clojure.gen-build.
  • Add usage instructions to README.md
  • Ideally, upload to the Bazel Central Registry so that consumers can depend with just
    bazel_dep(name = "rules_clojure", version = "x.y.z")

Notes

Mike Bland's ongoing series of blog posts on migrating to bzlmod was a useful resource.

jamesreprise and others added 5 commits May 20, 2025 22:17
drive-by: remove erroneous newlines, spaces, add clj-kondo to gitignore
drive-by: clean up tools_deps
paths is passed to the jvm, jvm takes the first one found
@jamesreprise jamesreprise self-assigned this May 21, 2025
@@ -0,0 +1,67 @@
module(
name = "rules_clojure",
version = "0.0.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decide on a version number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the clojure tools.build convention of defaulting to "x.y.z" where x and y are user controlled, and z is the total number of git commits on master. tools.build has a script for computing z, I don't know whether bazel can help there.

Comment on lines +16 to +17
def get_deps_repo_tag(repository_ctx):
return repository_ctx.original_name if hasattr(repository_ctx, "original_name") else repository_ctx.attr.name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a new naming scheme for repositories, which has repository_ctx.attr.name return _main+_repo_rules+deps or similar rather than their given names. original_name was added in Bazel 8.1, but not backported to earlier versions. As a consequence, this PR will have rules_clojure not support the use of bzlmod on Bazel 7.x.

Comment on lines -129 to -130
"_rules_clj_deps": attr.label(default="@rules_clojure//:deps.edn"),
"_rules_clj_src": attr.label(default="@rules_clojure//:src")})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't see these being referenced anywhere.

Comment on lines +104 to +105
org.clojure/tools.deps.alpha {:mvn/version "0.14.1178"}}}""" % (repository_ctx.path("../rules_clojure+/src"),
repository_ctx.path("../rules_clojure/src")),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsatisfied with this hack. I'd like to find a better way to get access to the genbuild code, whether that be by passing a reference into clojure_tools_deps or by finding the right attribute on repository_ctx.

)

maven.install(
name = "rules_clojure_maven_deps",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #22 we introduced a methodology for pinning maven dependencies for WORKSPACE.bazel files that avoided polluting the maven namespace and requiring users to load the dependencies manually. See the rationale given by the original authors of the method: https://github.com/bazel-contrib/rules_jvm/blob/e153df2d3f3077690e0e423769908f66b1d7893f/docs/postfix.md

In bzlmod, neither of these benefits stand - when one module depends on another, the dependee's dependencies are not included in a global namespace, and users do not need to manually load transitive dependencies.

Therefore, we can 'skip' the frozen dependencies part and run maven.install using the name rules_clojure_maven_deps immediately, maintaining compatibility across WORKSPACE and bzlmod approaches.

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

Successfully merging this pull request may close these issues.

2 participants