diff --git a/docs/go/core/rules.bzl b/docs/go/core/rules.bzl index be87765db..6acf32a54 100644 --- a/docs/go/core/rules.bzl +++ b/docs/go/core/rules.bzl @@ -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 @@ -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 @@ -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 diff --git a/docs/go/core/rules.md b/docs/go/core/rules.md index 5504bfb44..d41724c30 100644 --- a/docs/go/core/rules.md +++ b/docs/go/core/rules.md @@ -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 @@ -293,6 +294,42 @@ go_path(name, data, + +## go_reset_target + +
+go_reset_target(name, dep)
+
+ +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 | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| dep | The target to forward providers from and apply go_tool_transition to. | Label | required | | + + + + + ## go_source diff --git a/go/def.bzl b/go/def.bzl index 7a97073ac..e84245e35 100644 --- a/go/def.bzl +++ b/go/def.bzl @@ -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", @@ -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 diff --git a/go/private/rules/transition.bzl b/go/private/rules/transition.bzl index 89840eec3..b4b1c56b5 100644 --- a/go/private/rules/transition.bzl +++ b/go/private/rules/transition.bzl @@ -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. """, )