RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / toolchain / musl / build.sh
1181 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/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/)"