All possible GOOS value? - go

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.

Note that those values are defined in:
src/go/build/syslist.go, and
doc/install/source#environment.
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

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

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

Related

Cross-compile to ARMv7 failed

I try to compile a go program on my Linux desktop (Linux desktop 4.10.0-28-generic #32-Ubuntu SMP Fri Jun 30 05:32:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux), go version go version go1.8.3 linux/amd64 to arm:
$ GOPATH=/home/xrfang/git/hermes/ GOARM=7 GOARCH=arm go build .
the executable is generated, but seems NOT ARMv7:
$ file hermes
hermes: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
It shows EABI5. How can I cross-compile to ARMv7? Is there anything missing on my Linux Desktop so that the cross-compile fallback to a lower ARM version?
Thanks.
I believe, it is not ARMv5. I was trying to do the same on MAC OS and 'file' command on Mac is saying v7, but the 'file' command on Linux don't. However, I do know that v7 has some good improvements and may boost the performance of your program.
But, that is out of scope of this question and you may need to dig deeper into what you're doing and why a performance improvement is expected.
All I can say is, it is compiled for v7.

Golang. Cross Compiling for MIPS

I have tried compiling my simply program:
func main(){fmt.Printf("Hello")}
to MIPS architecture on my PC wit 64 bit Debian Linux according to documentation
https://golang.org/doc/install/source#environment
via using command
GOOS=linux GOARCH=mipsle go build
GOOS=linux GOARCH=mips go build
Every time I get the error:
runtime/internal/sys compile
unknown architecture "mipsle(mips)"
The interesting thing is, if a try using command:
GOOS=linux GOARCH=mipsle64 go build
The program was build.
Is it dependent on system OS on my PC ? How can I build a binary for MIPS or MIPSLE ?
Go 1.6 does not support MIPS or MIPSLE. 1.6 supports MIPS64(LE). 1.8 supports MIPS(LE).
From https://golang.org/doc/install/source:
amd64 (also known as x86-64)
A mature implementation.
386 (x86 or x86-32)
Comparable to the amd64 port.
arm (ARM)
Supports Linux, FreeBSD, NetBSD, OpenBSD and Darwin binaries. Less widely used than the other ports.
arm64 (AArch64)
Supports Linux and Darwin binaries. New in 1.5 and not as well exercised as other ports.
ppc64, ppc64le (64-bit PowerPC big- and little-endian)
Supports Linux binaries. New in 1.5 and not as well exercised as other ports.
mips, mipsle (32-bit MIPS big- and little-endian)
Supports Linux binaries. New in 1.8 and not as well exercised as other ports.
mips64, mips64le (64-bit MIPS big- and little-endian)
Supports Linux binaries. New in 1.6 and not as well exercised as other ports.
s390x (IBM System z)
Supports Linux binaries. New in 1.7 and not as well exercised as other ports.

How do I determine whether the program was built as 32 bit or 64 bit in Go?

The closest I can get is runtime.GOARCH, but that might also give arm, which could be either 32 or 64 bit.
I only care how this program was built, not whether the OS also supports 64-bit executables. e.g. for ARM mode on an AArch64 CPU or 32-bit compat mode on an x86-64 CPU, I still want 32 because that's the mode this program is running in.
Related: Detect OS x86 or x64, when compiled as x86 in GO is about detecting what the OS supports, e.g. for maybe running a differently-compiled executable.
Use GOARCH for arm: arm (ARM) and arm64 (AArch64),
Optional environment variables
$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
$GOOS $GOARCH
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 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
const is64Bit = uint64(^uintptr(0)) == ^uint64(0)
This works because if uintptr is 32 bits, ^uintptr(0) will be 0xffffffff rather than 0xffffffffffffffff.
^uint64(0) will always be 0xffffffffffffffff regardless of 32 or 64 bit architectures.

How do I make `go get` to build against x86_64 instead of i386

I am trying to use either go-qml or gotk3 to build a very simple desktop app that can run under OS X. However when I try to use go get to install either library, it will try to build for i386 and skip the libraries that were build against x86_64. I could try to get the 32 bit version of those libraries, but I would prefer to build for 64bit. How do I instruct go get to do so?
The warnings that are followed by errors look lie this:
go get gopkg.in/qml.v1
# gopkg.in/qml.v1
ld: warning: ld: warning: ld: warning: ignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtWidgets.framework/QtWidgets, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtWidgets.framework/QtWidgetsignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtGui.framework/QtGui, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtGui.framework/QtGuiignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtQuick.framework/QtQuick, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtQuick.framework/QtQuick
Set the environment variable GOARCH to the value amd64. This instructs the go command to generate files for amd64. Other valid values for GOARCH are 386 and arm.
F.Y.I.
The Go compilers support the following instruction sets:
amd64, 386
The x86 instruction set, 64- and 32-bit.
arm64, arm
The ARM instruction set, 64-bit (AArch64) and 32-bit.
mips64, mips64le, mips, mipsle
The MIPS instruction set, big- and little-endian, 64- and 32-bit.
ppc64, ppc64le
The 64-bit PowerPC instruction set, big- and little-endian.
riscv64
The 64-bit RISC-V instruction set.
s390x
The IBM z/Architecture.
wasm
WebAssembly.
(from: Introduction | Installing Go from source | Doc # golang.org)
Also, you can go tool dist list to check the available architectures to build in your machine.
$ go tool dist list
aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
(* snip *)
To build a static binary for macOS (Intel/ARM64) would be as below. In this manner, I suppose GOOS="darwin" GOARCH="arm64" combination will be for M1 architecture.
MyVar="foo"
CGO_ENABLED=0 \
GOOS="darwin" \
GOARCH="amd64" \
GOARM="" \
go build \
-ldflags="-s -w -extldflags \"-static\" -X 'main.myVar=${MyVar}'" \
-o="/path/to/export/bin/myApp" \
"/path/to/main.go"
To compile for Linux on ARM v6, such as RaspberryPi Zero W, the combination would be as below.
$ CGO_ENABLED=0 GOOS="linux" GOARCH="arm" GOARM="6" go build .

Shoes Debian package

Does anyone know of a Debian Package of Shoes?
I am building a live CD and would like to include shoes in it, but I can't seem to find one.
http://packages.debian.org/testing/interpreters/shoes
packages.debian.org/search?keywords=shoes
Paket shoes
lenny (stable) (interpreters): tiny graphics and windowing toolkit using Ruby
0.r396-5: alpha amd64 arm armel hppa i386 ia64 mips mipsel powerpc s390 sparc
squeeze (testing) (interpreters): tiny graphics and windowing toolkit using Ruby
0.r396-5: alpha amd64 armel hppa i386 ia64 mips mipsel powerpc s390 sparc
sid (unstable) (interpreters): tiny graphics and windowing toolkit using Ruby
0.r396-5: alpha amd64 armel hppa hurd-i386 i386 ia64 m68k mips mipsel powerpc s390 sparc

Resources