Files
StaticLink.Avalonia/scripts/woodpecker-cross-test.sh
T
2026-10-05 17:22:10 +08:00

70 lines
3.6 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TOOLCHAIN_IMAGE="ghcr.io/greepar/staticlink.avalonia-zig@sha256:a88b5ea9f76f659978cda36dda06233d7fdc9121046eedf945044fc908d24b85"
export CROSS_RID=linux-x64
AGENT_HOME="$(getent passwd "$(id -u)" | cut -d: -f6)"
if [ -z "$AGENT_HOME" ] || [ "$AGENT_HOME" = / ]; then
echo "Cannot find a persistent home directory for the agent user" >&2
exit 1
fi
CACHE_KEY="$(printf '%s\n' "${CI_REPO_OWNER:?}/${CI_REPO_NAME:?}" "${CI_COMMIT_BRANCH:?}" "$TOOLCHAIN_IMAGE" "$CROSS_RID" | sha256sum | cut -c1-24)"
CACHE_ROOT="$AGENT_HOME/.cache/staticlink-woodpecker/$CACHE_KEY"
RESULTS="$AGENT_HOME/staticlink-ci-artifacts/${CI_REPO_OWNER}/${CI_REPO_NAME}/${CI_COMMIT_BRANCH}/${CI_PIPELINE_NUMBER:?}"
mkdir -p "$CACHE_ROOT"
exec 9>"$CACHE_ROOT/build.lock"
echo "Waiting for exclusive access to persistent cache: $CACHE_ROOT"
flock 9
if [ ! -d "$CACHE_ROOT/source/.git" ]; then
git clone --no-hardlinks "$SCRIPT_ROOT" "$CACHE_ROOT/source"
fi
git -C "$CACHE_ROOT/source" fetch --depth=1 "$SCRIPT_ROOT" HEAD
git -C "$CACHE_ROOT/source" checkout --detach FETCH_HEAD
cd "$CACHE_ROOT/source"
cp build/linux-toolchain/sources.lock.json build/linux-toolchain/release.lock.json
mkdir -p "$RESULTS/environment"
df -h .
free -h
command -v docker
docker version
if [ "$(docker info --format '{{.OSType}}/{{.Architecture}}')" != "linux/x86_64" ]; then
echo "Requires a Linux x86_64 Docker daemon on the WSL agent" >&2
exit 1
fi
AVAILABLE_KB="$(df -Pk . | awk 'NR == 2 {print $4}')"
if [ "$AVAILABLE_KB" -lt 41943040 ]; then
echo "Need at least 40 GiB free before pulling the toolchain and compiling; more is recommended" >&2
exit 1
fi
echo "Persistent test results: $RESULTS"
exec > >(tee "$RESULTS/build.log") 2>&1
trap 'result=$?; trap - EXIT; if [ "$result" -eq 0 ] && [ -d External/NativeStatic/linux-x64/native ]; then mkdir -p "$RESULTS/native"; cp -a External/NativeStatic/linux-x64/native/. "$RESULTS/native/"; fi; printf "%s\n" "$result" > "$RESULTS/exit-code"; echo "Results retained at $RESULTS"; exit "$result"' EXIT
git rev-parse HEAD > "$RESULTS/commit"
printf '%s\n' "$TOOLCHAIN_IMAGE" > "$RESULTS/toolchain-image"
docker pull "$TOOLCHAIN_IMAGE"
docker run --rm --user "$(id -u):$(id -g)" \
-e HOME=/tmp -e DOTNET_CLI_HOME=/tmp -e ZIG_GLOBAL_CACHE_DIR=/tmp/zig-cache \
-v "$RESULTS/environment:/validation" --entrypoint python3 \
"$TOOLCHAIN_IMAGE" /opt/staticlink/validate-toolchain.py \
--output /validation --rids '["linux-x64"]'
mkdir -p External/NativeStatic/.work/home
docker run --rm --user "$(id -u):$(id -g)" \
-e HOME=/src/External/NativeStatic/.work/home -e CROSS_RID \
-e CCACHE_DIR=/src/External/NativeStatic/.work/ccache -e CCACHE_MAXSIZE=1G \
-e ZIG_GLOBAL_CACHE_DIR=/src/External/NativeStatic/.work/zig-global \
-v "$PWD:/src" -w /src --entrypoint bash "$TOOLCHAIN_IMAGE" -c '
set -euo pipefail
export SOURCE_LOCK=/src/build/linux-toolchain/release.lock.json
source scripts/prepare-cross-sources.sh
BUILD_JOBS="$(nproc)"
echo "Full CPU parallelism: $BUILD_JOBS compilation jobs"
python3 build/linux-toolchain/build-cross.py \
--target "$CROSS_RID" --sources-manifest "$WORK_DIR/cross-sources.json" \
--work /src/External/NativeStatic/.work/toolchains \
--output "/src/External/NativeStatic/zig-cross/$SKIASHARP_VERSION/$CROSS_RID" --jobs "$BUILD_JOBS"
python3 build/linux-toolchain/package-zig.py \
--rid "$CROSS_RID" \
--input "/src/External/NativeStatic/zig-cross/$SKIASHARP_VERSION/$CROSS_RID" \
--output "/src/External/NativeStatic/$CROSS_RID/native"
'