Skip to content

proposal: go/build: export an API to identify which tags are implied by a given GOOS #54738

@bcmills

Description

@bcmills

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions