diff --git a/docs/go/core/rules.md b/docs/go/core/rules.md
index 2ebc022541..f28e33d753 100644
--- a/docs/go/core/rules.md
+++ b/docs/go/core/rules.md
@@ -139,31 +139,31 @@ This builds an executable from a set of source files,
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| name | A unique name for this target. | Name | required | |
-| basename | The basename of this binary. The binary basename may also be platform-dependent: on Windows, we add an .exe extension. | String | optional | "" |
-| cdeps | The list of other libraries that the c code depends on. This can be anything that would be allowed in [cc_library deps] Only valid if cgo
= True
. | List of labels | optional | [] |
-| cgo | If True
, the package may contain [cgo] code, and srcs
may contain C, C++, Objective-C, and Objective-C++ files and non-Go assembly files. When cgo is enabled, these files will be compiled with the C/C++ toolchain and included in the package. Note that this attribute does not force cgo to be enabled. Cgo is enabled for non-cross-compiling builds when a C/C++ toolchain is configured. | Boolean | optional | False |
-| clinkopts | List of flags to add to the C link command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
-| copts | List of flags to add to the C compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
-| cppopts | List of flags to add to the C/C++ preprocessor command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
-| cxxopts | List of flags to add to the C++ compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
-| data | List of files needed by this rule at run-time. This may include data files needed or other programs that may be executed. The [bazel] package may be used to locate run files; they may appear in different places depending on the operating system and environment. See [data dependencies] for more information on data files. | List of labels | optional | [] |
-| deps | List of Go libraries this package imports directly. These may be go_library
rules or compatible rules with the [GoLibrary] provider. | List of labels | optional | [] |
-| embed | List of Go libraries whose sources should be compiled together with this binary's sources. Labels listed here must name go_library
, go_proto_library
, or other compatible targets with the [GoLibrary] and [GoSource] providers. Embedded libraries must all have the same importpath
, which must match the importpath
for this go_binary
if one is specified. At most one embedded library may have cgo = True
, and the embedding binary may not also have cgo = True
. See [Embedding] for more information. | List of labels | optional | [] |
-| embedsrcs | The list of files that may be embedded into the compiled package using //go:embed
directives. All files must be in the same logical directory or a subdirectory as source files. All source files containing //go:embed
directives must be in the same logical directory. It's okay to mix static and generated source files and static and generated embeddable files. | List of labels | optional | [] |
-| gc_goopts | List of flags to add to the Go compilation command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] |
-| gc_linkopts | List of flags to add to the Go link command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] |
-| goarch | Forces a binary to be cross-compiled for a specific architecture. It's usually better to control this on the command line with --platforms
.
This disables cgo by default, since a cross-compiling C/C++ toolchain is rarely available. To force cgo, set pure
= off
.
See [Cross compilation] for more information. | String | optional | "auto" |
-| goos | Forces a binary to be cross-compiled for a specific operating system. It's usually better to control this on the command line with --platforms
.
This disables cgo by default, since a cross-compiling C/C++ toolchain is rarely available. To force cgo, set pure
= off
.
See [Cross compilation] for more information. | String | optional | "auto" |
-| gotags | Enables a list of build tags when evaluating [build constraints]. Useful for conditional compilation. | List of strings | optional | [] |
-| importpath | The import path of this binary. Binaries can't actually be imported, but this may be used by [go_path] and other tools to report the location of source files. This may be inferred from embedded libraries. | String | optional | "" |
-| linkmode | Determines how the binary should be built and linked. This accepts some of the same values as `go build -buildmode` and works the same way.
on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:msan
. See [mode attributes], specifically [msan]. | String | optional | "auto" |
-| out | Sets the output filename for the generated executable. When set, go_binary
will write this file without mode-specific directory prefixes, without linkmode-specific prefixes like "lib", and without platform-specific suffixes like ".exe". Note that without a mode-specific directory prefix, the output file (but not its dependencies) will be invalidated in Bazel's cache when changing configurations. | String | optional | "" |
-| pure | Controls whether cgo source code and dependencies are compiled and linked, similar to setting CGO_ENABLED
. May be one of on
, off
, or auto
. If auto
, pure mode is enabled when no C/C++ toolchain is configured or when cross-compiling. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:pure
. See [mode attributes], specifically [pure]. | String | optional | "auto" |
-| race | Controls whether code is instrumented for race detection. May be one of on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:race
. See [mode attributes], specifically [race]. | String | optional | "auto" |
-| srcs | The list of Go source files that are compiled to create the package. Only .go
and .s
files are permitted, unless the cgo
attribute is set, in which case, .c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm
files are also permitted. Files may be filtered at build time using Go [build constraints]. | List of labels | optional | [] |
-| static | Controls whether a binary is statically linked. May be one of on
, off
, or auto
. Not available on all platforms or in all modes. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:static
. See [mode attributes], specifically [static]. | String | optional | "auto" |
-| x_defs | Map of defines to add to the go link command. See [Defines and stamping] for examples of how to use these. | Dictionary: String -> String | optional | {} |
+| basename | The basename of this binary. The binary basename may also be platform-dependent: on Windows, we add an .exe extension. | String | optional | "" |
+| cdeps | The list of other libraries that the c code depends on. This can be anything that would be allowed in [cc_library deps] Only valid if cgo
= True
. | List of labels | optional | [] |
+| cgo | If True
, the package may contain [cgo] code, and srcs
may contain C, C++, Objective-C, and Objective-C++ files and non-Go assembly files. When cgo is enabled, these files will be compiled with the C/C++ toolchain and included in the package. Note that this attribute does not force cgo to be enabled. Cgo is enabled for non-cross-compiling builds when a C/C++ toolchain is configured. | Boolean | optional | False |
+| clinkopts | List of flags to add to the C link command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
+| copts | List of flags to add to the C compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
+| cppopts | List of flags to add to the C/C++ preprocessor command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
+| cxxopts | List of flags to add to the C++ compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
+| data | List of files needed by this rule at run-time. This may include data files needed or other programs that may be executed. The [bazel] package may be used to locate run files; they may appear in different places depending on the operating system and environment. See [data dependencies] for more information on data files. | List of labels | optional | [] |
+| deps | List of Go libraries this package imports directly. These may be go_library
rules or compatible rules with the [GoLibrary] provider. | List of labels | optional | [] |
+| embed | List of Go libraries whose sources should be compiled together with this binary's sources. Labels listed here must name go_library
, go_proto_library
, or other compatible targets with the [GoLibrary] and [GoSource] providers. Embedded libraries must all have the same importpath
, which must match the importpath
for this go_binary
if one is specified. At most one embedded library may have cgo = True
, and the embedding binary may not also have cgo = True
. See [Embedding] for more information. | List of labels | optional | [] |
+| embedsrcs | The list of files that may be embedded into the compiled package using //go:embed
directives. All files must be in the same logical directory or a subdirectory as source files. All source files containing //go:embed
directives must be in the same logical directory. It's okay to mix static and generated source files and static and generated embeddable files. | List of labels | optional | [] |
+| gc_goopts | List of flags to add to the Go compilation command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] |
+| gc_linkopts | List of flags to add to the Go link command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] |
+| goarch | Forces a binary to be cross-compiled for a specific architecture. It's usually better to control this on the command line with --platforms
.pure
= off
.--platforms
.pure
= off
.on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:msan
. See [mode attributes], specifically [msan]. | String | optional | "auto" |
+| out | Sets the output filename for the generated executable. When set, go_binary
will write this file without mode-specific directory prefixes, without linkmode-specific prefixes like "lib", and without platform-specific suffixes like ".exe". Note that without a mode-specific directory prefix, the output file (but not its dependencies) will be invalidated in Bazel's cache when changing configurations. | String | optional | "" |
+| pure | Controls whether cgo source code and dependencies are compiled and linked, similar to setting CGO_ENABLED
. May be one of on
, off
, or auto
. If auto
, pure mode is enabled when no C/C++ toolchain is configured or when cross-compiling. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:pure
. See [mode attributes], specifically [pure]. | String | optional | "auto" |
+| race | Controls whether code is instrumented for race detection. May be one of on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:race
. See [mode attributes], specifically [race]. | String | optional | "auto" |
+| srcs | The list of Go source files that are compiled to create the package. Only .go
and .s
files are permitted, unless the cgo
attribute is set, in which case, .c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm
files are also permitted. Files may be filtered at build time using Go [build constraints]. | List of labels | optional | [] |
+| static | Controls whether a binary is statically linked. May be one of on
, off
, or auto
. Not available on all platforms or in all modes. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:static
. See [mode attributes], specifically [static]. | String | optional | "auto" |
+| x_defs | Map of defines to add to the go link command. See [Defines and stamping] for examples of how to use these. | Dictionary: String -> String | optional | {} |
@@ -331,30 +331,30 @@ This builds a set of tests that can be run with `bazel test`.cgo
= True
. | List of labels | optional | [] |
-| cgo | If True
, the package may contain [cgo] code, and srcs
may contain C, C++, Objective-C, and Objective-C++ files and non-Go assembly files. When cgo is enabled, these files will be compiled with the C/C++ toolchain and included in the package. Note that this attribute does not force cgo to be enabled. Cgo is enabled for non-cross-compiling builds when a C/C++ toolchain is configured. | Boolean | optional | False |
-| clinkopts | List of flags to add to the C link command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
-| copts | List of flags to add to the C compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
-| cppopts | List of flags to add to the C/C++ preprocessor command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
-| cxxopts | List of flags to add to the C++ compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
-| data | List of files needed by this rule at run-time. This may include data files needed or other programs that may be executed. The [bazel] package may be used to locate run files; they may appear in different places depending on the operating system and environment. See [data dependencies] for more information on data files. | List of labels | optional | [] |
-| deps | List of Go libraries this test imports directly. These may be go_library rules or compatible rules with the [GoLibrary] provider. | List of labels | optional | [] |
-| embed | List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name go_library
, go_proto_library
, or other compatible targets with the [GoLibrary] and [GoSource] providers. Embedded libraries must have the same importpath
as the embedding library. At most one embedded library may have cgo = True
, and the embedding library may not also have cgo = True
. See [Embedding] for more information. | List of labels | optional | [] |
-| embedsrcs | The list of files that may be embedded into the compiled package using //go:embed
directives. All files must be in the same logical directory or a subdirectory as source files. All source files containing //go:embed
directives must be in the same logical directory. It's okay to mix static and generated source files and static and generated embeddable files. | List of labels | optional | [] |
-| env | Environment variables to set for the test execution. The values (but not keys) are subject to [location expansion](https://docs.bazel.build/versions/main/skylark/macros.html) but not full [make variable expansion](https://docs.bazel.build/versions/main/be/make-variables.html). | Dictionary: String -> String | optional | {} |
-| gc_goopts | List of flags to add to the Go compilation command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] |
-| gc_linkopts | List of flags to add to the Go link command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] |
-| goarch | Forces a binary to be cross-compiled for a specific architecture. It's usually better to control this on the command line with --platforms
.pure
= off
.--platforms
.pure
= off
.on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:msan
. See [mode attributes], specifically [msan]. | String | optional | "auto" |
-| pure | Controls whether cgo source code and dependencies are compiled and linked, similar to setting CGO_ENABLED
. May be one of on
, off
, or auto
. If auto
, pure mode is enabled when no C/C++ toolchain is configured or when cross-compiling. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:pure
. See [mode attributes], specifically [pure]. | String | optional | "auto" |
-| race | Controls whether code is instrumented for race detection. May be one of on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:race
. See [mode attributes], specifically [race]. | String | optional | "auto" |
-| rundir | A directory to cd to before the test is run. This should be a path relative to the execution dir of the test.go test
so it is easy to write compatible tests..
makes the test behave the normal way for a bazel test..go
and .s
files are permitted, unless the cgo
attribute is set, in which case, .c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm
files are also permitted. Files may be filtered at build time using Go [build constraints]. | List of labels | optional | [] |
-| static | Controls whether a binary is statically linked. May be one of on
, off
, or auto
. Not available on all platforms or in all modes. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:static
. See [mode attributes], specifically [static]. | String | optional | "auto" |
-| x_defs | Map of defines to add to the go link command. See [Defines and stamping] for examples of how to use these. | Dictionary: String -> String | optional | {} |
+| cdeps | The list of other libraries that the c code depends on. This can be anything that would be allowed in [cc_library deps] Only valid if cgo
= True
. | List of labels | optional | [] |
+| cgo | If True
, the package may contain [cgo] code, and srcs
may contain C, C++, Objective-C, and Objective-C++ files and non-Go assembly files. When cgo is enabled, these files will be compiled with the C/C++ toolchain and included in the package. Note that this attribute does not force cgo to be enabled. Cgo is enabled for non-cross-compiling builds when a C/C++ toolchain is configured. | Boolean | optional | False |
+| clinkopts | List of flags to add to the C link command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
+| copts | List of flags to add to the C compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
+| cppopts | List of flags to add to the C/C++ preprocessor command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
+| cxxopts | List of flags to add to the C++ compilation command. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. Only valid if cgo
= True
. | List of strings | optional | [] |
+| data | List of files needed by this rule at run-time. This may include data files needed or other programs that may be executed. The [bazel] package may be used to locate run files; they may appear in different places depending on the operating system and environment. See [data dependencies] for more information on data files. | List of labels | optional | [] |
+| deps | List of Go libraries this test imports directly. These may be go_library rules or compatible rules with the [GoLibrary] provider. | List of labels | optional | [] |
+| embed | List of Go libraries whose sources should be compiled together with this package's sources. Labels listed here must name go_library
, go_proto_library
, or other compatible targets with the [GoLibrary] and [GoSource] providers. Embedded libraries must have the same importpath
as the embedding library. At most one embedded library may have cgo = True
, and the embedding library may not also have cgo = True
. See [Embedding] for more information. | List of labels | optional | [] |
+| embedsrcs | The list of files that may be embedded into the compiled package using //go:embed
directives. All files must be in the same logical directory or a subdirectory as source files. All source files containing //go:embed
directives must be in the same logical directory. It's okay to mix static and generated source files and static and generated embeddable files. | List of labels | optional | [] |
+| env | Environment variables to set for the test execution. The values (but not keys) are subject to [location expansion](https://docs.bazel.build/versions/main/skylark/macros.html) but not full [make variable expansion](https://docs.bazel.build/versions/main/be/make-variables.html). | Dictionary: String -> String | optional | {} |
+| gc_goopts | List of flags to add to the Go compilation command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] |
+| gc_linkopts | List of flags to add to the Go link command when using the gc compiler. Subject to ["Make variable"] substitution and [Bourne shell tokenization]. | List of strings | optional | [] |
+| goarch | Forces a binary to be cross-compiled for a specific architecture. It's usually better to control this on the command line with --platforms
.pure
= off
.--platforms
.pure
= off
.on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:msan
. See [mode attributes], specifically [msan]. | String | optional | "auto" |
+| pure | Controls whether cgo source code and dependencies are compiled and linked, similar to setting CGO_ENABLED
. May be one of on
, off
, or auto
. If auto
, pure mode is enabled when no C/C++ toolchain is configured or when cross-compiling. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:pure
. See [mode attributes], specifically [pure]. | String | optional | "auto" |
+| race | Controls whether code is instrumented for race detection. May be one of on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:race
. See [mode attributes], specifically [race]. | String | optional | "auto" |
+| rundir | A directory to cd to before the test is run. This should be a path relative to the execution dir of the test.go test
so it is easy to write compatible tests..
makes the test behave the normal way for a bazel test..go
and .s
files are permitted, unless the cgo
attribute is set, in which case, .c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm
files are also permitted. Files may be filtered at build time using Go [build constraints]. | List of labels | optional | [] |
+| static | Controls whether a binary is statically linked. May be one of on
, off
, or auto
. Not available on all platforms or in all modes. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:static
. See [mode attributes], specifically [static]. | String | optional | "auto" |
+| x_defs | Map of defines to add to the go link command. See [Defines and stamping] for examples of how to use these. | Dictionary: String -> String | optional | {} |
diff --git a/go/private/rules/BUILD.bazel b/go/private/rules/BUILD.bazel
index 21063d701d..b3ce9b8709 100644
--- a/go/private/rules/BUILD.bazel
+++ b/go/private/rules/BUILD.bazel
@@ -28,6 +28,7 @@ bzl_library(
"//go/private:mode",
"//go/private:providers",
"//go/private/rules:transition",
+ "@bazel_skylib//lib:dicts",
],
)
@@ -117,6 +118,7 @@ bzl_library(
"//go/private:providers",
"//go/private/rules:binary",
"//go/private/rules:transition",
+ "@bazel_skylib//lib:dicts",
"@bazel_skylib//lib:structs",
],
)
@@ -133,6 +135,7 @@ bzl_library(
"//go/private:mode",
"//go/private:platforms",
"//go/private:providers",
+ "//go/private/skylib/lib:dicts",
],
)
diff --git a/go/private/rules/binary.bzl b/go/private/rules/binary.bzl
index 78e74e26af..124d19abf6 100644
--- a/go/private/rules/binary.bzl
+++ b/go/private/rules/binary.bzl
@@ -29,7 +29,10 @@ load(
)
load(
"//go/private/rules:transition.bzl",
- "go_transition_rule",
+ "ForwardingPastTransitionProvider",
+ "forward_through_transition_impl",
+ "go_transition",
+ "transition_attrs",
)
load(
"//go/private:mode.bzl",
@@ -43,6 +46,10 @@ load(
"//go/private:rpath.bzl",
"rpath",
)
+load(
+ "@bazel_skylib//lib:dicts.bzl",
+ "dicts",
+)
_EMPTY_DEPSET = depset([])
@@ -110,7 +117,7 @@ def _go_binary_impl(ctx):
executable = executable,
)
- providers = [
+ providers_to_forward = [
library,
source,
archive,
@@ -118,11 +125,6 @@ def _go_binary_impl(ctx):
cgo_exports = archive.cgo_exports,
compilation_outputs = [archive.data.file],
),
- DefaultInfo(
- files = depset([executable]),
- runfiles = runfiles,
- executable = executable,
- ),
]
# If the binary's linkmode is c-archive or c-shared, expose CcInfo
@@ -151,214 +153,224 @@ def _go_binary_impl(ctx):
ccinfo = cc_common.merge_cc_infos(
cc_infos = [ccinfo] + [d[CcInfo] for d in source.cdeps],
)
- providers.append(ccinfo)
+ providers_to_forward.append(ccinfo)
- return providers
-
-_go_binary_kwargs = {
- "implementation": _go_binary_impl,
- "attrs": {
- "srcs": attr.label_list(
- allow_files = go_exts + asm_exts + cgo_exts,
- doc = """The list of Go source files that are compiled to create the package.
- Only `.go` and `.s` files are permitted, unless the `cgo`
- attribute is set, in which case,
- `.c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm`
- files are also permitted. Files may be filtered at build time
- using Go [build constraints].
- """,
- ),
- "data": attr.label_list(
- allow_files = True,
- doc = """List of files needed by this rule at run-time. This may include data files
- needed or other programs that may be executed. The [bazel] package may be
- used to locate run files; they may appear in different places depending on the
- operating system and environment. See [data dependencies] for more
- information on data files.
- """,
- ),
- "deps": attr.label_list(
- providers = [GoLibrary],
- doc = """List of Go libraries this package imports directly.
- These may be `go_library` rules or compatible rules with the [GoLibrary] provider.
- """,
- ),
- "embed": attr.label_list(
- providers = [GoLibrary],
- doc = """List of Go libraries whose sources should be compiled together with this
- binary's sources. Labels listed here must name `go_library`,
- `go_proto_library`, or other compatible targets with the [GoLibrary] and
- [GoSource] providers. Embedded libraries must all have the same `importpath`,
- which must match the `importpath` for this `go_binary` if one is
- specified. At most one embedded library may have `cgo = True`, and the
- embedding binary may not also have `cgo = True`. See [Embedding] for
- more information.
- """,
- ),
- "embedsrcs": attr.label_list(
- allow_files = True,
- doc = """The list of files that may be embedded into the compiled package using
- `//go:embed` directives. All files must be in the same logical directory
- or a subdirectory as source files. All source files containing `//go:embed`
- directives must be in the same logical directory. It's okay to mix static and
- generated source files and static and generated embeddable files.
- """,
- ),
- "importpath": attr.string(
- doc = """The import path of this binary. Binaries can't actually be imported, but this
- may be used by [go_path] and other tools to report the location of source
- files. This may be inferred from embedded libraries.
- """,
- ),
- "gc_goopts": attr.string_list(
- doc = """List of flags to add to the Go compilation command when using the gc compiler.
- Subject to ["Make variable"] substitution and [Bourne shell tokenization].
- """,
- ),
- "gc_linkopts": attr.string_list(
- doc = """List of flags to add to the Go link command when using the gc compiler.
- Subject to ["Make variable"] substitution and [Bourne shell tokenization].
- """,
- ),
- "x_defs": attr.string_dict(
- doc = """Map of defines to add to the go link command.
- See [Defines and stamping] for examples of how to use these.
- """,
- ),
- "basename": attr.string(
- doc = """The basename of this binary. The binary
- basename may also be platform-dependent: on Windows, we add an .exe extension.
- """,
- ),
- "out": attr.string(
- doc = """Sets the output filename for the generated executable. When set, `go_binary`
- will write this file without mode-specific directory prefixes, without
- linkmode-specific prefixes like "lib", and without platform-specific suffixes
- like ".exe". Note that without a mode-specific directory prefix, the
- output file (but not its dependencies) will be invalidated in Bazel's cache
- when changing configurations.
- """,
- ),
- "cgo": attr.bool(
- doc = """If `True`, the package may contain [cgo] code, and `srcs` may contain
- C, C++, Objective-C, and Objective-C++ files and non-Go assembly files.
- When cgo is enabled, these files will be compiled with the C/C++ toolchain
- and included in the package. Note that this attribute does not force cgo
- to be enabled. Cgo is enabled for non-cross-compiling builds when a C/C++
- toolchain is configured.
- """,
- ),
- "cdeps": attr.label_list(
- doc = """The list of other libraries that the c code depends on.
- This can be anything that would be allowed in [cc_library deps]
- Only valid if `cgo` = `True`.
- """,
- ),
- "cppopts": attr.string_list(
- doc = """List of flags to add to the C/C++ preprocessor command.
- Subject to ["Make variable"] substitution and [Bourne shell tokenization].
- Only valid if `cgo` = `True`.
- """,
- ),
- "copts": attr.string_list(
- doc = """List of flags to add to the C compilation command.
- Subject to ["Make variable"] substitution and [Bourne shell tokenization].
- Only valid if `cgo` = `True`.
- """,
- ),
- "cxxopts": attr.string_list(
- doc = """List of flags to add to the C++ compilation command.
- Subject to ["Make variable"] substitution and [Bourne shell tokenization].
- Only valid if `cgo` = `True`.
- """,
- ),
- "clinkopts": attr.string_list(
- doc = """List of flags to add to the C link command.
- Subject to ["Make variable"] substitution and [Bourne shell tokenization].
- Only valid if `cgo` = `True`.
- """,
- ),
- "pure": attr.string(
- default = "auto",
- doc = """Controls whether cgo source code and dependencies are compiled and linked,
- similar to setting `CGO_ENABLED`. May be one of `on`, `off`,
- or `auto`. If `auto`, pure mode is enabled when no C/C++
- toolchain is configured or when cross-compiling. It's usually better to
- control this on the command line with
- `--@io_bazel_rules_go//go/config:pure`. See [mode attributes], specifically
- [pure].
- """,
- ),
- "static": attr.string(
- default = "auto",
- doc = """Controls whether a binary is statically linked. May be one of `on`,
- `off`, or `auto`. Not available on all platforms or in all
- modes. It's usually better to control this on the command line with
- `--@io_bazel_rules_go//go/config:static`. See [mode attributes],
- specifically [static].
- """,
- ),
- "race": attr.string(
- default = "auto",
- doc = """Controls whether code is instrumented for race detection. May be one of
- `on`, `off`, or `auto`. Not available when cgo is
- disabled. In most cases, it's better to control this on the command line with
- `--@io_bazel_rules_go//go/config:race`. See [mode attributes], specifically
- [race].
- """,
- ),
- "msan": attr.string(
- default = "auto",
- doc = """Controls whether code is instrumented for memory sanitization. May be one of
- `on`, `off`, or `auto`. Not available when cgo is
- disabled. In most cases, it's better to control this on the command line with
- `--@io_bazel_rules_go//go/config:msan`. See [mode attributes], specifically
- [msan].
- """,
- ),
- "gotags": attr.string_list(
- doc = """Enables a list of build tags when evaluating [build constraints]. Useful for
- conditional compilation.
- """,
+ forwarding_provider = ForwardingPastTransitionProvider(executable = executable, runfiles = runfiles, providers_to_forward = providers_to_forward)
+ return providers_to_forward + [
+ forwarding_provider,
+ DefaultInfo(
+ files = depset([executable]),
+ runfiles = runfiles,
+ executable = executable,
),
- "goos": attr.string(
- default = "auto",
- doc = """Forces a binary to be cross-compiled for a specific operating system. It's
- usually better to control this on the command line with `--platforms`.
+ ]
- This disables cgo by default, since a cross-compiling C/C++ toolchain is
- rarely available. To force cgo, set `pure` = `off`.
+go_binary_attrs = {
+ "srcs": attr.label_list(
+ allow_files = go_exts + asm_exts + cgo_exts,
+ doc = """The list of Go source files that are compiled to create the package.
+ Only `.go` and `.s` files are permitted, unless the `cgo`
+ attribute is set, in which case,
+ `.c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm`
+ files are also permitted. Files may be filtered at build time
+ using Go [build constraints].
+ """,
+ ),
+ "data": attr.label_list(
+ allow_files = True,
+ doc = """List of files needed by this rule at run-time. This may include data files
+ needed or other programs that may be executed. The [bazel] package may be
+ used to locate run files; they may appear in different places depending on the
+ operating system and environment. See [data dependencies] for more
+ information on data files.
+ """,
+ ),
+ "deps": attr.label_list(
+ providers = [GoLibrary],
+ doc = """List of Go libraries this package imports directly.
+ These may be `go_library` rules or compatible rules with the [GoLibrary] provider.
+ """,
+ ),
+ "embed": attr.label_list(
+ providers = [GoLibrary],
+ doc = """List of Go libraries whose sources should be compiled together with this
+ binary's sources. Labels listed here must name `go_library`,
+ `go_proto_library`, or other compatible targets with the [GoLibrary] and
+ [GoSource] providers. Embedded libraries must all have the same `importpath`,
+ which must match the `importpath` for this `go_binary` if one is
+ specified. At most one embedded library may have `cgo = True`, and the
+ embedding binary may not also have `cgo = True`. See [Embedding] for
+ more information.
+ """,
+ ),
+ "embedsrcs": attr.label_list(
+ allow_files = True,
+ doc = """The list of files that may be embedded into the compiled package using
+ `//go:embed` directives. All files must be in the same logical directory
+ or a subdirectory as source files. All source files containing `//go:embed`
+ directives must be in the same logical directory. It's okay to mix static and
+ generated source files and static and generated embeddable files.
+ """,
+ ),
+ "importpath": attr.string(
+ doc = """The import path of this binary. Binaries can't actually be imported, but this
+ may be used by [go_path] and other tools to report the location of source
+ files. This may be inferred from embedded libraries.
+ """,
+ ),
+ "gc_goopts": attr.string_list(
+ doc = """List of flags to add to the Go compilation command when using the gc compiler.
+ Subject to ["Make variable"] substitution and [Bourne shell tokenization].
+ """,
+ ),
+ "gc_linkopts": attr.string_list(
+ doc = """List of flags to add to the Go link command when using the gc compiler.
+ Subject to ["Make variable"] substitution and [Bourne shell tokenization].
+ """,
+ ),
+ "x_defs": attr.string_dict(
+ doc = """Map of defines to add to the go link command.
+ See [Defines and stamping] for examples of how to use these.
+ """,
+ ),
+ "basename": attr.string(
+ doc = """The basename of this binary. The binary
+ basename may also be platform-dependent: on Windows, we add an .exe extension.
+ """,
+ ),
+ "out": attr.string(
+ doc = """Sets the output filename for the generated executable. When set, `go_binary`
+ will write this file without mode-specific directory prefixes, without
+ linkmode-specific prefixes like "lib", and without platform-specific suffixes
+ like ".exe". Note that without a mode-specific directory prefix, the
+ output file (but not its dependencies) will be invalidated in Bazel's cache
+ when changing configurations.
+ """,
+ ),
+ "cgo": attr.bool(
+ doc = """If `True`, the package may contain [cgo] code, and `srcs` may contain
+ C, C++, Objective-C, and Objective-C++ files and non-Go assembly files.
+ When cgo is enabled, these files will be compiled with the C/C++ toolchain
+ and included in the package. Note that this attribute does not force cgo
+ to be enabled. Cgo is enabled for non-cross-compiling builds when a C/C++
+ toolchain is configured.
+ """,
+ ),
+ "cdeps": attr.label_list(
+ doc = """The list of other libraries that the c code depends on.
+ This can be anything that would be allowed in [cc_library deps]
+ Only valid if `cgo` = `True`.
+ """,
+ ),
+ "cppopts": attr.string_list(
+ doc = """List of flags to add to the C/C++ preprocessor command.
+ Subject to ["Make variable"] substitution and [Bourne shell tokenization].
+ Only valid if `cgo` = `True`.
+ """,
+ ),
+ "copts": attr.string_list(
+ doc = """List of flags to add to the C compilation command.
+ Subject to ["Make variable"] substitution and [Bourne shell tokenization].
+ Only valid if `cgo` = `True`.
+ """,
+ ),
+ "cxxopts": attr.string_list(
+ doc = """List of flags to add to the C++ compilation command.
+ Subject to ["Make variable"] substitution and [Bourne shell tokenization].
+ Only valid if `cgo` = `True`.
+ """,
+ ),
+ "clinkopts": attr.string_list(
+ doc = """List of flags to add to the C link command.
+ Subject to ["Make variable"] substitution and [Bourne shell tokenization].
+ Only valid if `cgo` = `True`.
+ """,
+ ),
+ "pure": attr.string(
+ default = "auto",
+ doc = """Controls whether cgo source code and dependencies are compiled and linked,
+ similar to setting `CGO_ENABLED`. May be one of `on`, `off`,
+ or `auto`. If `auto`, pure mode is enabled when no C/C++
+ toolchain is configured or when cross-compiling. It's usually better to
+ control this on the command line with
+ `--@io_bazel_rules_go//go/config:pure`. See [mode attributes], specifically
+ [pure].
+ """,
+ ),
+ "static": attr.string(
+ default = "auto",
+ doc = """Controls whether a binary is statically linked. May be one of `on`,
+ `off`, or `auto`. Not available on all platforms or in all
+ modes. It's usually better to control this on the command line with
+ `--@io_bazel_rules_go//go/config:static`. See [mode attributes],
+ specifically [static].
+ """,
+ ),
+ "race": attr.string(
+ default = "auto",
+ doc = """Controls whether code is instrumented for race detection. May be one of
+ `on`, `off`, or `auto`. Not available when cgo is
+ disabled. In most cases, it's better to control this on the command line with
+ `--@io_bazel_rules_go//go/config:race`. See [mode attributes], specifically
+ [race].
+ """,
+ ),
+ "msan": attr.string(
+ default = "auto",
+ doc = """Controls whether code is instrumented for memory sanitization. May be one of
+ `on`, `off`, or `auto`. Not available when cgo is
+ disabled. In most cases, it's better to control this on the command line with
+ `--@io_bazel_rules_go//go/config:msan`. See [mode attributes], specifically
+ [msan].
+ """,
+ ),
+ "gotags": attr.string_list(
+ doc = """Enables a list of build tags when evaluating [build constraints]. Useful for
+ conditional compilation.
+ """,
+ ),
+ "goos": attr.string(
+ default = "auto",
+ doc = """Forces a binary to be cross-compiled for a specific operating system. It's
+ usually better to control this on the command line with `--platforms`.
- See [Cross compilation] for more information.
- """,
- ),
- "goarch": attr.string(
- default = "auto",
- doc = """Forces a binary to be cross-compiled for a specific architecture. It's usually
- better to control this on the command line with `--platforms`.
+ This disables cgo by default, since a cross-compiling C/C++ toolchain is
+ rarely available. To force cgo, set `pure` = `off`.
- This disables cgo by default, since a cross-compiling C/C++ toolchain is
- rarely available. To force cgo, set `pure` = `off`.
+ See [Cross compilation] for more information.
+ """,
+ ),
+ "goarch": attr.string(
+ default = "auto",
+ doc = """Forces a binary to be cross-compiled for a specific architecture. It's usually
+ better to control this on the command line with `--platforms`.
- See [Cross compilation] for more information.
- """,
- ),
- "linkmode": attr.string(
- default = LINKMODE_NORMAL,
- doc = """Determines how the binary should be built and linked. This accepts some of
- the same values as `go build -buildmode` and works the same way.
-