diff --git a/build.zig b/build.zig index 5aef0225..9ea6126f 100644 --- a/build.zig +++ b/build.zig @@ -10,8 +10,11 @@ pub fn build(b: *std.build.Builder) !void { const src_path = "src/libsodium"; const src_dir = try fs.Dir.openIterableDir(fs.cwd(), src_path, .{ .no_follow = true }); - var target = b.standardTargetOptions(.{}); - var mode = b.standardReleaseOptions(); + const target = b.standardTargetOptions(.{}); + const mode = b.standardReleaseOptions(); + + const enable_benchmarks = b.option(bool, "enable_benchmarks", "Whether tests should be benchmarks.") orelse false; + const benchmarks_iterations = b.option(u32, "iterations", "Number of iterations for benchmarks.") orelse 200; const static = b.addStaticLibrary("sodium", null); const shared = b.addSharedLibrary("sodium", null, .unversioned); @@ -216,6 +219,13 @@ pub fn build(b: *std.build.Builder) !void { const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ test_path, entry.path }); exe.addCSourceFiles(&.{full_path}, &.{}); exe.strip = true; + + if (enable_benchmarks) { + exe.defineCMacro("BENCHMARKS", "1"); + var buf: [16]u8 = undefined; + exe.defineCMacro("ITERATIONS", std.fmt.bufPrintIntToSlice(&buf, benchmarks_iterations, 10, .lower, .{})); + } + exe.install(); } }