extract.sh (2737B)
1 #!/usr/bin/env bash 2 # test/libc/musl/extract.sh — build a musl sysroot container image and 3 # unpack /sysroot from it into $XDG_CACHE_HOME/kit/sysroots/linux-musl[-ARCH]/. 4 # Cached after the first successful run; pass `-f` to force a rebuild. 5 # 6 # Usage: 7 # extract.sh # default aarch64 -> $XDG_CACHE_HOME/kit/sysroots/linux-musl/ 8 # extract.sh -a aarch64 # same as default 9 # extract.sh -a x64 # x86_64 -> $XDG_CACHE_HOME/kit/sysroots/linux-musl-x64/ 10 # extract.sh -a rv64 # riscv64 -> $XDG_CACHE_HOME/kit/sysroots/linux-musl-rv64/ 11 # 12 # Arch-specific Containerfiles live next to this script 13 # (Containerfile, Containerfile.x64, Containerfile.rv64). 14 # 15 # The aarch64 sysroot uses the bare `musl-sysroot` name (no arch suffix) 16 # for consistency with existing test-libc-musl usage. test-libc on Linux 17 # uses the arch-suffixed paths uniformly and re-targets `musl-sysroot` for 18 # aarch64. 19 # 20 # Output layout (per arch): 21 # $XDG_CACHE_HOME/kit/sysroots/linux-musl[-ARCH]/ 22 # lib/ crt1.o crti.o crtn.o libc.a libssp_nonshared.a ld-musl-* 23 # include/ musl + linux-headers tree 24 # PROVENANCE 25 set -eu 26 27 ROOT="$(cd "$(dirname "$0")/../../.." && pwd)" 28 _KIT_SYSROOTS="${XDG_CACHE_HOME:-$HOME/.cache}/kit/sysroots" 29 ARCH=aarch64 30 FORCE=0 31 32 while [ $# -gt 0 ]; do 33 case "$1" in 34 -a) ARCH="$2"; shift 2 ;; 35 --arch=*) ARCH="${1#--arch=}"; shift ;; 36 -f|--force) FORCE=1; shift ;; 37 *) echo "unknown arg: $1" >&2; exit 2 ;; 38 esac 39 done 40 41 case "$ARCH" in 42 aarch64) 43 SYSROOT="$_KIT_SYSROOTS/linux-musl" 44 PLATFORM="linux/arm64" 45 CFILE="Containerfile" 46 TAG="kit-musl-sysroot" 47 ;; 48 x64) 49 SYSROOT="$_KIT_SYSROOTS/linux-musl-x64" 50 PLATFORM="linux/amd64" 51 CFILE="Containerfile.x64" 52 TAG="kit-musl-sysroot-x64" 53 ;; 54 rv64) 55 SYSROOT="$_KIT_SYSROOTS/linux-musl-rv64" 56 PLATFORM="linux/riscv64" 57 CFILE="Containerfile.rv64" 58 TAG="kit-musl-sysroot-rv64" 59 ;; 60 *) 61 echo "extract.sh: unknown arch '$ARCH' (want aarch64|x64|rv64)" >&2 62 exit 2 63 ;; 64 esac 65 66 if [ -f "$SYSROOT/PROVENANCE" ] && [ $FORCE -eq 0 ]; then 67 echo "musl sysroot already present at $SYSROOT (use -f to rebuild)" 68 exit 0 69 fi 70 71 if ! command -v podman >/dev/null 2>&1; then 72 echo "extract.sh: podman is required" >&2 73 exit 1 74 fi 75 76 cd "$ROOT/test/libc/musl" 77 echo "Building $TAG (Alpine $ARCH + musl-dev)..." 78 podman build --platform "$PLATFORM" -f "$CFILE" -t "$TAG" . >/dev/null 79 80 rm -rf "$SYSROOT" 81 mkdir -p "$SYSROOT" 82 83 echo "Extracting sysroot to $SYSROOT..." 84 podman run --rm --platform "$PLATFORM" "$TAG" | tar -C "$SYSROOT" -xf - 85 86 echo "Done. Provenance:" 87 cat "$SYSROOT/PROVENANCE"