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