Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazeliskrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
USE_BAZEL_VERSION=7.4.1
USE_BAZEL_VERSION=8.2.1
4 changes: 3 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ test --test_output=all
test --verbose_failures

build --java_runtime_version=remotejdk_17
build --tool_java_runtime_version=remotejdk_17
build --tool_java_runtime_version=remotejdk_17

common --enable_bzlmod
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.ijwb/
bazel-*

.clj-kondo/
67 changes: 67 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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.

)

bazel_dep(name = "rules_jvm_external", version = "6.7")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")

maven.artifact(
name = "rules_clojure_maven_deps",
group = "org.clojure",
artifact = "clojure",
version = "1.11.1",
exclusions = [
"org.clojure:spec.alpha",
"org.clojure:core.specs.alpha"
]
)

maven.artifact(
name = "rules_clojure_maven_deps",
group = "org.clojure",
artifact = "spec.alpha",
version = "0.3.218",
exclusions = ["org.clojure:clojure"]
)

maven.artifact(
name = "rules_clojure_maven_deps",
group = "org.clojure",
artifact = "core.specs.alpha",
version = "0.2.62",
exclusions = [
"org.clojure:clojure",
"org.clojure:spec.alpha"
]
)

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.

artifacts = [
"org.clojure:data.json:2.4.0",
"org.clojure:java.classpath:1.0.0",
"org.clojure:tools.namespace:1.1.0",
"org.clojure:tools.deps.alpha:0.14.1212"
],
# When updating versions, run `REPIN=1 bazel run @rules_clojure_maven_deps//:pin`
fail_if_repin_required = True,
lock_file = "//:rules_clojure_maven_deps_install.json",
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.clojars.org/"
]
)

maven.install(
name = "clojure_old",
artifacts = ["org.clojure:clojure:1.8.0"],
fail_if_repin_required = True,
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.clojars.org/"
]
)

use_repo(maven, "rules_clojure_maven_deps", "clojure_old")
221 changes: 221 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ maven_install(
load("@frozen_deps//:defs.bzl", "pinned_maven_install")
pinned_maven_install()

load ("//:repositories.bzl", "rules_clojure_deps")
load("//:repositories.bzl", "rules_clojure_deps")
rules_clojure_deps()

load("//:setup.bzl", "rules_clojure_setup")
rules_clojure_setup()


# used for testing
maven_install(
name = "clojure_old",
Expand Down
1 change: 0 additions & 1 deletion rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def clojure_test(name, *, test_ns, deps=[], runtime_deps=[], **kwargs):
**kwargs)

def cljs_impl(ctx):

runfiles = ctx.runfiles(files=ctx.outputs.outs)

inputs = ctx.files.data + ctx.files.compile_opts_files
Expand Down
1 change: 0 additions & 1 deletion rules/jar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def printable_label(label):
label.name)

def clojure_jar_impl(ctx):

if (len(ctx.attr.srcs) > 0 and len(ctx.attr.aot) == 0):
fail("srcs but no AOT")

Expand Down
18 changes: 11 additions & 7 deletions rules/tools_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ CLJ_VERSIONS_LINUX = {
clj_install_prefix = "tools.deps"
clj_path = clj_install_prefix + "/bin/clojure"

def get_deps_repo_tag(repository_ctx):
return repository_ctx.original_name if hasattr(repository_ctx, "original_name") else repository_ctx.attr.name
Comment on lines +16 to +17
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.


def _install_clj_mac(repository_ctx):
clj_version = repository_ctx.attr.clj_version

Expand Down Expand Up @@ -65,6 +68,7 @@ def aliases_str(aliases):
return str("[" + " ".join([ (":%s" % (a)) for a in aliases]) + "]")

def _install_scripts(repository_ctx):
deps_repo_tag = get_deps_repo_tag(repository_ctx)
repository_ctx.file(repository_ctx.path("scripts/BUILD.bazel"),
executable = True,
content = """
Expand All @@ -81,7 +85,7 @@ java_binary(name="gen_srcs",
":aliases", "\\"{aliases}\\""],
data=["{deps_edn_label}"])

""".format(deps_repo_tag = "@" + repository_ctx.attr.name,
""".format(deps_repo_tag = "@" + deps_repo_tag,
deps_edn_label = repository_ctx.attr.deps_edn,
deps_edn_path = repository_ctx.path(repository_ctx.attr.deps_edn),
repository_dir = repository_ctx.path("repository"),
Expand All @@ -92,11 +96,13 @@ def _symlink_repository(repository_ctx):
repository_ctx.symlink(repository_ctx.os.environ["HOME"] + "/.m2/repository", repository_ctx.path("repository"))

def _run_gen_build(repository_ctx):
deps_repo_tag = get_deps_repo_tag(repository_ctx)
args = [repository_ctx.path("tools.deps/bin/clojure"),
"-Srepro",
"-Sdeps", """{:paths ["%s"]
"-Sdeps", """{:paths ["%s", "%s"]
:deps {org.clojure/tools.namespace {:mvn/version "1.1.0"}
org.clojure/tools.deps.alpha {:mvn/version "0.14.1178"}}}""" % repository_ctx.path("../rules_clojure/src"),
org.clojure/tools.deps.alpha {:mvn/version "0.14.1178"}}}""" % (repository_ctx.path("../rules_clojure+/src"),
repository_ctx.path("../rules_clojure/src")),
Comment on lines +104 to +105
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.


"-J-Dclojure.main.report=stderr",
"-M",
Expand All @@ -105,7 +111,7 @@ def _run_gen_build(repository_ctx):
":deps-edn-path", repository_ctx.path(repository_ctx.attr.deps_edn),
":repository-dir", repository_ctx.path("repository/"),
":deps-build-dir", repository_ctx.path(""),
":deps-repo-tag", "@" + repository_ctx.attr.name,
":deps-repo-tag", "@" + deps_repo_tag,
":workspace-root", repository_ctx.attr.deps_edn.workspace_root,
":aliases", aliases_str(repository_ctx.attr.aliases)]
ret = repository_ctx.execute(args, quiet=False, environment=repository_ctx.attr.env)
Expand All @@ -125,9 +131,7 @@ clojure_tools_deps = repository_rule(
attrs = {"deps_edn": attr.label(allow_single_file = True),
"aliases": attr.string_list(default = [], doc = "extra aliases in deps.edn to merge in while resolving deps"),
"clj_version": attr.string(default="1.11.1.1347"),
"env": attr.string_dict(default = {}),
"_rules_clj_deps": attr.label(default="@rules_clojure//:deps.edn"),
"_rules_clj_src": attr.label(default="@rules_clojure//:src")})
Comment on lines -129 to -130
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.

"env": attr.string_dict(default = {})})

def clojure_gen_srcs(name):
native.alias(name=name,
Expand Down
Loading