summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2024-12-08 12:35:00 +0100
committerGravatar Vincent Rischmann2024-12-08 12:35:00 +0100
commit7fdaabd31db62b57ea663964a14904f558352589 (patch)
tree6bf02399af8f1d976e4e7ebc0b3eb8b5d0e7b00e /build.zig
parentMerge pull request #170 from vrischmann/ci-ubuntu-2404 (diff)
parentadd a fuzz test (diff)
downloadzig-sqlite-7fdaabd31db62b57ea663964a14904f558352589.tar.gz
zig-sqlite-7fdaabd31db62b57ea663964a14904f558352589.tar.xz
zig-sqlite-7fdaabd31db62b57ea663964a14904f558352589.zip
Merge branch 'fuzzing'
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig48
1 files changed, 0 insertions, 48 deletions
diff --git a/build.zig b/build.zig
index b851865..3b990ff 100644
--- a/build.zig
+++ b/build.zig
@@ -242,8 +242,6 @@ pub fn build(b: *std.Build) !void {
242 test_step.dependOn(&run_tests.step); 242 test_step.dependOn(&run_tests.step);
243 } 243 }
244 244
245 // Fuzzing
246
247 const lib = b.addStaticLibrary(.{ 245 const lib = b.addStaticLibrary(.{
248 .name = "sqlite", 246 .name = "sqlite",
249 .target = getTarget(target, true), 247 .target = getTarget(target, true),
@@ -253,52 +251,6 @@ pub fn build(b: *std.Build) !void {
253 lib.addIncludePath(b.path("c")); 251 lib.addIncludePath(b.path("c"));
254 lib.linkLibC(); 252 lib.linkLibC();
255 253
256 // The library
257 const fuzz_lib = b.addStaticLibrary(.{
258 .name = "fuzz-lib",
259 .root_source_file = b.path("fuzz/main.zig"),
260 .target = getTarget(target, true),
261 .optimize = optimize,
262 });
263 fuzz_lib.addIncludePath(b.path("c"));
264 fuzz_lib.linkLibrary(lib);
265 fuzz_lib.want_lto = true;
266 fuzz_lib.bundle_compiler_rt = true;
267 fuzz_lib.root_module.addImport("sqlite", sqlite_mod);
268
269 // Setup the output name
270 const fuzz_executable_name = "fuzz";
271 const fuzz_exe_path = try b.cache_root.join(b.allocator, &.{fuzz_executable_name});
272
273 // We want `afl-clang-lto -o path/to/output path/to/library`
274 const fuzz_compile = b.addSystemCommand(&.{ "afl-clang-lto", "-o", fuzz_exe_path });
275 fuzz_compile.addArtifactArg(lib);
276 fuzz_compile.addArtifactArg(fuzz_lib);
277
278 // Install the cached output to the install 'bin' path
279 const fuzz_install = b.addInstallBinFile(.{ .cwd_relative = fuzz_exe_path }, fuzz_executable_name);
280
281 // Add a top-level step that compiles and installs the fuzz executable
282 const fuzz_compile_run = b.step("fuzz", "Build executable for fuzz testing using afl-clang-lto");
283 // fuzz_compile_run.dependOn(&fuzz_lib.step);
284 fuzz_compile_run.dependOn(&fuzz_compile.step);
285 fuzz_compile_run.dependOn(&fuzz_install.step);
286
287 // Compile a companion exe for debugging crashes
288 const fuzz_debug_exe = b.addExecutable(.{
289 .name = "fuzz-debug",
290 .root_source_file = b.path("fuzz/main.zig"),
291 .target = getTarget(target, true),
292 .optimize = optimize,
293 });
294 fuzz_debug_exe.addIncludePath(b.path("c"));
295 fuzz_debug_exe.linkLibrary(lib);
296 fuzz_debug_exe.root_module.addImport("sqlite", sqlite_mod);
297
298 // Only install fuzz-debug when the fuzz step is run
299 const install_fuzz_debug_exe = b.addInstallArtifact(fuzz_debug_exe, .{});
300 fuzz_compile_run.dependOn(&install_fuzz_debug_exe.step);
301
302 // 254 //
303 // Examples 255 // Examples
304 // 256 //