diff --git a/docs/native_binary_doc.md b/docs/native_binary_doc.md index a9c476dc..0dcee4af 100755 --- a/docs/native_binary_doc.md +++ b/docs/native_binary_doc.md @@ -30,7 +30,7 @@ in genrule.tools for example. You can also augment the binary with runfiles. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | data | data dependencies. See https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data | List of labels | optional | [] | -| out | An output name for the copy of the binary | String | required | | +| out | An output name for the copy of the binary (defaults to target name) | String | optional | "" | | src | path of the pre-built executable | Label | required | | @@ -56,7 +56,7 @@ the binary with runfiles. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | data | data dependencies. See https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data | List of labels | optional | [] | -| out | An output name for the copy of the binary | String | required | | +| out | An output name for the copy of the binary (defaults to target name) | String | optional | "" | | src | path of the pre-built executable | Label | required | | diff --git a/rules/native_binary.bzl b/rules/native_binary.bzl index a027fc9a..25f6a251 100644 --- a/rules/native_binary.bzl +++ b/rules/native_binary.bzl @@ -21,7 +21,12 @@ don't depend on Bash and work with --shell_executable="". """ def _impl_rule(ctx): - out = ctx.actions.declare_file(ctx.attr.out) + if ctx.attr.out: + out_file = ctx.attr.out + else: + out_file = ctx.name + out = ctx.actions.declare_file(out_file) + ctx.actions.symlink( target_file = ctx.executable.src, output = out, @@ -64,7 +69,7 @@ _ATTRS = { " https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data", ), # "out" is attr.string instead of attr.output, so that it is select()'able. - "out": attr.string(mandatory = True, doc = "An output name for the copy of the binary"), + "out": attr.string(doc = "An output name for the copy of the binary (defaults to target name)"), } native_binary = rule(