所有可能的 GOOS 值?

新手上路,请多包涵

如果我没看错的话, GOOS 是编译源码时确定的。

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

当然,它可能有无限的可能性,因为 Go 是开源的。所以我真正想要的是一个“通用列表”。

已知值是:

  • windows
  • linux
  • darwinfreebsdunix ?我知道至少其中之一必须存在。

原文由 liuyanghejerry 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.3k
2 个回答

请注意,这些值定义在:

随着 Go 1.5(2015 年第 3 季度), GOARCH 将变得 更加 完整。

参见 Minux Ma 提交1eebb91 ( minux )

go/build : reserve GOARCH 所有 通用架构的值

每当我们引入新的 GOARCH 时,旧的 Go 版本将无法识别它们,这会给我们的用户和我们带来麻烦(我们需要添加不必要的构建标签)。

Go 1.5 到目前为止引入了三个新的 GOARChes: arm64 ppc64 ppc64le ,我们可以花时间为 Go 将来可能支持的所有常见架构引入 GOARChes 以避免问题。

 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。

现在的 官方文档(GO 1.5+ Q3 2015)反映了完整的列表。


2018 年更新:如 Giorgos Oikonomou回答 中所述,Go 1.7(2016 年第一季度)引入了

go tool dist list 命令。

请参阅 提交 c3ecded :它修复了 2015 年第三季度打开的 问题 12270

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

这是在 CL 19837 中实现的

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

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

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

正如 马克贝茨发推文

奖励:列输出格式正确显示:

 go tool dist list | column -c 75 | column -t

原文由 VonC 发布,翻译遵循 CC BY-SA 4.0 许可协议

我认为您正在本节中寻找可能的 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位,little -endian)、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

原文由 Eve Freeman 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏