#!/bin/bash # remote-warm.sh : runs on the Linux build # host (build.sh GOLIB_REMOTE_CACHE). Compiles the pure-Go packages of the # framework into /gocache with the same Go release as the Mac, so their # cache keys match; cacheprog -serve then hands them to the Mac's build. # No Xcode here: an xcrun stand-in makes every cgo package (and the link) # fail, and those are left to the Mac. set -euo pipefail D="$(mkdir -p "$1/bin" && cd "$1" && pwd)" GOVERSION=$2 MOBILE=$3 if [[ "$("$D/go/bin/go" env GOVERSION 2>/dev/null)" != "${GOVERSION}" ]]; then echo "installing ${GOVERSION} into $D/go..." rm -rf "$D/go" python3 - "$D" "${GOVERSION}" <<'PY' import hashlib, io, json, sys, tarfile, urllib.request d, v = sys.argv[1], sys.argv[2] name = f"{v}.linux-amd64.tar.gz" rel = [r for r in json.load(urllib.request.urlopen("https://go.dev/dl/?mode=json&include=all")) if r["version"] == v][0] want = [f["sha256"] for f in rel["files"] if f["filename"] == name][0] b = urllib.request.urlopen("https://go.dev/dl/" + name).read() assert hashlib.sha256(b).hexdigest() == want, "sha256 mismatch for " + name tarfile.open(fileobj=io.BytesIO(b)).extractall(d) PY fi export PATH="$D/bin:$D/go/bin:$PATH" GOPATH="$D/gopath" GOMODCACHE="$D/gomod" GOCACHE="$D/gocache" GOTOOLCHAIN=local GOFLAGS= go_version_of() { go version -m "$1" 2>/dev/null | awk '$1 == "mod" && $2 == "golang.org/x/mobile" {print $3}'; } if [[ "$(go_version_of "$D/bin/gomobile")" != "${MOBILE}" ]]; then GOBIN="$D/bin" go install "golang.org/x/mobile/cmd/gomobile@${MOBILE}" "golang.org/x/mobile/cmd/gobind@${MOBILE}" fi (cd "$D/src/cacheprog" && go build -o "$D/bin/cacheprog" .) cat > "$D/bin/xcrun" <<'EOF' #!/bin/sh # xcrun stand-in for the cache warm-up: no Xcode or SDK, so cgo fails. case "$*" in *--find*) echo /bin/false ;; *--show-sdk-path*) echo /nonexistent-ios-sdk ;; *xcodebuild*-version*) echo "Xcode stand-in" ;; *) exit 1 ;; esac EOF chmod +x "$D/bin/xcrun" cd "$D/src/kcp" start=$(date +%s) # Fails at the first cgo package of each target; go builds the rest anyway. nice -n 10 gomobile bind -trimpath -target=ios,iossimulator -ldflags="-s -w" \ -o "$D/out/AtircGo.xcframework" github.com/kcp-dev/kcp/contrib/wasm/ios/atircgo \ > "$D/warm.log" 2>&1 || true rm -rf "$D/out" echo "$(hostname): warm-up $(( $(date +%s) - start ))s, cache $(du -sh "$GOCACHE" | cut -f1)"