#!/usr/bin/env bash # Unpack the cached musl tarball, apply patches/*.patch in order, and # install a static-only musl into a sysroot (headers in include/, libc.a and # the crt*.o start files in lib/, plus a musl-gcc wrapper in bin/). # # Not used by the contract-v1 image yet (milestone M2). Since Rustbelt # 0.19.0 loads static-PIE programs, the plan is plain # out/sysroot/bin/musl-gcc -static-pie hello.c # with none of the old rb-cc link tricks (see docs/porting.md). # # Usage: toolchain/musl/build.sh CACHE_DIR BUILD_DIR SYSROOT set -euo pipefail HERE=$(cd "$(dirname "$0")" && pwd) CACHE=$(realpath "$1") BUILD=$(realpath -m "$2") SYSROOT=$(realpath -m "$3") read -r _ name < "$HERE/musl.sha256" rm -rf "$BUILD" && mkdir -p "$BUILD" tar -xzf "$CACHE/$name" -C "$BUILD" src=$BUILD/${name%.tar.gz} for p in "$HERE"/patches/*.patch; do [ -e "$p" ] || continue echo "[musl] applying $(basename "$p")"; patch -d "$src" -p1 < "$p" done cd "$src" ./configure --prefix="$SYSROOT" --syslibdir="$SYSROOT/lib" --disable-shared >/dev/null make -j"$(nproc)" >/dev/null make install >/dev/null echo "[musl] installed into $SYSROOT ($(ls "$SYSROOT/lib" | wc -l) files in lib/)"