Closed
Description
go_prefix
is used to translate Bazel labels (for example, //foo/bar:go_default_library
) to Go import paths (example.com/repo/foo/bar
) and vice versa. There are a number of problems with go_prefix
, and we'd like to stop using it and eventually stop supporting it.
- Go rules implicitly depend on
//:go_prefix
. This means there must be ago_prefix
defined in the repository root package, even if there are no other Go rules in that package. - This does not work well for Go subtrees that are part of larger repositories. The actual import path of libraries within the repository may not correspond to
<go_prefix>/<subtree>/<library>
. - This does not work for vendoring. We have special cases for vendoring in several places.
- It's confusing and unexpected that
go_prefix
is required forgo_binary
. For binary-only repositories, it shouldn't be required at all.
We would like to move away from using go_prefix
. go_library
already has an importpath
attribute, which allows the import path to be set explicitly. This is currently optional, but it may be required in the future.
We will deprecate go_prefix
slowly in several steps to avoid breaking people.
- Gazelle will add
importpath
attributes to new and existinggo_library
rules. These import paths will match the import paths that already would be computed, based on the currentgo_prefix
and the relative path within the repository. go_prefix
will no longer be mandatory forgo_library
rules that specifyimportpath
. We should be able to accomplish this with computed dependencies.- Gazelle will no longer generate
go_prefix
rules. When Gazelle is run with the "fix" command, it will remove existinggo_prefix
rules. - At some point in the distant future, we may remove
go_prefix
altogether (this might not actually happen, but it's the plan of record).
breakds, inas9, emcfarlane and ashi009