1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-24 04:25:10 -07:00

Add the ability to convert tests into benchmarks

This commit is contained in:
Frank Denis 2022-12-17 21:36:15 +01:00
parent 6aa4e8c240
commit 1ff1396283

View File

@ -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();
}
}