Skip to content

Commit

Permalink
make go_reset_target publicly usable
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-french committed Jul 10, 2024
1 parent c2212fd commit 762b419
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/go/core/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
[go_path]: #go_path
[go_source]: #go_source
[go_test]: #go_test
[go_reset_target]: #go_reset_target
[Examples]: examples.md#examples
[Defines and stamping]: defines_and_stamping.md#defines-and-stamping
[Stamping with the workspace status script]: defines_and_stamping.md#stamping-with-the-workspace-status-script
Expand Down Expand Up @@ -119,6 +120,7 @@ load("//go/private/rules:cross.bzl", _go_cross_binary = "go_cross_binary")
load("//go/private/rules:library.bzl", _go_library = "go_library")
load("//go/private/rules:source.bzl", _go_source = "go_source")
load("//go/private/rules:test.bzl", _go_test = "go_test")
load("//go/private/rules:transition.bzl", _go_reset_target = "go_reset_target")
load("//go/private/tools:path.bzl", _go_path = "go_path")

go_library = _go_library
Expand All @@ -127,3 +129,4 @@ go_test = _go_test
go_source = _go_source
go_path = _go_path
go_cross_binary = _go_cross_binary
go_reset_target = _go_reset_target
37 changes: 37 additions & 0 deletions docs/go/core/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
[go_path]: #go_path
[go_source]: #go_source
[go_test]: #go_test
[go_reset_target]: #go_reset_target
[Examples]: examples.md#examples
[Defines and stamping]: defines_and_stamping.md#defines-and-stamping
[Stamping with the workspace status script]: defines_and_stamping.md#stamping-with-the-workspace-status-script
Expand Down Expand Up @@ -293,6 +294,42 @@ go_path(<a href="#go_path-name">name</a>, <a href="#go_path-data">data</a>, <a h



<a id="#go_reset_target"></a>

## go_reset_target

<pre>
go_reset_target(<a href="#go_reset_target-name">name</a>, <a href="#go_reset_target-dep">dep</a>)
</pre>

Forwards providers from a target and default Go binary settings.

go_reset_target depends on a single target and builds it to be a Go tool binary. It
forwards Go providers and DefaultInfo.

go_reset_target does two things using transitions:
1. builds the tool with 'cfg = "exec"' so they work on the execution platform.
2. Sets most Go settings to default value and disables nogo.

This is used for Go tool binaries that shouldn't depend on the link mode or tags of the
target configuration and neither the tools nor the code they potentially
generate should be subject to Nogo's static analysis. This is helpful, for example, so
a tool isn't built as a shared library with race instrumentation. This acts as an
intermediate rule that allows users to apply these transitions.


### **Attributes**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="go_reset_target-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="go_reset_target-dep"></a>dep | The target to forward providers from and apply go_tool_transition to. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |





<a id="#go_source"></a>

## go_source
Expand Down
7 changes: 7 additions & 0 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ load(
"//go/private/rules:source.bzl",
_go_source = "go_source",
)
load(
"//go/private/rules:transition.bzl",
_go_reset_target = "go_reset_target",
)
load(
"//go/private/rules:wrappers.bzl",
_go_binary_macro = "go_binary_macro",
Expand Down Expand Up @@ -163,6 +167,9 @@ go_source = _go_source
# See docs/go/core/rules.md#go_path for full documentation.
go_path = _go_path

# See docs/go/core/rules.md#go_reset_target for full documentation.
go_reset_target = _go_reset_target

# See docs/go/core/rules.md#go_cross_binary for full documentation.
go_cross_binary = _go_cross_binary

Expand Down
19 changes: 12 additions & 7 deletions go/private/rules/transition.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,26 @@ go_reset_target = rule(
"dep": attr.label(
mandatory = True,
cfg = go_tool_transition,
doc = """The target to forward providers from and apply go_tool_transition to.""",
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
doc = """Forwards providers from a target and applies go_tool_transition.
doc = """Forwards providers from a target and default Go binary settings.
go_reset_target depends on a single target, built using go_tool_transition. It
go_reset_target depends on a single target and builds it to be a Go tool binary. It
forwards Go providers and DefaultInfo.
This is used to work around a problem with building tools: Go tools should be
built with 'cfg = "exec"' so they work on the execution platform, but we also
need to apply go_tool_transition so that e.g. a tool isn't built as a shared
library with race instrumentation. This acts as an intermediate rule that allows
to apply both both transitions.
go_reset_target does two things using transitions:
1. builds the tool with 'cfg = "exec"' so they work on the execution platform.
2. Sets most Go settings to default value and disables nogo.
This is used for Go tool binaries that shouldn't depend on the link mode or tags of the
target configuration and neither the tools nor the code they potentially
generate should be subject to Nogo's static analysis. This is helpful, for example, so
a tool isn't built as a shared library with race instrumentation. This acts as an
intermediate rule that allows users to apply these transitions.
""",
)

Expand Down

0 comments on commit 762b419

Please sign in to comment.