|
| 1 | +const std = @import("std"); |
| 2 | + |
| 3 | +pub fn build(b: *std.Build) void { |
| 4 | + const target = b.standardTargetOptions(.{}); |
| 5 | + const optimize = b.standardOptimizeOption(.{}); |
| 6 | + const version = std.SemanticVersion{ .major = 4, .minor = 21, .patch = 0 }; |
| 7 | + |
| 8 | + // Dependencies |
| 9 | + const AFLplusplus_dep = b.dependency("AFLplusplus", .{}); |
| 10 | + const AFLplusplus_src_path = AFLplusplus_dep.path("src/"); |
| 11 | + const AFLplusplus_inc_path = AFLplusplus_dep.path("include/"); |
| 12 | + |
| 13 | + // Executable suite |
| 14 | + const exes_step = b.step("exes", "Install executables"); |
| 15 | + |
| 16 | + var flags = std.BoundedArray([]const u8, 15){}; |
| 17 | + flags.appendSliceAssumeCapacity(&FLAGS); |
| 18 | + if (target.result.cpu.arch.isX86()) { |
| 19 | + flags.appendSliceAssumeCapacity(&.{ "-mavx2", "-D_HAVE_AVX2" }); |
| 20 | + } |
| 21 | + if (target.query.isNative()) { |
| 22 | + flags.appendAssumeCapacity("-march=native"); |
| 23 | + } |
| 24 | + |
| 25 | + const fuzz_exe = b.addExecutable(.{ |
| 26 | + .name = "afl-fuzz", |
| 27 | + .pic = true, |
| 28 | + .target = target, |
| 29 | + .version = version, |
| 30 | + .optimize = optimize, |
| 31 | + }); |
| 32 | + fuzz_exe.addCSourceFiles(.{ |
| 33 | + .root = AFLplusplus_src_path, |
| 34 | + .files = &(FUZZ_SOURCES ++ SHARED_SOURCES), |
| 35 | + .flags = flags.constSlice(), |
| 36 | + }); |
| 37 | + fuzz_exe.addIncludePath(AFLplusplus_inc_path); |
| 38 | + fuzz_exe.linkSystemLibrary("z"); |
| 39 | + fuzz_exe.linkLibC(); |
| 40 | + |
| 41 | + const fuzz_exe_install = b.addInstallArtifact(fuzz_exe, .{}); |
| 42 | + exes_step.dependOn(&fuzz_exe_install.step); |
| 43 | + |
| 44 | + const showmap_exe = b.addExecutable(.{ |
| 45 | + .name = "afl-showmap", |
| 46 | + .pic = true, |
| 47 | + .target = target, |
| 48 | + .version = version, |
| 49 | + .optimize = optimize, |
| 50 | + }); |
| 51 | + showmap_exe.addCSourceFiles(.{ |
| 52 | + .root = AFLplusplus_src_path, |
| 53 | + .files = &(.{ "afl-showmap.c", "afl-fuzz-mutators.c", "afl-fuzz-python.c" } ++ SHARED_SOURCES), |
| 54 | + .flags = flags.constSlice(), |
| 55 | + }); |
| 56 | + showmap_exe.addIncludePath(AFLplusplus_inc_path); |
| 57 | + showmap_exe.linkSystemLibrary("z"); |
| 58 | + showmap_exe.linkLibC(); |
| 59 | + |
| 60 | + const showmap_exe_install = b.addInstallArtifact(showmap_exe, .{}); |
| 61 | + exes_step.dependOn(&showmap_exe_install.step); |
| 62 | + |
| 63 | + const tmin_exe = b.addExecutable(.{ |
| 64 | + .name = "afl-tmin", |
| 65 | + .pic = true, |
| 66 | + .target = target, |
| 67 | + .version = version, |
| 68 | + .optimize = optimize, |
| 69 | + }); |
| 70 | + tmin_exe.addCSourceFiles(.{ |
| 71 | + .root = AFLplusplus_src_path, |
| 72 | + .files = &(.{"afl-tmin.c"} ++ SHARED_SOURCES), |
| 73 | + .flags = flags.constSlice(), |
| 74 | + }); |
| 75 | + tmin_exe.addIncludePath(AFLplusplus_inc_path); |
| 76 | + tmin_exe.linkSystemLibrary("z"); |
| 77 | + tmin_exe.linkLibC(); |
| 78 | + |
| 79 | + const tmin_exe_install = b.addInstallArtifact(tmin_exe, .{}); |
| 80 | + exes_step.dependOn(&tmin_exe_install.step); |
| 81 | + |
| 82 | + const analyze_exe = b.addExecutable(.{ |
| 83 | + .name = "afl-analyze", |
| 84 | + .pic = true, |
| 85 | + .target = target, |
| 86 | + .version = version, |
| 87 | + .optimize = optimize, |
| 88 | + }); |
| 89 | + analyze_exe.addCSourceFiles(.{ |
| 90 | + .root = AFLplusplus_src_path, |
| 91 | + .files = &(.{"afl-analyze.c"} ++ SHARED_SOURCES), |
| 92 | + .flags = flags.constSlice(), |
| 93 | + }); |
| 94 | + analyze_exe.addIncludePath(AFLplusplus_inc_path); |
| 95 | + analyze_exe.linkSystemLibrary("z"); |
| 96 | + analyze_exe.linkLibC(); |
| 97 | + |
| 98 | + const analyze_exe_install = b.addInstallArtifact(analyze_exe, .{}); |
| 99 | + exes_step.dependOn(&analyze_exe_install.step); |
| 100 | + |
| 101 | + const gotcpu_exe = b.addExecutable(.{ |
| 102 | + .name = "afl-gotcpu", |
| 103 | + .pic = true, |
| 104 | + .target = target, |
| 105 | + .version = version, |
| 106 | + .optimize = optimize, |
| 107 | + }); |
| 108 | + gotcpu_exe.addCSourceFiles(.{ |
| 109 | + .root = AFLplusplus_src_path, |
| 110 | + .files = &.{ "afl-gotcpu.c", "afl-common.c" }, |
| 111 | + .flags = flags.constSlice(), |
| 112 | + }); |
| 113 | + gotcpu_exe.addIncludePath(AFLplusplus_inc_path); |
| 114 | + gotcpu_exe.linkSystemLibrary("z"); |
| 115 | + gotcpu_exe.linkLibC(); |
| 116 | + |
| 117 | + const gotcpu_exe_install = b.addInstallArtifact(gotcpu_exe, .{}); |
| 118 | + exes_step.dependOn(&gotcpu_exe_install.step); |
| 119 | + |
| 120 | + const as_exe = b.addExecutable(.{ |
| 121 | + .name = "afl-as", |
| 122 | + .pic = true, |
| 123 | + .target = target, |
| 124 | + .version = version, |
| 125 | + .optimize = optimize, |
| 126 | + }); |
| 127 | + as_exe.addCSourceFiles(.{ |
| 128 | + .root = AFLplusplus_src_path, |
| 129 | + .files = &.{"afl-as.c"}, |
| 130 | + .flags = flags.constSlice(), |
| 131 | + }); |
| 132 | + as_exe.addIncludePath(AFLplusplus_inc_path); |
| 133 | + as_exe.linkSystemLibrary("z"); |
| 134 | + as_exe.linkLibC(); |
| 135 | + |
| 136 | + const as_exe_install = b.addInstallArtifact(as_exe, .{}); |
| 137 | + exes_step.dependOn(&as_exe_install.step); |
| 138 | + |
| 139 | + b.default_step.dependOn(exes_step); |
| 140 | + |
| 141 | + // Formatting checks |
| 142 | + const fmt_step = b.step("fmt", "Run formatting checks"); |
| 143 | + |
| 144 | + const fmt = b.addFmt(.{ |
| 145 | + .paths = &.{ |
| 146 | + "build.zig", |
| 147 | + }, |
| 148 | + .check = true, |
| 149 | + }); |
| 150 | + fmt_step.dependOn(&fmt.step); |
| 151 | + b.default_step.dependOn(fmt_step); |
| 152 | +} |
| 153 | + |
| 154 | +const FUZZ_SOURCES = .{ |
| 155 | + "afl-fuzz-bitmap.c", |
| 156 | + "afl-fuzz-cmplog.c", |
| 157 | + "afl-fuzz-extras.c", |
| 158 | + "afl-fuzz-init.c", |
| 159 | + "afl-fuzz-mutators.c", |
| 160 | + "afl-fuzz-one.c", |
| 161 | + "afl-fuzz-python.c", |
| 162 | + "afl-fuzz-queue.c", |
| 163 | + "afl-fuzz-redqueen.c", |
| 164 | + "afl-fuzz-run.c", |
| 165 | + "afl-fuzz-skipdet.c", |
| 166 | + "afl-fuzz-state.c", |
| 167 | + "afl-fuzz-stats.c", |
| 168 | + "afl-fuzz-statsd.c", |
| 169 | + "afl-fuzz.c", |
| 170 | +}; |
| 171 | + |
| 172 | +const SHARED_SOURCES = .{ |
| 173 | + "afl-performance.c", |
| 174 | + "afl-common.c", |
| 175 | + "afl-forkserver.c", |
| 176 | + "afl-sharedmem.c", |
| 177 | +}; |
| 178 | + |
| 179 | +const FLAGS = .{ |
| 180 | + "-O2", |
| 181 | + "-g", |
| 182 | + "-Wno-pointer-sign", |
| 183 | + "-Wno-variadic-macros", |
| 184 | + "-Wall", |
| 185 | + "-Wextra", |
| 186 | + "-Wno-pointer-arith", |
| 187 | + "-D_AFL_SPECIAL_PERFORMANCE", |
| 188 | + "-DHAVE_ZLIB", |
| 189 | + "-DAFL_PATH=\"\"", |
| 190 | + "-DBIN_PATH=\"\"", |
| 191 | + "-DDOC_PATH=\"\"", |
| 192 | +}; |
0 commit comments