|
1 | | -#!/bin/bash |
| 1 | +#!/usr/bin/env bash |
2 | 2 | # SPDX-License-Identifier: MPL-2.0 |
3 | | -# Build script for ClusterFuzzLite fuzzing |
| 3 | +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 4 | +# |
| 5 | +# ClusterFuzzLite build script. Builds libproven via Zig (which compiles |
| 6 | +# Idris2 RefC output) and then builds the cargo-fuzz targets that link |
| 7 | +# against it. |
| 8 | +# |
| 9 | +# Runs inside the ClusterFuzzLite container (see Dockerfile). Outputs |
| 10 | +# the fuzz target binaries to $OUT, the path the runner expects. |
| 11 | +# |
| 12 | +# Replaces the prior Zig-only build that pointed at a non-existent |
| 13 | +# `proven/fuzz/zig/` directory. The Rust bindings are the natural FFI |
| 14 | +# fuzz surface: panic safety + allocator handling are exactly what |
| 15 | +# libFuzzer is good at. |
4 | 16 |
|
5 | | -cd "$SRC"/proven/fuzz/zig |
| 17 | +set -euo pipefail |
6 | 18 |
|
7 | | -# Build fuzz targets with Zig |
8 | | -# Note: Zig produces native binaries compatible with libFuzzer |
| 19 | +echo "=== ClusterFuzzLite build: proven ===" |
9 | 20 |
|
10 | | -for target in fuzz_*.zig; do |
11 | | - name="${target%.zig}" |
12 | | - zig build-exe "$target" \ |
13 | | - -O ReleaseSafe \ |
14 | | - -fno-stack-check \ |
15 | | - -target x86_64-linux-gnu \ |
16 | | - --name "$name" \ |
17 | | - -lc |
| 21 | +# Build libproven via the Zig FFI bridge. The container has Idris2 + Zig |
| 22 | +# baked in; this step compiles Idris2 → C → libproven.so. |
| 23 | +if [[ -f ffi/zig/build.zig ]]; then |
| 24 | + pushd ffi/zig >/dev/null |
| 25 | + zig build || { |
| 26 | + echo "WARN: Zig FFI build failed; fuzz targets will not link." >&2 |
| 27 | + echo " Investigate libproven build before re-running." >&2 |
| 28 | + exit 1 |
| 29 | + } |
| 30 | + popd >/dev/null |
| 31 | +fi |
18 | 32 |
|
19 | | - cp "$name" $OUT/ |
| 33 | +# Make libproven discoverable to the cargo-fuzz linker. |
| 34 | +export PROVEN_LIB_DIR="$PWD/ffi/zig/zig-out/lib" |
| 35 | +export LD_LIBRARY_PATH="$PROVEN_LIB_DIR:${LD_LIBRARY_PATH:-}" |
| 36 | + |
| 37 | +# Build cargo-fuzz targets and stage them at $OUT (ClusterFuzzLite |
| 38 | +# convention; runner reads from there). |
| 39 | +pushd bindings/rust/fuzz >/dev/null |
| 40 | +cargo fuzz build -O --debug-assertions |
| 41 | + |
| 42 | +# Copy each compiled fuzzer + libproven.so into $OUT. |
| 43 | +TARGETS_DIR="target/x86_64-unknown-linux-gnu/release" |
| 44 | +for fuzzer in safe_url_parse safe_email_is_valid safe_json_is_valid safe_path_has_traversal; do |
| 45 | + if [[ -f "$TARGETS_DIR/$fuzzer" ]]; then |
| 46 | + cp "$TARGETS_DIR/$fuzzer" "$OUT/" |
| 47 | + else |
| 48 | + echo "WARN: missing fuzz binary $fuzzer (build failed)" >&2 |
| 49 | + fi |
20 | 50 | done |
21 | 51 |
|
22 | | -echo "Fuzz targets built successfully" |
| 52 | +# Bundle libproven.so so the runner can find it at exec time. |
| 53 | +mkdir -p "$OUT/lib" |
| 54 | +if [[ -f "$PROVEN_LIB_DIR/libproven.so" ]]; then |
| 55 | + cp "$PROVEN_LIB_DIR/libproven.so" "$OUT/lib/" |
| 56 | +fi |
| 57 | +popd >/dev/null |
| 58 | + |
| 59 | +echo "=== Build complete. Staged to $OUT. ===" |
0 commit comments