#!/usr/bin/env bash # Build louise_rt as a staticlib and run the M0 ABI spike against it. # Usage: scripts/spike.sh [--release] [--asan] set -euo pipefail root="$(cd "$(dirname "$0")/.." && pwd)" profile=debug cargo_flags=() cflags=(-O2) target="$root/target" for arg in "$@"; do case "$arg" in --release) profile=release cargo_flags+=(--release) ;; --asan) cflags=(-O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer) # ASan sees only the system allocator's blocks: build the runtime # without mimalloc, apart from the usual one. target="$root/target/sanitize" cargo_flags+=(--no-default-features --features stats --target-dir "$target") ;; *) echo "unknown flag: $arg" >&2; exit 64 ;; esac done # CARGO_TARGET_DIR relocates the build (ci.sh isolates the release # spike's and sweeps it: peak disk on a bounded runner store). --asan # already has its own. if [ -n "${CARGO_TARGET_DIR:-}" ] && [ "$target" = "$root/target" ]; then case "$CARGO_TARGET_DIR" in /*) target="$CARGO_TARGET_DIR" ;; *) target="$root/$CARGO_TARGET_DIR" ;; esac cargo_flags+=(--target-dir "$target") fi cargo build --quiet -p louise_rt "${cargo_flags[@]}" --manifest-path "$root/Cargo.toml" mkdir -p "$root/build" cc="${CC:-cc}" [[ " ${cflags[*]} " == *sanitize* && -z "${CC:-}" ]] && cc=clang # gcc often lacks libasan "$cc" -std=c11 -Wall -Wextra -Werror "${cflags[@]}" \ -I "$root/runtime/louise_rt/include" \ "$root/runtime/spike/spike.c" "$target/$profile/liblouise_rt.a" \ -lpthread -ldl -lm -o "$root/build/spike" "$root/build/spike"