mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-19 22:10:29 +00:00
Clean up how fuzzers are laid out
This commit is contained in:
@@ -1,69 +1,72 @@
|
||||
const std = @import("std");
|
||||
const afl = @import("afl");
|
||||
|
||||
const FuzzTarget = struct {
|
||||
/// Possible fuzz targets. Each fuzz target is implemented in
|
||||
/// src/fuzz_<name>.zig and has an initial corpus in corpus/<name>-initial.
|
||||
const Fuzzer = struct {
|
||||
name: []const u8,
|
||||
source: []const u8,
|
||||
corpus: []const u8,
|
||||
|
||||
pub fn source(comptime self: Fuzzer) []const u8 {
|
||||
return "src/fuzz_" ++ self.name ++ ".zig";
|
||||
}
|
||||
|
||||
pub fn corpus(comptime self: Fuzzer) []const u8 {
|
||||
// Change this suffix to use cmin vs initial corpus
|
||||
return "corpus/" ++ self.name ++ "-initial";
|
||||
}
|
||||
};
|
||||
|
||||
const fuzz_targets = [_]FuzzTarget{
|
||||
.{
|
||||
.name = "fuzz-vt-parser",
|
||||
.source = "src/fuzz_vt_parser.zig",
|
||||
.corpus = "corpus/vt-parser-cmin",
|
||||
},
|
||||
.{
|
||||
.name = "fuzz-vt-stream",
|
||||
.source = "src/fuzz_vt_stream.zig",
|
||||
.corpus = "corpus/vt-stream-initial",
|
||||
},
|
||||
const fuzzers: []const Fuzzer = &.{
|
||||
.{ .name = "parser" },
|
||||
.{ .name = "stream" },
|
||||
};
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const run_step = b.step("run", "Run the default fuzzer (vt-parser) with afl-fuzz");
|
||||
|
||||
const ghostty_dep = b.lazyDependency("ghostty", .{
|
||||
.simd = false,
|
||||
});
|
||||
|
||||
for (fuzz_targets, 0..) |fuzz, i| {
|
||||
const target_run_step = b.step(
|
||||
b.fmt("run-{s}", .{fuzz.name}),
|
||||
b.fmt("Run {s} with afl-fuzz", .{fuzz.name}),
|
||||
inline for (fuzzers) |fuzzer| {
|
||||
const run_step = b.step(
|
||||
b.fmt("run-{s}", .{fuzzer.name}),
|
||||
b.fmt("Run {s} with afl-fuzz", .{fuzzer.name}),
|
||||
);
|
||||
|
||||
const lib_mod = b.createModule(.{
|
||||
.root_source_file = b.path(fuzz.source),
|
||||
.root_source_file = b.path(fuzzer.source()),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
if (ghostty_dep) |dep| {
|
||||
lib_mod.addImport("ghostty-vt", dep.module("ghostty-vt"));
|
||||
lib_mod.addImport(
|
||||
"ghostty-vt",
|
||||
dep.module("ghostty-vt"),
|
||||
);
|
||||
}
|
||||
|
||||
const lib = b.addLibrary(.{
|
||||
.name = fuzz.name,
|
||||
.name = fuzzer.name,
|
||||
.root_module = lib_mod,
|
||||
});
|
||||
lib.root_module.stack_check = false;
|
||||
lib.root_module.fuzz = true;
|
||||
|
||||
const exe = afl.addInstrumentedExe(b, lib);
|
||||
const run = afl.addFuzzerRun(
|
||||
b,
|
||||
exe,
|
||||
b.path(fuzzer.corpus()),
|
||||
b.path(b.fmt("afl-out/{s}", .{fuzzer.name})),
|
||||
);
|
||||
run_step.dependOn(&run.step);
|
||||
|
||||
const run = afl.addFuzzerRun(b, exe, b.path(fuzz.corpus), b.path(b.fmt("afl-out/{s}", .{fuzz.name})));
|
||||
|
||||
b.installArtifact(lib);
|
||||
const exe_install = b.addInstallBinFile(exe, fuzz.name);
|
||||
const exe_install = b.addInstallBinFile(
|
||||
exe,
|
||||
"fuzz-" ++ fuzzer.name,
|
||||
);
|
||||
b.getInstallStep().dependOn(&exe_install.step);
|
||||
|
||||
target_run_step.dependOn(&run.step);
|
||||
|
||||
// Default `zig build run` runs the first target (vt-parser)
|
||||
if (i == 0) {
|
||||
run_step.dependOn(&run.step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user