Skip to content
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

Generate sha256 message digest for built binaries #418

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("//:def.bzl", "sha256sum")

# gazelle:prefix github.com/bazelbuild/bazelisk
gazelle(name = "gazelle")
Expand Down Expand Up @@ -85,6 +86,11 @@ go_binary(
visibility = ["//visibility:public"],
)

sha256sum(
name = "bazelisk-darwin-amd64-sha",
src = ":bazelisk-darwin-amd64",
)

go_binary(
name = "bazelisk-darwin-arm64",
out = "bazelisk-darwin_arm64",
Expand All @@ -99,6 +105,11 @@ go_binary(
visibility = ["//visibility:public"],
)

sha256sum(
name = "bazelisk-darwin-arm64-sha",
src = ":bazelisk-darwin-arm64",
)

genrule(
name = "bazelisk-darwin-universal",
srcs = [
Expand All @@ -113,6 +124,11 @@ genrule(
],
)

sha256sum(
name = "bazelisk-darwin-universal-sha",
src = ":bazelisk-darwin-universal",
)

go_binary(
name = "bazelisk-linux-amd64",
out = "bazelisk-linux_amd64",
Expand All @@ -127,6 +143,11 @@ go_binary(
visibility = ["//visibility:public"],
)

sha256sum(
name = "bazelisk-linux-amd64-sha",
src = ":bazelisk-linux-amd64",
)

go_binary(
name = "bazelisk-linux-arm64",
out = "bazelisk-linux_arm64",
Expand All @@ -141,6 +162,11 @@ go_binary(
visibility = ["//visibility:public"],
)

sha256sum(
name = "bazelisk-linux-arm64-sha",
src = ":bazelisk-linux-arm64",
)

go_binary(
name = "bazelisk-windows-amd64",
out = "bazelisk-windows_amd64.exe",
Expand All @@ -151,6 +177,11 @@ go_binary(
visibility = ["//visibility:public"],
)

sha256sum(
name = "bazelisk-windows-amd64-sha",
src = ":bazelisk-windows-amd64",
)

pkg_npm(
name = "npm_package",
package_name = "@bazel/bazelisk",
Expand Down
27 changes: 27 additions & 0 deletions def.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def _sha256sum_impl(ctx):
ctx.actions.run_shell(
outputs = [ctx.outputs.sha256],
inputs = [ctx.file.src],
command = "CWD=$PWD && cd `dirname {0}` && sha256sum `basename {0}` > $CWD/{1}".format(ctx.file.src.path, ctx.outputs.sha256.path),
Copy link
Member

Choose a reason for hiding this comment

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

We typically build releases on MacOS, which uses a different tool (shasum -a 256)

)

return DefaultInfo(files = depset([ctx.outputs.sha256]))

_sha256sum = rule(
implementation = _sha256sum_impl,
attrs = {
"src": attr.label(mandatory = True, allow_single_file = True),
"sha256": attr.output(),
}
)

def sha256sum(name, src, **kwargs):
"""
Macro to create a sha256 message digest file
"""
_sha256sum(
name = name,
src = src,
sha256 = "%s.sha256" % src,
**kwargs,
)