kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

extract.sh (2662B)


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