xref: /llvm-project/utils/bazel/llvm-project-overlay/llvm/binary_alias.bzl (revision 4aeb2e60df98a07e6a2a3cc16fc9ad1c1001d563)
1# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5"""Creates a copy of a binary, giving it a different basename.
6
7binary_alias(
8    name = "my_binary_other_name",
9    binary = ":some_cc_binary",
10)
11"""
12
13def _binary_alias_impl(ctx):
14    ctx.actions.symlink(
15        target_file = ctx.executable.binary,
16        output = ctx.outputs.executable,
17        is_executable = True,
18    )
19
20    return [DefaultInfo(
21        executable = ctx.outputs.executable,
22        runfiles = ctx.attr.binary[DefaultInfo].default_runfiles,
23    )]
24
25binary_alias = rule(
26    _binary_alias_impl,
27    attrs = {
28        "binary": attr.label(
29            mandatory = True,
30            executable = True,
31            cfg = "target",
32        ),
33    },
34    executable = True,
35)
36