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

native_binary: use target name as filename by default #373

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

psigen
Copy link

@psigen psigen commented Jun 10, 2022

This changes the out attribute in native binary to default to the target name if unspecified, which is convenient because it can be omitted when renaming targets that are linux executables and frequently share the target name.

⚠️ This is just a proposal for feedback. If this looks interesting, I will clean up the change and can apply it more consistently over more of the native_* rules as suggested.

My motivating example: wrapping a ton of CLI tools like this:

native_binary(
    name = "kubectl",
    src = select({
        "@bazel_tools//src/conditions:linux_x86_64": "@io_k8s_kubectl_linux_x86_64//file:kubectl",
        "@bazel_tools//src/conditions:darwin_x86_64": "@io_k8s_kubectl_darwin_x86_64//file:kubectl",
    }),
    out = "kubectl",  # <--- it would be great to de-duplicate this
)

This changes the `out` attribute in native binary to default to the target name
if unspecified, which is convenient because it can be omitted when renaming targets
that are linux executables and frequently share the target name.
Copy link
Collaborator

@tetromino tetromino left a comment

Choose a reason for hiding this comment

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

The default is unsuitable for Windows, where executable files must have an extension. You'd need to make the rule hidden (e.g. _native_binary) and wrap it in a macro, something along the lines of

 def native_binary(name, src, out = None, data = None, **kwargs):
    """Move rule docs here"""
    if out == None:
        out = select({
            "@bazel_tools//src/conditions:windows": "%s.exe" % name,
            "//conditions:default": name,
        })
    _native_binary(
        name = name,
        src = src,
        out = out,
        data = data,
        **kwargs
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants