ci: run go build jobs in parallel in cross compile job

This commit is contained in:
Marten Seemann
2023-04-23 14:13:12 +02:00
parent 1a483c0e43
commit 523036c4e6
2 changed files with 15 additions and 13 deletions

View File

@@ -2,16 +2,17 @@
set -e set -e
for dist in $(go tool dist list); do dist="$1"
goos=$(echo $dist | cut -d "/" -f1) goos=$(echo "$dist" | cut -d "/" -f1)
goarch=$(echo $dist | cut -d "/" -f2) goarch=$(echo "$dist" | cut -d "/" -f2)
# cross-compiling for android is a pain...
if [[ "$goos" == "android" ]]; then continue; fi
# iOS builds require Cgo, see https://github.com/golang/go/issues/43343
# Cgo would then need a C cross compilation setup. Not worth the hassle.
if [[ "$goos" == "ios" ]]; then continue; fi
echo "$dist" # cross-compiling for android is a pain...
GOOS=$goos GOARCH=$goarch go build -o main example/main.go if [[ "$goos" == "android" ]]; then exit; fi
rm main # iOS builds require Cgo, see https://github.com/golang/go/issues/43343
done # Cgo would then need a C cross compilation setup. Not worth the hassle.
if [[ "$goos" == "ios" ]]; then exit; fi
echo "$dist"
out="main-$goos-$goarch"
GOOS=$goos GOARCH=$goarch go build -o $out example/main.go
rm $out

View File

@@ -19,4 +19,5 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: go build example/main.go run: go build example/main.go
- name: Run cross compilation - name: Run cross compilation
run: .github/workflows/cross-compile.sh # run in parallel on as many cores as are available on the machine
run: go tool dist list | xargs -I % -P "$(nproc)" .github/workflows/cross-compile.sh %