Go : кросс-компиляция и переносимость

Вопросы написания собственного программного кода (на любых языках)

Модератор: Olej

Аватара пользователя
Olej
Писатель
Сообщения: 21338
Зарегистрирован: 24 сен 2011, 14:22
Откуда: Харьков
Контактная информация:

Re: Go : кросс-компиляция и переносимость

Непрочитанное сообщение Olej » 02 май 2022, 17:41

На странице инструкции по сборке GoLang из исходников самой последней версии 1.18 Installing Go from source даётся полный перечень архитектур:
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 android, darwin, dragonfly, freebsd, illumos, ios, js, 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), mips64 (MIPS 64-bit, big-endian), mipsle (MIPS 32-bit, little-endian), mips (MIPS 32-bit, big-endian), s390x (IBM System z 64-bit, big-endian), and wasm (WebAssembly 32-bit).

The valid combinations of $GOOS and $GOARCH are:

$GOOS $GOARCH
aix ppc64
android 386
android amd64
android arm
android arm64
darwin amd64
darwin arm64
dragonfly amd64
freebsd 386
freebsd amd64
freebsd arm
illumos amd64
ios arm64
js wasm
linux 386
linux amd64
linux arm
linux arm64
linux ppc64
linux ppc64le
linux mips
linux mipsle
linux mips64
linux mips64le
linux riscv64
linux s390x
netbsd 386
netbsd amd64
netbsd arm
openbsd 386
openbsd amd64
openbsd arm
openbsd arm64
plan9 386
plan9 amd64
plan9 arm
solaris amd64
windows 386
windows amd64
windows arm
windows arm64
С такими вот интересными уточнениями относительно ARM:

Код: Выделить всё

$GOARM (for arm only; default is auto-detected if building on the target processor, 6 if not)
This sets the ARM floating point co-processor architecture version the run-time should target. If you are compiling on the target system, its value will be auto-detected.

GOARM=5: use software floating point; when CPU doesn't have VFP co-processor
GOARM=6: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)
GOARM=7: use VFPv3; usually Cortex-A cores
If in doubt, leave this variable unset, and adjust it if required when you first run the Go executable. The GoARM page on the Go community wiki contains further details regarding Go's ARM support.

Аватара пользователя
Olej
Писатель
Сообщения: 21338
Зарегистрирован: 24 сен 2011, 14:22
Откуда: Харьков
Контактная информация:

Re: Go : кросс-компиляция и переносимость

Непрочитанное сообщение Olej » 02 май 2022, 17:50

Olej писал(а):
02 май 2022, 17:41
С такими вот интересными уточнениями относительно ARM:
Собираю на x86_64 под Rabsberry Pi:

Код: Выделить всё

olej@nvidia:~/2022/Go/hello$ uname -a
Linux nvidia 5.4.0-107-generic #121-Ubuntu SMP Thu Mar 24 16:04:27 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Код: Выделить всё

olej@nvidia:~/2022/Go/hello$ GOOS=linux GOARCH=arm GOARM=7 go build hello.go

olej@nvidia:~/2022/Go/hello$ file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, Go BuildID=6vW1dMzqNoTu_OuycWLq/Oc-f2Whug2sgLwCERR_1/uLPnNuhdVdCRD7brWeGP/Vq_yw9p6-q4SH04aq94U, not stripped

olej@nvidia:~/2022/Go/hello$ ls -l hello
-rwxrwxr-x 1 olej olej 1880157 мая  2 17:26 hello
Теперь этот файл по SSH заливаю в Rabsberry Pi в отдельный каталог:

Код: Выделить всё

olej@localhost:~/go/x86_64 $ inxi -Mxxxf
Machine:   Type: ARM Device System: Raspberry Pi 2 Model B Rev 1.1 details: BCM2835 rev: a21041 
           serial: 00000000f57e2ca8 
CPU:       Info: Quad Core model: ARMv7 v7l variant: cortex-a7 bits: 32 type: MCP arch: v7l rev: 5 bogomips: 256 
           Speed: 1000 MHz min/max: 600/1000 MHz Core speeds (MHz): 1: 1000 2: 1000 3: 1000 4: 1000 
           Features: edsp evtstrm fastmult half idiva idivt lpae neon thumb tls vfp vfpd32 vfpv3 vfpv4 

Код: Выделить всё

olej@localhost:~/go/x86_64 $ uname -a
Linux localhost 5.15.32-v7+ #1538 SMP Thu Mar 31 19:38:48 BST 2022 armv7l GNU/Linux

Код: Выделить всё

olej@localhost:~/go/x86_64 $ pwd
/home/olej/go/x86_64

olej@localhost:~/go/x86_64 $ ls -l
итого 1840
-rwxrwxr-x 1 olej olej 1880157 мая  2 17:26 hello

Код: Выделить всё

olej@localhost:~/go/x86_64 $ ./hello
ты кто будешь?
> x86_64
какое длинное имя ... целых 7 байт
привет, x86_64

Ответить

Вернуться в «Программирование»

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и 5 гостей