pkg/afl++: extract runner

This commit is contained in:
Mitchell Hashimoto
2026-02-28 20:26:36 -08:00
parent 54bdbdf87d
commit afabbaf012
2 changed files with 25 additions and 14 deletions

View File

@@ -30,6 +30,30 @@ pub fn addInstrumentedExe(
return fuzz_exe;
}
/// Creates a run step that invokes `afl-fuzz` with the given instrumented
/// executable, input corpus directory, and output directory.
///
/// Returns the `Run` step so callers can wire it into a build step.
pub fn addFuzzerRun(
b: *std.Build,
exe: std.Build.LazyPath,
corpus_dir: std.Build.LazyPath,
output_dir: std.Build.LazyPath,
) *std.Build.Step.Run {
const run = b.addSystemCommand(&.{
b.findProgram(&.{"afl-fuzz"}, &.{}) catch
@panic("Could not find 'afl-fuzz', which is required to run"),
"-i",
});
run.addDirectoryArg(corpus_dir);
run.addArgs(&.{"-o"});
run.addDirectoryArg(output_dir);
run.addArgs(&.{"--"});
run.addFileArg(exe);
run.addArgs(&.{"@@"});
return run;
}
// Required so `zig build` works although it does nothing.
pub fn build(b: *std.Build) !void {
_ = b;

View File

@@ -44,20 +44,7 @@ pub fn build(b: *std.Build) void {
const exe = afl.addInstrumentedExe(b, lib);
// Runner to simplify running afl-fuzz
const run = run: {
const run = b.addSystemCommand(&.{
b.findProgram(&.{"afl-fuzz"}, &.{}) catch
@panic("Could not find 'afl-fuzz', which is required to run"),
"-i",
});
run.addDirectoryArg(b.path("corpus/initial"));
run.addArgs(&.{"-o"});
run.addDirectoryArg(b.path("afl-out"));
run.addArgs(&.{"--"});
run.addFileArg(exe);
run.addArgs(&.{"@@"});
break :run run;
};
const run = afl.addFuzzerRun(b, exe, b.path("corpus/initial"), b.path("afl-out"));
// Install
b.installArtifact(lib);