所有可能的GOOS价值?

liu*_*rry 51 cross-compiling go

如果我做对了,GOOS确定编译源代码时.

为了更好地支持多个操作系统,我对GOOS可能的内容感兴趣.

当然,它可能有无限的可能性,因为Go是开源的.所以我真正想要的是一个"共同列表".

已知值为:

  • windows
  • linux
  • darwinfreebsdunix?我知道其中至少有一个必须存在.

Von*_*onC 57

请注意,这些值在中定义src/go/build/syslist.go.

随着围棋1.5(Q3 2015年),GOARCH将成为很多更加完整.
提交1eebb91Minux马(minux)

go/build:保留所有常见体系结构的GOARCH

每当我们介绍一个新的GOARCH,较旧的Go版本将无法识别它们,这会给我们的用户和我们带来麻烦(我们需要添加不必要的构建标记).

到目前为止arm64 ppc64 ppc64le,Go 1.5已经引入了三个新的GOARCH:我们可以花时间为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)
Run Code Online (Sandbox Code Playgroud)

该列表仍在Change 9644中进行审核,其评论如下:

我不打扰Itanium.它基本上是一个死的架构.
另外,编写一个编译器是如此困难,以至于我真的看不到它的发生,除非作为爱的劳动,没有人喜欢Itanium.

现在的官方文件(GO 1.5 + 2015年第3季度)反映了完整的清单.


更新2018年:正如Giorgos Oikonomou回答所述,Go 1.7(2016年第一季度)引入了该
go tool dist list命令.
请参阅commit c3ecded:它修复了2015年第3季度开放的问题12270:

为了更容易编写工具来进行交叉编译,最好以编程方式获得GOOS和GOARCH的可能组合.

这是在CL 19837中实现的

cmd/dist:introduction list子命令列出所有支持的平台

您可以用纯文本或json列出:

> go tool dist list -json
[
        {
                "GOOS": "android",
                "GOARCH": "386",
                "CgoSupported": true
        },
        ...
]
Run Code Online (Sandbox Code Playgroud)


Eve*_*man 38

我想你正在寻找这个可能的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位,小-endian),ppc64(PowerPC 64位,big-endian),mips64le(MIPS 64位,little-endian)和mips64(MIPS 64位,big-endian).mipsle(MIPS 32位,little-endian)和mips(MIPS 32位,big-endian).

$ 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
Run Code Online (Sandbox Code Playgroud)


geo*_*eok 16

您可以通过运行来查看支持的平台列表:

$ go tool dist list

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
Run Code Online (Sandbox Code Playgroud)

以及该工具的官方文档:

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

交叉编译使用:

GOOS=darwin GOARCH=386 go build main.go
Run Code Online (Sandbox Code Playgroud)