The providers are the outputs of the rules, you generaly get them by having a dependency on a rule, and then asking for a provider of a specific type.
The Go providers are designed primarily for the efficiency of the Go rules, the information they share is mostly there because it is required for the core rules to work.
All the providers are designed to hold only immutable data. This is partly because its a cleaner design choice to be able to assume a provider will never change, but also because only immutable objects are allowed to be stored in a depset, and it's really useful to have depsets of providers. Specifically the direct and transitive fields on GoLibrary only work because it is immutable.
This is the provider exposed by the go_library rule, or anything that wants to behave like one. It provides all the information requried to use the library as a dependency, for other libraries, binaries or tests.
Name | Type |
importpath | string |
The import path for this library. | |
direct | depset(GoLibrary) |
The direct depencancies of the library. | |
transitive | depset(GoLibrary) |
The full transitive set of Go libraries depended on. | |
srcs | depset(File) |
The original sources used to build the library. | |
cover_vars | tuple(String) |
The cover variables added to this library. | |
cgo_deps | depset(cc_library) |
The direct cgo dependencies of this library. This has the same constraints as things that can appear in the deps of a cc_library. | |
runfiles | runfiles |
The files needed to run anything that includes this library. |
GoSourceList is a provider designed to be used as the output of anything that provides Go code, and an input to anything that compiles Go code. It combines the source with dependencies that source will require.
There are two main uses for this.
- Recompiling a library with additional sources. go_library returns a GoSourceList provider with the transformed sources and deps that it was consuming. go_test uses this to recompile the library with additional test files, to build the test version of the library. You can use the same feature to recompile a proto library with additional sources that were not generated by the proto compiler.
- Providing the dependencies for generated code.
If you wanted to use flatbuffers in your code, and you had a custom rule that ran the
flatbuffers compiler to generate the serialization functions, you might hit the issue that
the only thing that knows you depend on
github.com/google/flatbuffers/go
is the generated code. You can instead have the generator return a GoSourceList provider instead of just the generated files, allowing you to tie the generated files to the additional dependencies they add to any package trying to compile them.
Name | Type |
entries | list of GoSource |
The full list of GoSource entries that this source set is composed of. |
GoSource represents a single entry in a GoSourceList source provider.
Name | Type |
srcs | depset(File) |
The original sources for this library before transformations like cgo and coverage. | |
deps | depset(GoLibrary) |
The direct dependencies needed by the srcs. | |
gc_goopts | tuple(string) |
Go compilation options that should be used when compiling these sources. In general these will be used for all sources of any library this provider is embedded into. | |
cover_vars | string |
The cover variables used in these sources. | |
runfiles | Runfiles |
The set of files needed by code in these sources at runtime. | |
cgo_deps | depset(cc_library) |
The direct cgo dependencies of this library. | |
cgo_exports | depset(File) |
The exposed cc headers for these sources. | |
cgo_archive | File |
The cgo archive to merge into a go archive for these sources. |
GoArchive is a provider that exposes a compiled library.
Name | Type |
lib | compiled archive file |
The archive file representing the library compiled in a specific mode ready for linking into binaries. | |
searchpath | string |
The search path entry under which the lib would be found. | |
mode | Mode |
The mode the library was compiled in. |