Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Bazel Function to return sha256sum

15 views
Skip to first unread message

Manish Singh

unread,
Dec 1, 2024, 4:24:30 PM12/1/24
to bazel-discuss

Hi, 

I am looking a way to find sha256sum in bazel. 

normally  bazel rule defines output which is written to file.

def _impl(ctx):
    # Create actions to generate the three output files.
    # Actions are run only when the corresponding file is requested.

    ctx.actions.run_shell(
        outputs = [ctx.outputs.sha256],
        inputs = [ctx.file.src],
        use_default_shell_env = True,
        command = "sha256sum {} > {}".format(ctx.file.src.path, ctx.outputs.sha256.path),
    )

    # By default (if you run `bazel build` on this target, or if you use it as a
    # source of another target), only the sha256 is computed.
    return DefaultInfo(files = depset([ctx.outputs.sha256]))


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

def hashes(**kwargs):
    name = kwargs["name"]
    _hashes(
        sha256 = "%s.sha256" % name,
        **kwargs
    )

How can I create a function/macro which returns sha256 of given source? Appreciate help?



Thanks,
Reply all
Reply to author
Forward
0 new messages