Skip to content

Add dependency pinning for rules_clojure's own Maven dependencies#22

Merged
dancmeyers merged 2 commits intomainfrom
infra/zip-pin-deps
Nov 16, 2022
Merged

Add dependency pinning for rules_clojure's own Maven dependencies#22
dancmeyers merged 2 commits intomainfrom
infra/zip-pin-deps

Conversation

@dancmeyers
Copy link
Contributor

@dancmeyers dancmeyers commented Nov 14, 2022

What

Some minor refactors, for consistency:

  • Add .cpcache to .gitignore, so you can run bazel commands in-repo and not get spurious files.
  • Rename BUILD.bazel files to BUILD, as that is the newer pattern, and we had a mixture of both.

The main event

We're now following the pattern that the Bazel team themselves use for dependencies of rules, particularly for JVM-based languages making use of rules_jvm_external. E.g. this is used in contrib/rules_jvm, among others.

  • We've pinned the dependencies for rules_clojure in frozen_deps_install.json, using standard options built into maven_install.
  • There's a new zip_repository definition, that extracts the files necessary for Bazel to fetch dependencies from a zipfile.
  • This zip_repository is what we reference everywhere when referring to rules_clojure's internal dependencies, so is what is run by users of rules_clojure to set it up.
  • To construct the zipfile, there is a (for now, Python) script under tools/freeze-deps.py. Instructions in README.md explain how to update deps when necessary.

The Python script is pretty simple, and could be changed to a Clojure one in future. For now, while proving the idea, I've kept it as is. Both it and zip_repository.bzl were taken from contrib/rules_jvm, where they're licensed under Apache 2. One of the devs of rules_jvm_external and that (seems to do most of the releases for both) helped me out with all this and pointed me at them.

Why?

By pinning dependencies and making it so that users of rules_clojure reference the pinned versions, users can make use of standard Bazel options and configuration to switch the mirrors used to fetch files from (https://bazel.build/reference/command-line-reference#flag--experimental_downloader_config), and to configure auth for those new URLs (via .netrc: https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html). This is the recommended way to handle upstream dependencies in Bazel, rather than requiring your users to understand whatever is being used within your rule (Coursier, in the case of rules_jvm_external, which is why none of our configuration in ~/.m2/settings.xml for Maven was obeyed. There are also other issues that arise if you use Coursier's own mirror config, as it breaks rules_jvm_external).

See https://github.com/griffinbank/banksy/pull/5395 for am example of it 'in action'.

@dancmeyers dancmeyers force-pushed the infra/zip-pin-deps branch 8 times, most recently from d0db43f to 8bc7233 Compare November 15, 2022 10:47
RULES_JVM_EXTERNAL_TAG = "4.2"
RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca"
RULES_JVM_EXTERNAL_TAG = "4.5"
RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rules_jvm_external 4.5 is needed to properly support the .netrc stuff we intend to use in banksy.

clojure_library(
name = "example",
srcs = ["example.clj"],
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've deleted this example, as it seemed outdated. Even before I started changing stuff around, I couldn't find anything in toolchains.bzl that allowed defining a custom toolchain, only the rules_clojure_default_toolchain function, which has now become setup.bzl/rules_clojure_setup.

@dancmeyers dancmeyers changed the title WIP test Add dependency pinning for rules_clojure's own Maven dependencies Nov 15, 2022
@dancmeyers dancmeyers marked this pull request as ready for review November 15, 2022 10:58
Some minor refactors, for consistency:
- Add `.cpcache` to `.gitignore`, so you can run `bazel` commands
  in-repo and not get spurious files.
- Rename `BUILD.bazel` files to `BUILD`, as that is the newer pattern,
  and we had a mixture of both.

And now, the main event:

We're now following the pattern that the Bazel team themselves use for
dependencies of rules, particularly for JVM-based languages making use
of `rules_jvm_external`. E.g. this is used in `contrib/rules_jvm`, among
others.

- We've pinned the dependencies for `rules_clojure` in
  `frozen_deps_install.json`, using standard options built into
`maven_install`.
- There's a new `zip_repository` definition, that extracts the files
  necessary for Bazel to fetch dependencies from a zipfile.
- This `zip_repository` is what we reference everywhere when referring
  to `rules_clojure`'s internal dependencies, so is what is run by users
of `rules_clojure` to set it up.
- To construct the zipfile, there is a (for now, Python) script under
  `tools/freeze-deps.py`. Instructions in `README.md` explain how to
update deps when necessary.

The Python script is pretty simple, and could be changed to a Clojure
one in future. For now, while proving the idea, I've kept it as is. Both
it and `zip_repository.bzl` were taken from `contrib/rules_jvm`, where
they're licensed under Apache 2. One of the devs of `rules_jvm_external`
and that (seems to do most of the releases for both) helped me out with
all this and pointed me at them.
load("@rules_clojure//:toolchains.bzl", "rules_clojure_default_toolchain")
rules_clojure_default_toolchain()
load("@rules_clojure//:setup.bzl", "rules_clojure_setup")
rules_clojure_setup()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This 2 stage 'deps+setup' pattern is apparently very common in Bazel.

@dancmeyers dancmeyers mentioned this pull request Nov 15, 2022
WORKSPACE Outdated
"org.clojure:java.classpath:1.0.0",
"org.clojure:tools.namespace:1.1.0",
"org.clojure:tools.deps.alpha:0.14.1212",
"org.projectodd.shimdandy:shimdandy-api:1.2.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Shimdandy is no longer required since the rewrite in clojure, but it looks like I failed to remove it from deps.

It's not needed any more.
@dancmeyers dancmeyers merged commit 020161f into main Nov 16, 2022
@dancmeyers dancmeyers deleted the infra/zip-pin-deps branch November 16, 2022 13:54
@jamesreprise jamesreprise mentioned this pull request May 21, 2025
3 tasks
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