Breaking changes
In order to reduce CPU and memory usage in the analysis phase and to improve the maintainability of the codebase, this release contains a number of breaking changes.
As the bulk of these changes are to the Go context API, users of the go_*
rules should not be affected (with a very minor exception below).
The maintainers would like to give a special thanks to @dzbarsky for numerous contributions to this release!
Changes to rules
- Support for inferring an importpath for libraries named
go_default_library
has been removed. Modern versions of Gazelle do not generate this target name, please ensure you are up to date. (c8a7ebca3)
Changes to the Go context API and behavior
-
Converted SDK files to depsets (
go.sdk.tools
,go.sdk.headers
,go.sdk.libs
,go.sdk.srcs
). To migrate, either callto_list()
on those properties or, preferably, use them asdepset
s in your downstream actions. To remain compatible with older versions, consider a conditional conversion such asdepset_or_list if type(depset_or_list) == type([]) else depset_or_list.to_list()
(3994841a) -
go.sdk_files
has been removed and can be replaced withdepset(direct = [go.sdk.go], transitive = [go.sdk.srcs, go.sdk.headers, go.sdk.libs, go.sdk.tools])
(which is adepset
). Wherever possible, try to use only the subset of those files that's actually needed. -
GoSource
andGoLibrary
providers have been merged and renamed toGoInfo
. The previous names are now aliases, but can result in errors about duplicate providers when both are returned from the same rule.go.new_library
andgo.library_to_source
are now deprecated. To migrate, usego.new_go_info
. To remain compatible with older versions that require both providers, consider checking whetherGoSource != GoLibrary
. (564f8204) -
Some fields on the Go context object are marked deprecated.
go_context
will still add them to the context object, unless it is invoked withinclude_deprecated_properties = False
. This default will be flipped in the future and eventually this codepath will be removed. (aa96a1174) You can migrate as follows:go.root
->go.env["GOROOT"]
go.go
->go.sdk.go
go.sdk_root
->go.sdk.root_file
go.sdk_tools
->go.sdk.tools
go.package_list
->go.sdk.package_list
go.tags
->go.mode.tags
go.stamp
->go.mode.stamp
go.cover_format
->go.mode.cover_format
go.pgoprofile
->go.mode.pgoprofile
-
Removed
get_nogo
from the Go context object (0f88f8c8) -
Removed
exe_extension
andshared_extension
from the Go context object. (c419453a) -
Removed
GoSource.cc_info
. If you need to access theCcInfo
from a Go target, you will need to apply the_go_cc_aspect
fromgo/private/rules/binary.bzl
. Please let us know if it's needed and we can move it to public API. (a01ba7c72) -
go_binary
andgo_test
targets no longer exposeGoInfo
,GoSource
orGoLibrary
providers. If you need a dedicated provider to attach an aspect to, please let us know. (2d2266) -
The Go context's
mode
property is now aGoConfigInfo
provider instead of a bare struct.go.mode.link
has been renamed togo.mode.linkmode
(5933f872) -
If you are relying on
go_context
to read an_stdlib
attribute from yourattr
s, please ensure the attribute is not transitioned, as it will no longer handle a list value. (9214edcd126) -
go_context
now accepts keyword arguments for the following fields:go_context_data
,importpath
,importmap
,embed
,importpath_aliases
. If these properties are omitted, the function will continue to fall back to reading them fromattr
. Consider passing these explicitly to improve code clarity and analysis phase performance. (6749a3819, f3029e2a8)
Changes to providers
GoSource
-
Removed
cgo_deps
, usecdeps
instead (56d415d) -
Removed
orig_srcs
(520bee50) -
Removed
cgo_exports
(86c3f3ae97) -
Converted
cover
to adepset
(692d008c96) -
deps
is now a list ofGoArchive
s instead ofTarget
s (a32f3e1)
GoArchive
- Removed
mode
, usesource.mode
instead (bfd99a663)
GoArchiveData
- Removed
data_files
, use withrunfiles
instead, which is arunfiles
object (60f55c91ce)
CgoContextInfo
- Converted
cc_toolchain_files
to adepset
(3994841)
WORKSPACE
code
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "1101d7e81a6e7f9cee94dd947bed705144bf339257fbec1d73d620df87e58885",
urls = [
"https://mirror.bazel.build/github.com/bazel-contrib/rules_go/releases/download/v0.51.0-rc2/rules_go-v0.51.0-rc2.zip",
"https://github.com/bazel-contrib/rules_go/releases/download/v0.51.0-rc2/rules_go-v0.51.0-rc2.zip",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains(version = "1.23.3")
What's Changed
- Use rules_shell's sh_binary and sh_test by @ted-xie in #4182
- prepare rules_go release 0.51.0-rc2 by @fmeum in #4183
New Contributors
Full Changelog: v0.51.0-rc1...v0.51.0-rc2