Make `out` on `native_binary` optional (#474)

Fixes: #399
diff --git a/docs/native_binary_doc.md b/docs/native_binary_doc.md
index 2b603be..67c6be3 100755
--- a/docs/native_binary_doc.md
+++ b/docs/native_binary_doc.md
@@ -30,7 +30,7 @@
 | :------------- | :------------- | :------------- | :------------- | :------------- |
 | <a id="native_binary-name"></a>name |  A unique name for this target.   | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required |  |
 | <a id="native_binary-data"></a>data |  data dependencies. See https://bazel.build/reference/be/common-definitions#typical.data   | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
-| <a id="native_binary-out"></a>out |  An output name for the copy of the binary   | String | required |  |
+| <a id="native_binary-out"></a>out |  An output name for the copy of the binary. Defaults to name.exe. (We add .exe to the name by default because it's required on Windows and tolerated on other platforms.)   | String | optional | <code>""</code> |
 | <a id="native_binary-src"></a>src |  path of the pre-built executable   | <a href="https://bazel.build/concepts/labels">Label</a> | required |  |
 
 
@@ -56,7 +56,7 @@
 | :------------- | :------------- | :------------- | :------------- | :------------- |
 | <a id="native_test-name"></a>name |  A unique name for this target.   | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required |  |
 | <a id="native_test-data"></a>data |  data dependencies. See https://bazel.build/reference/be/common-definitions#typical.data   | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
-| <a id="native_test-out"></a>out |  An output name for the copy of the binary   | String | required |  |
+| <a id="native_test-out"></a>out |  An output name for the copy of the binary. Defaults to name.exe. (We add .exe to the name by default because it's required on Windows and tolerated on other platforms.)   | String | optional | <code>""</code> |
 | <a id="native_test-src"></a>src |  path of the pre-built executable   | <a href="https://bazel.build/concepts/labels">Label</a> | required |  |
 
 
diff --git a/rules/native_binary.bzl b/rules/native_binary.bzl
index b33347b..7b1483a 100644
--- a/rules/native_binary.bzl
+++ b/rules/native_binary.bzl
@@ -21,7 +21,7 @@
 """
 
 def _impl_rule(ctx):
-    out = ctx.actions.declare_file(ctx.attr.out)
+    out = ctx.actions.declare_file(ctx.attr.out if (ctx.attr.out != "") else ctx.attr.name + ".exe")
     ctx.actions.symlink(
         target_file = ctx.executable.src,
         output = out,
@@ -64,7 +64,12 @@
               " https://bazel.build/reference/be/common-definitions#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(
+        default = "",
+        doc = "An output name for the copy of the binary. Defaults to " +
+              "name.exe. (We add .exe to the name by default because it's " +
+              "required on Windows and tolerated on other platforms.)",
+    ),
 }
 
 native_binary = rule(
diff --git a/tests/native_binary/BUILD b/tests/native_binary/BUILD
index d60b78a..ad32cba 100644
--- a/tests/native_binary/BUILD
+++ b/tests/native_binary/BUILD
@@ -96,6 +96,12 @@
     data = ["testdata.txt"],
 )
 
+native_binary(
+    name = "no_out_bin",
+    src = ":copy_assertdata_exe",
+    data = ["testdata.txt"],
+)
+
 native_test(
     name = "data_test",
     src = ":copy_assertdata_exe",