Skip to content

Commit

Permalink
Add sha256 support for bzlmod case (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianimboden authored May 15, 2024
1 parent 88c0cd8 commit 35408b9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions buf/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load("//buf/internal:toolchain.bzl", "buf_download_releases")
load("//buf/internal:repo.bzl", "buf_dependencies")

_DEFAULT_VERSION = "v1.28.1"
_DEFAULT_SHA256 = "05dfb45d2330559d258e1230f5a25e154f0a328afda2a434348b5ba4c124ece7"
_DEFAULT_TOOLCHAIN_NAME = "rules_buf_toolchains"
_DEFAULT_DEPS = "buf_deps"

Expand All @@ -31,6 +32,7 @@ dependency = tag_class(attrs = {
toolchains = tag_class(attrs = {
"name": attr.string(doc = "name of resulting buf toolchains repo", default = _DEFAULT_TOOLCHAIN_NAME),
"version": attr.string(doc = "Version of the buf tool, see https://github.com/bufbuild/buf/releases"),
"sha256": attr.string(doc = "The checksum sha256.txt file"),
})

def _extension_impl(module_ctx):
Expand All @@ -55,11 +57,11 @@ def _extension_impl(module_ctx):
""")
if toolchains.name not in registrations.keys():
registrations[toolchains.name] = []
registrations[toolchains.name].append(toolchains.version)
registrations[toolchains.name].append({"version": toolchains.version, "sha256": toolchains.sha256})

# Don't require that the user manually registers a toolchain
if len(registrations) == 0:
registrations = {_DEFAULT_TOOLCHAIN_NAME: [_DEFAULT_VERSION]}
registrations = {_DEFAULT_TOOLCHAIN_NAME: [{"version": _DEFAULT_VERSION, "sha256": _DEFAULT_SHA256}]}

for name, versions in registrations.items():
if len(versions) > 1:
Expand All @@ -72,7 +74,8 @@ def _extension_impl(module_ctx):
selected = versions[0]
buf_download_releases(
name = name,
version = selected,
version = selected["version"],
sha256 = selected["sha256"],
)

for name, modules in dependencies.items():
Expand Down

0 comments on commit 35408b9

Please sign in to comment.