Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/build: should export lists of all possible GOOS and GOARCH values #21544

Closed
willfaught opened this issue Aug 21, 2017 · 8 comments
Closed
Milestone

Comments

@willfaught
Copy link
Contributor

willfaught commented Aug 21, 2017

go/build (or one of the go/ sub-packages, at least) should export a list of all the possible build tags. This is useful when writing a tool that needs to strip a file name of all the build tags. Right now I have a list like this that I've cobbled together, but I don't know for sure that it's complete, and even if it is now, it probably won't remain so:

var suffixes = []string{
	"_386",
	"_amd64",
	"_amd64p32",
	"_android",
	"_arm",
	"_arm64",
	"_arm64be",
	"_armbe",
	"_darwin",
	"_dragonfly",
	"_freebsd",
	"_linux",
	"_mips",
	"_mips64",
	"_mips64le",
	"_mips64p32",
	"_mips64p32le",
	"_mipsle",
	"_nacl",
	"_netbsd",
	"_openbsd",
	"_plan9",
	"_ppc",
	"_ppc64",
	"_ppc64le",
	"_s390",
	"_s390x",
	"_solaris",
	"_sparc",
	"_sparc64",
	"_test",
	"_windows",
	"_zos",
}
@willfaught willfaught changed the title go/build: should export list of possible hardware and operating systems go/build: should export list of possible build tags Aug 21, 2017
@mvdan
Copy link
Member

mvdan commented Aug 21, 2017

Please note that these are not all the possible build tags. Anyone can set up their own custom build tags.

What you seem to be listing here is all the (current) possible values of GOOS and GOARCH, which you can also use as build tags. Is that what you'd be interested in?

@mvdan
Copy link
Member

mvdan commented Aug 21, 2017

Also note that if you meant all the build tags recognized by the Go toolchain, that list is not complete either - there's also unix, test, fuzz among others.

@willfaught
Copy link
Contributor Author

willfaught commented Aug 21, 2017 via email

@willfaught
Copy link
Contributor Author

willfaught commented Aug 21, 2017 via email

@mvdan
Copy link
Member

mvdan commented Aug 21, 2017

https://github.com/dvyukov/go-fuzz (this one isn't part of the Go toolchain at the moment, but it may be in the future)

@mvdan
Copy link
Member

mvdan commented Aug 21, 2017

After a quick search, I found #12270, but that's not in any Go package and it's all the possible combinations, not the values separately.

@mvdan mvdan changed the title go/build: should export list of possible build tags go/build: should export lists of all possible GOOS and GOARCH values Aug 21, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Aug 25, 2017
@rsc
Copy link
Contributor

rsc commented Nov 22, 2017

I don't really think this is well-formed. Any such list is going to be out-of-date / dependent on a very specific Go version. If you want to strip a file name of _foo suffixes, I would just remove any underscores anywhere.

@rsc rsc closed this as completed Nov 22, 2017
@willfaught
Copy link
Contributor Author

I don't really think this is well-formed. Any such list is going to be out-of-date / dependent on a very specific Go version.

I don't understand why a maintenance concern makes this malformed.

Perhaps it's possible to generate a go/build declaration from lists of OS and arch build tags defined elsewhere?

If you want to strip a file name of _foo suffixes, I would just remove any underscores anywhere.

From go doc go/build:

If a file's name, after stripping the extension and a possible _test suffix, matches any of the following patterns:

*_GOOS
*_GOARCH
*_GOOS_GOARCH

(example: source_windows_amd64.go) where GOOS and GOARCH represent any known operating system and architecture values respectively, then the file is considered to have an implicit build constraint requiring those terms (in addition to any explicit constraints in the file).

If I understand correctly, then foo_bar.go is a valid Go file name with no build tags in the name, and foo_bar_windows_amd64.go is a valid Go file name with OS and arch build tags in the name. If by "remove any underscores anywhere" you mean "strip a file name of _foo suffixes", then "_bar" would be stripped as well, which is incorrect.

@golang golang locked and limited conversation to collaborators Nov 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants