Базовый образ на основе goreleaser-cross имеет старый Xcode, по этому мы собираем свой.
Огромное спасибо за проекту osxcross, за инструментарий и сопровождение.
Образ с C,C++ компиляторами, для кросс компиляции golang c CGO_ENABLED=1 из linux, под macOS, linux(arm,arm64), windows, freebsd, openbsd.
Примеры есть также у них тут.
GOOS=darwin \
GOARCH=amd64 \
CGO_ENABLED=1 \
CC=o64-clang \
CXX=o64-clang++ \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=darwin \
GOARCH=amd64 \
CGO_ENABLED=1 \
CC=oa64-clang \
CXX=oa64-clang++ \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=windows \
GOARCH=amd64 \
CGO_ENABLED=1 \
CC=x86_64-w64-mingw32-gcc \
CXX=x86_64-w64-mingw32-g++ \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=linux \
GOARCH=arm \
CGO_ENABLED=1 \
CC=x86_64-linux-gnu-gcc \
CXX=x86_64-linux-gnu-g++ \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=linux \
GOARCH=arm \
CGO_ENABLED=1 \
CC=arm-linux-gnueabihf-gcc \
CXX=arm-linux-gnueabihf-g++ \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=linux \
GOARCH=arm64 \
CGO_ENABLED=1 \
CC=aarch64-linux-gnu-gcc \
CXX=aarch64-linux-gnu-g++ \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=linux \
GOARCH=arm \
CGO_ENABLED=1 \
CC=arm-linux-gnueabihf-gcc \
CXX=arm-linux-gnueabihf-g++ \
CGO_LDFLAGS="-static"
go build -ldflags "-linkmode external -extldflags=\"${CGO_LDFLAGS}\"" -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=freebsd \
GOARCH=amd64 \
CGO_ENABLED=1 \
CC="clang --target=x86_64-unknown-freebsd --sysroot=/sysroot/freebsd/amd64" \
CXX="clang++ --target=x86_64-unknown-freebsd --sysroot=/sysroot/freebsd/amd64" \
CGO_CFLAGS="--sysroot=/sysroot/freebsd/amd64" \
CGO_LDFLAGS="--sysroot=/sysroot/freebsd/amd64 -L/sysroot/freebsd/amd64/lib" \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=freebsd \
GOARCH=arm64 \
CGO_ENABLED=1 \
CC="clang --target=aarch64-unknown-freebsd --sysroot=/sysroot/freebsd/arm64" \
CXX="clang++ --target=aarch64-unknown-freebsd --sysroot=/sysroot/freebsd/arm64" \
CGO_CFLAGS="--sysroot=/sysroot/freebsd/arm64" \
CGO_LDFLAGS="--sysroot=/sysroot/freebsd/arm64 -L/sysroot/freebsd/arm64/lib" \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=freebsd \
GOARCH=amd64 \
CGO_ENABLED=1 \
CC="clang --target=x86_64-unknown-freebsd --sysroot=/sysroot/freebsd/amd64" \
CXX="clang++ --target=x86_64-unknown-freebsd --sysroot=/sysroot/freebsd/amd64" \
CGO_CFLAGS="-static --sysroot=/sysroot/freebsd/amd64" \
CGO_LDFLAGS="-static --sysroot=/sysroot/freebsd/amd64 -L/sysroot/freebsd/amd64/lib" \
go build -ldflags "-linkmode external -extldflags=\"${CGO_LDFLAGS}\"" -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=openbsd \
GOARCH=amd64 \
CGO_ENABLED=1 \
CC="clang --target=x86_64-unknown-openbsd --sysroot=/sysroot/openbsd/amd64" \
CXX="clang++ --target=x86_64-unknown-openbsd --sysroot=/sysroot/openbsd/amd64" \
CGO_CFLAGS="--sysroot=/sysroot/openbsd/amd64" \
CGO_LDFLAGS="--sysroot=/sysroot/openbsd/amd64 -L/sysroot/openbsd/amd64/lib" \
go build -o build/${GOOS}_${GOARCH}/example ./main.goGOOS=openbsd \
GOARCH=arm64 \
CGO_ENABLED=1 \
CC="clang --target=aarch64-unknown-openbsd --sysroot=/sysroot/openbsd/arm64" \
CXX="clang++ --target=aarch64-unknown-openbsd --sysroot=/sysroot/openbsd/arm64" \
CGO_CFLAGS="--sysroot=/sysroot/openbsd/arm64" \
CGO_LDFLAGS="--sysroot=/sysroot/openbsd/arm64 -L/sysroot/openbsd/arm64/lib" \
go build -o build/${GOOS}_${GOARCH}/example ./main.go