2# Regenerate results/arm64_benchmark.json: cross-build liboqs for aarch64 (ML-KEM-768, static,
3# no OpenSSL), compile bench_liboqs.c against it, run under qemu-aarch64, write the full JSON.
4# Every number in the output is measured by bench_liboqs.c; this script only drives the build.
5# Missing tools are a hard error naming the fix, never a silent fallback.
7# Usage (from the repository root, on an x86-64 Linux/WSL host):
8# code/c/build_arm64_benchmark.sh [output.json] [budget_sec] [liboqs_version] [n_runs]
9# Defaults: results/arm64_benchmark.json, 1.0 s per op, liboqs 0.15.0, 20 runs.
10# The binary is run n_runs times and reduced to mean +/- 95% CI by arm64_aggregate.py.
13OUT=
"${1:-results/arm64_benchmark.json}"
18HERE=
"$(cd "$(dirname
"${BASH_SOURCE[0]}")
" && pwd)"
19REPO=
"$(cd "$HERE/../..
" && pwd)"
20# Build tree lives outside the repo (overridable) so a run leaves git status clean; a stable
21# path lets repeat runs skip the liboqs rebuild.
22BUILD=
"${ARM64_BUILD_DIR:-$HOME/.cache/pqwbkem_arm64_build}"
24PREFIX=
"$BUILD/install-aarch64"
25TC=
"$BUILD/aarch64-toolchain.cmake"
26HARNESS=
"$HERE/bench_liboqs.c"
27BIN=
"$BUILD/bench_liboqs_arm64"
29need() { command -v
"$1" >/dev/null 2>&1 || { echo
"ERROR: '$1' not found. $2" >&2; exit 1; }; }
30need aarch64-linux-gnu-gcc
"Install with: sudo apt-get install -y gcc-aarch64-linux-gnu"
31need qemu-aarch64
"Install with: sudo apt-get install -y qemu-user qemu-user-static"
32need cmake
"Install with: sudo apt-get install -y cmake"
33need ninja
"Install with: sudo apt-get install -y ninja-build"
34need git
"Install with: sudo apt-get install -y git"
38if [ ! -
f "$PREFIX/lib/liboqs.a" ]; then
39 [ -d
"$SRC" ] || git clone --depth 1 --branch
"$OQS_VER" \
43set(CMAKE_SYSTEM_NAME Linux)
44set(CMAKE_SYSTEM_PROCESSOR aarch64)
45set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
46set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
47set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
48set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
49set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
52 cmake -S "$SRC" -B "$SRC/build" -GNinja \
53 -DCMAKE_TOOLCHAIN_FILE="$TC" \
54 -DCMAKE_BUILD_TYPE=Release \
55 -DOQS_USE_OPENSSL=OFF \
56 -DOQS_BUILD_ONLY_LIB=ON \
57 -DOQS_MINIMAL_BUILD="KEM_ml_kem_768" \
58 -DCMAKE_INSTALL_PREFIX="$PREFIX" \
61 ninja -C "$SRC/build" install
64GCC_VER="$(aarch64-linux-gnu-gcc -dumpfullversion)"
66aarch64-linux-gnu-gcc -O3 -static -o "$BIN" "$HARNESS" \
67 -I "$PREFIX/include" -L "$PREFIX/lib" \
68 -DBENCH_COMPILER="\"gcc $GCC_VER\"" \
69 -DBENCH_TARGET="\"aarch64-Linux\"" \
70 -DBENCH_PLATFORM="\"ARM64 (QEMU emulation)\"" \
74mkdir -p "$(dirname "$REPO/$OUT")" 2>/dev/null || true