gpt4 book ai didi

go - 所有可能的 GOOS 值?

转载 作者:IT老高 更新时间:2023-10-28 12:58:42 29 4
gpt4 key购买 nike

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

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

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

已知值为:

  • windows
  • linux
  • darwin 还是 freebsd 还是 unix?我知道其中至少有一个必须存在。

最佳答案

请注意,这些值定义在:

随着 Go 1.5(2015 年第三季度),GOARCH 将变得更加更加完整。
commit 1eebb91Minux 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)

Change 9644 中的列表仍在审核中,评论如下:

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.

official documentation现在(GO 1.5+ Q3 2015)反射(reflect)了已完成的列表。


2018 年更新:如 Giorgos Oikonomou 中所述的answer , Go 1.7 (Q1 2016) 引入了
go tool dist list 命令。
commit c3ecded :它修复了issue 12270于 2015 年第三季度开业:

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

这是在 CL 19837 中实现的

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

可以用纯文本列出,也可以用json列出:

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

作为 Mark Bates tweeted :

Bonus: Column output properly formatted for display:

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

关于go - 所有可能的 GOOS 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20728767/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com