#!/usr/bin/env bash # The runtime and the native programs on aarch64, under qemu (ADR 0011). # # Everything is compiled here, for aarch64 (rustc's target, clang # --target, lld), against an arm64 Fedora sysroot made once with podman in # target/arm64-sysroot. The aarch64 binaries then run through qemu: the # test binaries as cargo's runner, and the programs they build through the # kernel's binfmt handler. # # scripts/aarch64.sh run: the runtime's unit tests, then # every tests/run program natively (on # 4 then 1 threads), then again with # every parked actor hibernated # scripts/aarch64.sh --available exit 0 if this machine can run it # # Needs: podman, qemu-user-static with its binfmt handler (Fedora: # `sudo dnf install qemu-user-static && sudo systemctl restart # systemd-binfmt`), clang, lld and llvm-ar. Emulated, the native step takes # a few minutes. set -euo pipefail cd "$(dirname "$0")/.." TARGET=aarch64-unknown-linux-gnu IMAGE=registry.fedoraproject.org/fedora:44 available() { command -v podman >/dev/null && command -v qemu-aarch64-static >/dev/null && command -v clang >/dev/null && command -v ld.lld >/dev/null && command -v llvm-ar >/dev/null && [ -e /proc/sys/fs/binfmt_misc/qemu-aarch64 ] } if [ "${1:-}" = --available ]; then available exit fi if ! available; then echo "aarch64.sh: needs podman, qemu-user-static (binfmt), clang, lld and llvm-ar" >&2 exit 1 fi sysroot="$PWD/target/arm64-sysroot" if [ ! -e "$sysroot/usr/lib/ld-linux-aarch64.so.1" ] || [ ! -d "$sysroot/usr/lib/gcc" ]; then echo "== making the arm64 sysroot (once)" name="louise-arm64-sysroot-$$" podman run --arch arm64 --name "$name" "$IMAGE" \ sh -c 'dnf -y -q install gcc glibc-devel >/dev/null' rm -rf "$sysroot" mkdir -p "$sysroot" podman cp "$name:/usr" "$sysroot/usr" podman rm -f "$name" >/dev/null ln -sfn usr/lib64 "$sysroot/lib64" ln -sfn usr/lib "$sysroot/lib" fi cross="--target=aarch64-linux-gnu --sysroot=$sysroot" export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=clang export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C link-arg=--target=aarch64-linux-gnu -C link-arg=--sysroot=$sysroot -C link-arg=-fuse-ld=lld" export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64-static -L $sysroot" export CC_aarch64_unknown_linux_gnu=clang CFLAGS_aarch64_unknown_linux_gnu="$cross" export AR_aarch64_unknown_linux_gnu=llvm-ar # The programs the native tests build: clang for aarch64, linked by lld, # run by binfmt's qemu, which finds the dynamic loader in the sysroot. export LOUISE_CC=clang LOUISE_CFLAGS="$cross" LOUISE_LD=lld QEMU_LD_PREFIX="$sysroot" echo "== runtime unit tests (aarch64)" cargo test --quiet -p louise_rt --lib --target "$TARGET" cargo build --quiet -p louise_rt --target "$TARGET" echo "== tests/run natively (aarch64, 4 then 1 threads)" cargo test --quiet -p louise_codegen_c --test native --target "$TARGET" echo "== tests/run natively, every parked actor hibernated (aarch64)" LOUISE_PARKED_EPOCH_MS=0 cargo test --quiet -p louise_codegen_c --test native --target "$TARGET"