-
Notifications
You must be signed in to change notification settings - Fork 10
DRAFT: Add bzlmod support #67
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
base: main
Are you sure you want to change the base?
Changes from all commits
940bf7d
d0436f1
0669994
a2f2b77
9b07a83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| USE_BAZEL_VERSION=7.4.1 | ||
| USE_BAZEL_VERSION=8.2.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ | |
| .ijwb/ | ||
| bazel-* | ||
|
|
||
| .clj-kondo/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| module( | ||
| name = "rules_clojure", | ||
| version = "0.0.1", | ||
| ) | ||
|
|
||
| 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", | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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") | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a new naming scheme for repositories, which has |
||
|
|
||
| def _install_clj_mac(repository_ctx): | ||
| clj_version = repository_ctx.attr.clj_version | ||
|
|
||
|
|
@@ -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 = """ | ||
|
|
@@ -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"), | ||
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| "-J-Dclojure.main.report=stderr", | ||
| "-M", | ||
|
|
@@ -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) | ||
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.