From 387db22fb347b1dfa8b4914a88ec254c8c6d5919 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 20 Sep 2023 15:59:28 -0700 Subject: [PATCH] test all backends --- build.zig | 9 ++++++++- src/main.zig | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 5e0595221ab3cbfb04f4403800716d9161e2218b..8873db880ca772dd209fcb20bda1b0a4965498cf 100644 --- a/build.zig +++ b/build.zig @@ -6,11 +6,18 @@ pub fn build(b: *std.Build) void { const mod = b.addModule("tracer", .{ .source_file = .{ .path = "src/mod.zig" } }); + addTest(b, target, mode, mod, 0); + addTest(b, target, mode, mod, 1); + addTest(b, target, mode, mod, 2); +} + +fn addTest(b: *std.Build, target: std.zig.CrossTarget, mode: std.builtin.Mode, mod: *std.build.Module, comptime backend: u8) void { const options = b.addOptions(); options.addOption(usize, "src_file_trimlen", std.fs.path.dirname(std.fs.path.dirname(@src().file).?).?.len); + options.addOption(u8, "backend", backend); const exe = b.addExecutable(.{ - .name = "test", + .name = "test" ++ std.fmt.comptimePrint("{d}", .{backend}), .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = mode, diff --git a/src/main.zig b/src/main.zig index b78557d482999d07cfc3395a35b688b97a75d644..6c8e7c9b6795607975c2c193029f0ad9db36d213 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,7 +2,12 @@ const std = @import("std"); const tracer = @import("tracer"); pub const build_options = @import("build_options"); -pub const tracer_impl = tracer.spall; +pub const tracer_impl = switch (build_options.backend) { + 0 => tracer.none, + 1 => tracer.log, + 2 => tracer.spall, + else => unreachable, +}; pub fn main() !void { try tracer.init(); -- 2.54.0