所有可能的GOOS值是什么?

huangapple go评论100阅读模式
英文:

All possible GOOS value?

问题

如果我理解正确,GOOS是在编译源代码时确定的。

为了更好地支持多个操作系统,我对GOOS可能是什么感兴趣。

当然,由于Go是开源的,可能存在无限的可能性。所以我真正想要的是一个“常见列表”。

已知的值有:

  • windows
  • linux
  • darwin 或者 freebsd 或者 unix?我知道至少其中一个必须存在。
英文:

If I get it right, GOOS is determined when compile the source code.

To better support multiple OS, I'm interested in what GOOS could be.

Of course, there might be infinite possibilities of it, since Go is opensourced. So what I really want is a "common list".

Known values are:

  • windows
  • linux
  • darwin or freebsd or unix? I know that at least one of them must exist.

答案1

得分: 93

请注意,这些值在以下位置定义:

从Go 1.5(2015年第三季度)开始,GOARCH将变得更加完整。请参见Minux Ma (minux)提交1eebb91

> ## go/build: 为所有常见架构保留GOARCH
>
> 每当我们引入新的GOARCH时,旧版本的Go将无法识别它们,这对我们的用户和我们自己都会造成麻烦(我们需要添加不必要的构建标签)。
>
> 到目前为止,Go 1.5已经引入了三个新的GOARCH:arm64 ppc64 ppc64le,我们可以花时间为Go可能在未来支持的所有常见架构引入GOARCH,以避免这个问题。

const goosList = "android darwin dragonfly freebsd linux nacl \ 
  netbsd openbsd plan9 solaris windows "

const goarchList = "386 amd64 amd64p32 arm arm64 ppc64 ppc64le \
   mips mipsle mips64 mips64le mips64p32 mips64p32le \ # (new)
   ppc s390 s390x sparc sparc64 " # (new)

该列表仍在Change 9644中进行审查,其中包含以下评论:

> 我不会费心去关注Itanium。它基本上是一种已经过时的架构。
此外,编写Itanium编译器非常困难,我真的无法想象除了出于热爱之外还会有其他原因去编写它,而且没有人喜欢Itanium。

官方文档(GO 1.5+ 2015年第三季度)现在反映了该完整列表。


2018年更新:正如Giorgos Oikonomou答案中所记录的那样,Go 1.7(2016年第一季度)引入了**go tool dist list**命令。请参见提交c3ecded:它修复了2015年第三季度提出的issue 12270

> 为了更容易地编写用于交叉编译的工具,以编程方式获取GOOS和GOARCH的可能组合将是很好的。

这在CL 19837中实现了。

> cmd/dist:引入list子命令以列出所有支持的平台

您可以以纯文本或json格式列出:

> go tool dist list -json
[
        {
                "GOOS": "android",
                "GOARCH": "386",
                "CgoSupported": true
        },
        ...
]

正如Mark Bates在推特上发表的

> 奖励:以适合显示的列格式输出:
>
> go tool dist list | column -c 75 | column -t

英文:

Note that those values are defined in:

With Go 1.5 (Q3 2015), GOARCH will become much more complete.
See commit 1eebb91 by Minux Ma (minux)

> ## go/build: reserve GOARCH values for all common architectures
>
> Whenever we introduce a new GOARCH, older Go releases won't recognize them and this causes trouble for both our users and us (we need to add unnecessary build tags).
>
> Go 1.5 has introduced three new GOARCHes so far: arm64 ppc64 ppc64le, we can take the time to introduce GOARCHes for all common architectures that Go might support in the future to avoid the problem.

const goosList = "android darwin dragonfly freebsd linux nacl \ 
  netbsd openbsd plan9 solaris windows "

const goarchList = "386 amd64 amd64p32 arm arm64 ppc64 ppc64le \
   mips mipsle mips64 mips64le mips64p32 mips64p32le \ # (new)
   ppc s390 s390x sparc sparc64 " # (new)

The list is still being review in Change 9644, with comments like:

> I wouldn't bother with Itanium. It's basically a dead architecture.
Plus, it's so hard to write a compiler for it that I really can't see it happening except as a labor of love, and nobody loves the Itanium.

The official documentation now (GO 1.5+ Q3 2015) reflects that completed list.


Update 2018: as documented in Giorgos Oikonomou's answer, Go 1.7 (Q1 2016) has introduced the
go tool dist list command.
See commit c3ecded: it fixes issue 12270 opened in Q3 2015:

> To easier write tooling for cross compiling it would be good to programmatically get the possible combinations of GOOS and GOARCH.

This was implemented in CL 19837

> cmd/dist: introduce list subcommand to list all supported platforms

You can list in plain text, or in json:

> go tool dist list -json
[
        {
                "GOOS": "android",
                "GOARCH": "386",
                "CgoSupported": true
        },
        ...
]

As Mark Bates tweeted:

> Bonus: Column output properly formatted for display:
>
> go tool dist list | column -c 75 | column -t

答案2

得分: 47

我认为你正在寻找可能的GOOS和GOARCH组合的列表,在这个部分:

http://golang.org/doc/install/source#environment

$GOOS和$GOARCH
目标操作系统和编译架构的名称。它们默认为$GOHOSTOS和$GOHOSTARCH的值(下面有描述)。

$GOOS的选择包括darwin(Mac OS X 10.8及以上版本和iOS)、dragonfly、freebsd、linux、netbsd、openbsd、plan9、solaris和windows。$GOARCH的选择包括amd64(64位x86,最成熟的端口)、386(32位x86)、arm(32位ARM)、arm64(64位ARM)、ppc64le(PowerPC 64位,小端序)、ppc64(PowerPC 64位,大端序)、mips64le(MIPS 64位,小端序)和mips64(MIPS 64位,大端序)。mipsle(MIPS 32位,小端序)和mips(MIPS 32位,大端序)。

$GOOS和$GOARCH的有效组合有:

$GOOS	$GOARCH
android	arm
darwin	386
darwin	amd64
darwin	arm
darwin	arm64
dragonfly	amd64
freebsd	386
freebsd	amd64
freebsd	arm
linux		386
linux		amd64
linux		arm
linux		arm64
linux		ppc64
linux		ppc64le
linux		mips
linux		mipsle
linux		mips64
linux		mips64le
netbsd	386
netbsd	amd64
netbsd	arm
openbsd	386
openbsd	amd64
openbsd	arm
plan9		386
plan9		amd64
solaris	amd64
windows	386
windows	amd64
英文:

I think you're looking for this list of possible GOOS and GOARCH combinations, in this section:

http://golang.org/doc/install/source#environment

> $GOOS and $GOARCH
> The name of the target operating system and
> compilation architecture. These default to the values of $GOHOSTOS and
> $GOHOSTARCH respectively (described below).
>
> Choices for $GOOS are darwin (Mac OS X 10.8 and above and iOS),
> dragonfly, freebsd, linux, netbsd, openbsd, plan9, solaris and
> windows. Choices for $GOARCH are amd64 (64-bit x86, the most mature
> port), 386 (32-bit x86), arm (32-bit ARM), arm64 (64-bit ARM), ppc64le
> (PowerPC 64-bit, little-endian), ppc64 (PowerPC 64-bit, big-endian),
> mips64le (MIPS 64-bit, little-endian), and mips64 (MIPS 64-bit,
> big-endian). mipsle (MIPS 32-bit, little-endian), and mips (MIPS
> 32-bit, big-endian).
>
> The valid combinations of $GOOS and $GOARCH are:
>
> $GOOS $GOARCH
> android arm
> darwin 386
> darwin amd64
> darwin arm
> darwin arm64
> dragonfly amd64
> freebsd 386
> freebsd amd64
> freebsd arm
> linux 386
> linux amd64
> linux arm
> linux arm64
> linux ppc64
> linux ppc64le
> linux mips
> linux mipsle
> linux mips64
> linux mips64le
> netbsd 386
> netbsd amd64
> netbsd arm
> openbsd 386
> openbsd amd64
> openbsd arm
> plan9 386
> plan9 amd64
> solaris amd64
> windows 386
> windows amd64

答案3

得分: 31

你可以通过运行以下命令来查看支持的平台列表:

go tool dist list

这将打印出(根据Go版本的不同):

android/386
android/amd64
android/arm
android/arm64
darwin/386
darwin/amd64
darwin/arm
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/s390x
nacl/386
nacl/amd64p32
nacl/arm
netbsd/386
netbsd/amd64
netbsd/arm
openbsd/386
openbsd/amd64
openbsd/arm
plan9/386
plan9/amd64
plan9/arm
solaris/amd64
windows/386
windows/amd64

工具的官方文档可以在以下链接找到:

https://godoc.org/github.com/golang/go/src/cmd/dist

要进行交叉编译,请使用以下命令:

GOOS=darwin GOARCH=386 go build main.go
英文:

You can see the list of supported platform by running:

go tool dist list

and this will print(depending on the Go version):

android/386
android/amd64
android/arm
android/arm64
darwin/386
darwin/amd64
darwin/arm
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/s390x
nacl/386
nacl/amd64p32
nacl/arm
netbsd/386
netbsd/amd64
netbsd/arm
openbsd/386
openbsd/amd64
openbsd/arm
plan9/386
plan9/amd64
plan9/arm
solaris/amd64
windows/386
windows/amd64

And the official documentation for the tool:

https://godoc.org/github.com/golang/go/src/cmd/dist

To cross compile use:

GOOS=darwin GOARCH=386 go build main.go

huangapple
  • 本文由 发表于 2013年12月22日 19:12:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/20728767.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定