Skip to content

Commit

Permalink
make fuzzing deps lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-it committed Jul 26, 2024
1 parent be2f15f commit aab3c01
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
17 changes: 10 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ pub fn build(b: *std.Build) !void {
setupTestStep(b, target, superhtml);
setupCliTool(b, target, optimize, options, superhtml, folders, lsp);
setupWasmStep(b, optimize, options, superhtml, lsp);
setupFuzzStep(b, target, superhtml);
setupCheckStep(b, target, optimize, options, superhtml, folders, lsp);
if (version == .tag) {
setupReleaseStep(b, options, superhtml, folders, lsp);
}

if (b.option(
bool,
"fuzz",
"Generate an executable for AFL++ (persistent mode) plus extra tooling",
) orelse false) {
setupFuzzStep(b, target, superhtml);
}
}

fn setupCheckStep(
Expand Down Expand Up @@ -103,10 +110,6 @@ fn setupFuzzStep(
target: std.Build.ResolvedTarget,
superhtml: *std.Build.Module,
) void {
const fuzz = b.step(
"fuzz",
"Generate an executable for AFL++ (persistent mode) plus extra tooling",
);
const afl_obj = b.addObject(.{
.name = "superfuzz-afl",
.root_source_file = b.path("src/fuzz/afl.zig"),
Expand Down Expand Up @@ -134,7 +137,7 @@ fn setupFuzzStep(
});

super_fuzz.root_module.addImport("superhtml", superhtml);
fuzz.dependOn(&b.addInstallArtifact(super_fuzz, .{}).step);
b.installArtifact(super_fuzz);

const supergen = b.addExecutable(.{
.name = "supergen",
Expand All @@ -144,7 +147,7 @@ fn setupFuzzStep(
});

supergen.root_module.addImport("superhtml", superhtml);
fuzz.dependOn(&b.addInstallArtifact(supergen, .{}).step);
b.installArtifact(supergen);
}

fn setupCliTool(
Expand Down
5 changes: 3 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
.hash = "12209cde192558f8b3dc098ac2330fc2a14fdd211c5433afd33085af75caa9183147",
},
.scripty = .{
.url = "git+https://github.com/kristoff-it/scripty#141af2a88ed45a8e0fa5762ae7acddb8e747d8c9",
.hash = "12209226037051a39081e33137927031e378d76420088fd57cf0eab0fa98474456b4",
.url = "git+https://github.com/kristoff-it/scripty#3338e0ed9e1ffd869acadca9673c87894b3ba38c",
.hash = "1220a064034f7b797618a1fc5c2f3596b5dbfe4f309afd0798cfc77bbea6bb5eb672",
},
.@"zig-afl-kit" = .{
.url = "git+https://github.com/kristoff-it/zig-afl-kit#f003bfe714f2964c90939fdc940d5993190a66ec",
.hash = "1220f2d8402bb7bbc4786b9c0aad73910929ea209cbd3b063842371d68abfed33c1e",
.lazy = true,
},
},
.paths = .{
Expand Down
26 changes: 19 additions & 7 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ pub fn panic(
std.process.exit(1);
}

pub const Command = enum { fmt, lsp, help, version };
pub const Command = enum {
check,
interface,
i, // alias for interface
fmt,
lsp,
help,
version,
};

pub fn main() !void {
var gpa_impl: std.heap.GeneralPurposeAllocator(.{}) = .{};
Expand All @@ -72,10 +80,13 @@ pub fn main() !void {
if (cmd == .lsp) lsp_mode = true;

_ = switch (cmd) {
// .check => check_exe.run(gpa, args[2..]),
// .interface, .i => interface_exe.run(gpa, args[2..]),
.fmt => fmt_exe.run(gpa, args[2..]),
.lsp => lsp_exe.run(gpa, args[2..]),
.help => fatalHelp(),
.version => printVersion(),
else => fatalHelp(),
} catch |err| fatal("unexpected error: {s}\n", .{@errorName(err)});
}

Expand All @@ -95,14 +106,15 @@ fn printVersion() noreturn {

fn fatalHelp() noreturn {
fatal(
\\Usage: super COMMAND [OPTIONS]
\\Usage: superhtml COMMAND [OPTIONS]
\\
\\Commands:
// \\ check Check HTML documents for syntax errors
\\ fmt Format HTML documents
\\ lsp Start the Super LSP
\\ help Show this menu and exit
\\ version Print Super's version and exit
\\ check Check documents for syntax errors
\\ interface, i Print a SuperHTML template's interface
\\ fmt Format documents
\\ lsp Start the Super LSP
\\ help Show this menu and exit
\\ version Print Super's version and exit
\\
\\General Options:
\\ --help, -h Print command specific usage
Expand Down

0 comments on commit aab3c01

Please sign in to comment.