Skip to content

Commit a61c186

Browse files
authored
Support fully deterministic toolchain (#36)
1 parent 03484cb commit a61c186

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

buf/internal/toolchain.bzl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def declare_buf_toolchains(os, cpu, rules_buf_repo_name):
5555
ext = ""
5656
if os == "windows":
5757
ext = ".exe"
58-
toolchain_impl = cmd + "_toolchain_impl"
58+
toolchain_impl = cmd + "_toolchain_impl"
5959
_buf_toolchain(
6060
name = toolchain_impl,
6161
cli = str(Label("//:"+ cmd)),
@@ -133,6 +133,7 @@ def _detect_host_platform(ctx):
133133

134134
def _buf_download_releases_impl(ctx):
135135
version = ctx.attr.version
136+
sha256 = ctx.attr.sha256
136137
if not version:
137138
ctx.report_progress("Finding latest buf version")
138139

@@ -156,12 +157,13 @@ def _buf_download_releases_impl(ctx):
156157
cpu = "x86_64"
157158

158159
ctx.report_progress("Downloading buf release hash")
159-
ctx.download(
160+
sha256 = ctx.download(
160161
url = [
161162
"https://github.com/bufbuild/buf/releases/download/{}/sha256.txt".format(version),
162163
],
164+
sha256 = sha256,
163165
output = "sha256.txt",
164-
)
166+
).sha256
165167
ctx.file("WORKSPACE", "workspace(name = \"{name}\")".format(name = ctx.name))
166168
ctx.file("toolchain.bzl", _TOOLCHAIN_FILE)
167169
sha_list = ctx.read("sha256.txt").splitlines()
@@ -197,27 +199,30 @@ def _buf_download_releases_impl(ctx):
197199
rules_buf_repo_name = Label("//buf/repositories.bzl").workspace_name,
198200
),
199201
)
200-
return update_attrs(ctx.attr, ["version"], {"version": version})
202+
return update_attrs(ctx.attr, ["version", "sha256"], {"version": version, "sha256": sha256})
201203

202204
_buf_download_releases = repository_rule(
203205
implementation = _buf_download_releases_impl,
204206
attrs = {
205207
"version": attr.string(
206208
doc = "Buf release version",
207209
),
210+
"sha256": attr.string(
211+
doc = "Buf release sha256.txt checksum",
212+
),
208213
},
209214
)
210215

211216
# buildifier: disable=unnamed-macro
212-
def rules_buf_toolchains(name = _TOOLCHAINS_REPO, version = None):
217+
def rules_buf_toolchains(name = _TOOLCHAINS_REPO, version = None, sha256 = None):
213218
"""rules_buf_toolchains sets up toolchains for buf, protoc-gen-buf-lint, and protoc-gen-buf-breaking
214219
215220
Args:
216221
name: The name of the toolchains repository. Defaults to "buf_toolchains"
217222
version: Release version, eg: `v.1.0.0-rc12`. If `None` defaults to latest
218223
"""
219224

220-
_buf_download_releases(name = name, version = version)
225+
_buf_download_releases(name = name, version = version, sha256 = sha256)
221226

222227
_register_toolchains(name, "buf")
223228
_register_toolchains(name, "protoc-gen-buf-breaking")

0 commit comments

Comments
 (0)