For #51572 we added a unix build constraint that implicitly applies to all Unix-like GOOS values.
That is in addition to some GOOS chains that already existed:
android implies linux
ios implies darwin
illumos implies solaris
The number of such chains that already exist suggests that we may end up adding further chains in the future, and if we add new GOOS values in the future they may also imply unix, linux, or some other constraint.
Currently we have duplicated the logic for these implicit chains of constraints in at least three places: go/build, cmd/go, and cmd/dist. That suggests to me that authors of Go tools in general are likely to also need this information.
I propose that we add one or more functions to either the go/build package or the go/build/constraints package to resolve these chains. The simplest API I can think of for this would be something like:
// OSImpliedTags reports additional build tags that are implicitly satisfied
// by the given GOOS value when evaluating build constraints.
//
// The returned slice may be nil, and does not include the GOOS value itself.
func ImpliedOSTags(goos string) []string {
var tags []string
switch goos {
case "android":
tags = append(tags, "linux")
case "ios":
tags = append(tags, "darwin")
case "illumos":
tags = append(tags, "solaris")
}
if unixOS[goos] {
tags = append(tags, "unix")
}
return tags
}
For #51572 we added a
unix
build constraint that implicitly applies to all Unix-likeGOOS
values.That is in addition to some
GOOS
chains that already existed:android
implieslinux
ios
impliesdarwin
illumos
impliessolaris
The number of such chains that already exist suggests that we may end up adding further chains in the future, and if we add new
GOOS
values in the future they may also implyunix
,linux
, or some other constraint.Currently we have duplicated the logic for these implicit chains of constraints in at least three places:
go/build
,cmd/go
, andcmd/dist
. That suggests to me that authors of Go tools in general are likely to also need this information.I propose that we add one or more functions to either the
go/build
package or thego/build/constraints
package to resolve these chains. The simplest API I can think of for this would be something like: