#!/bin/bash
# Copyright 2023 - 2025, project-repo and the cagebreak contributors
# SPDX-License-Identifier: MIT

readonly fuzzing_corpus="${1}"

if [[ -n ${MESON_SOURCE_ROOT} ]]
then
	# shellcheck disable=2164
	cd "${MESON_SOURCE_ROOT}"
fi

rm -rf fuzzing-directory
CC=clang CCXFLAGS=-std=c11 meson setup fuzzing-directory -Dfuzz=true -Db_sanitize=address,undefined -Db_lundef=false
ninja -C fuzzing-directory/
WLR_BACKENDS=headless ./fuzzing-directory/fuzz-parse -detect_leaks=0 -jobs=12 -max_len=50000 -close_fd_mask=3 "${fuzzing_corpus}"
rm -rf fuzzing-directory
