@@ -115,6 +115,9 @@ _go_cc_aspect = aspect(
115115
116116def _go_binary_impl (ctx ):
117117 """go_binary_impl emits actions for compiling and linking a go executable."""
118+ if ctx .attr .out and ctx .attr .out_auto :
119+ fail ("Only one of out and out_auto must be set." )
120+
118121 go = go_context (
119122 ctx ,
120123 include_deprecated_properties = False ,
@@ -148,11 +151,14 @@ def _go_binary_impl(ctx):
148151 validation_output = archive .data ._validation_output
149152 nogo_diagnostics = archive .data ._nogo_diagnostics
150153
151- if ctx .attr .out :
152- # Use declare_file instead of attr.output(). When users set output files
153- # directly, Bazel warns them not to use the same name as the rule, which is
154- # the common case with go_binary.
155- executable = ctx .actions .declare_file (ctx .attr .out )
154+ if ctx .attr .out or ctx .attr .out_auto :
155+ if ctx .attr .out :
156+ # Use declare_file instead of attr.output(). When users set output files
157+ # directly, Bazel warns them not to use the same name as the rule, which is
158+ # the common case with go_binary.
159+ executable = ctx .actions .declare_file (ctx .attr .out )
160+ else :
161+ executable = ctx .actions .declare_file (name )
156162 ctx .actions .symlink (
157163 output = executable ,
158164 target_file = executable_binary ,
@@ -316,7 +322,11 @@ def _go_binary_kwargs(go_cc_aspects = []):
316322 """ ,
317323 ),
318324 "out" : attr .string (
319- doc = """Sets the output symlink filename for the generated executable.
325+ doc = """Create a symlink with this name for the generated executable.
326+ """ ,
327+ ),
328+ "out_auto" : attr .bool (
329+ doc = """Create a symlink with a name inferred from basename for the generated executable.
320330 """ ,
321331 ),
322332 "cgo" : attr .bool (
0 commit comments