-
Notifications
You must be signed in to change notification settings - Fork 5
/
go-cross
executable file
·38 lines (31 loc) · 1.18 KB
/
go-cross
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# go-cross [go binary] [version]
#
# go-cross builds the main package under the current directory for all the first
# class Go ports. The optional parameters configure which Go command to build
# with, and a version override.
#
# This script is meant to be simple. If you need more, copy and adapt it.
# Consistently turn cgo off, even for our local linux/amd64.
export CGO_ENABLED=0
# Since we use GOAMD64=v3 locally,
# turn that off for cross-builds for greater compatibility.
export GOAMD64=v1
gocmd=${1:-"go"}
version=${2:-"$(git describe --always --dirty --tags)"}
dir=$(basename "$PWD")
echo "Building version ${version} with $($gocmd version)"
while read goos goarch; do
(
export GOOS=$goos GOARCH=$goarch
out="${dir}_${version}_${goos}_${goarch}$($gocmd env GOEXE)"
$gocmd build -trimpath -ldflags="-w -s -X 'main.version=${version}'" -o="${out}"
echo $out
) &
done < <(
# "dist list -json" gives us a list of all targets in JSON format.
# Flatten the list, and only keep the first-class ports.
# Then print the GOOS/GOARCH pairs in a way that shell can easily read.
$gocmd tool dist list -json | jq -r '.[] | select(.FirstClass) | [.GOOS, .GOARCH] | @tsv'
)
wait