From b5c2d80f57a2fd0909f2061e30505e94281318ec Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 10 Apr 2024 17:37:46 -0500 Subject: [PATCH] build: add build flag for example --- build.zig | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/build.zig b/build.zig index 1235047..77a5897 100644 --- a/build.zig +++ b/build.zig @@ -30,19 +30,21 @@ pub fn build(b: *std.Build) void { vaxis_mod.addImport("gap_buffer", gap_buffer_dep.module("gap_buffer")); // Examples - const text_input_step = b.step("examples/text_input", "Run text_input.zig"); - - const text_input = b.addExecutable(.{ - .name = "text_input", - // Change this to the example you want to use! - .root_source_file = std.Build.LazyPath.relative("examples/text_input.zig"), + const Example = enum { image, main, pathological, table, text_input }; + const example_option = b.option(Example, "example", "Example to run (default: text_input)") orelse .text_input; + const example_step = b.step("example", "Run example"); + const example = b.addExecutable(.{ + .name = "example", + // future versions should use b.path, see zig PR #19597 + .root_source_file = std.Build.LazyPath.relative( + b.fmt("examples/{s}.zig", .{@tagName(example_option)}), + ), .target = target, .optimize = optimize, }); - text_input.root_module.addImport("vaxis", vaxis_mod); - - const text_input_run = b.addRunArtifact(text_input); - text_input_step.dependOn(&text_input_run.step); + example.root_module.addImport("vaxis", vaxis_mod); + const example_run = b.addRunArtifact(example); + example_step.dependOn(&example_run.step); // Tests const tests_step = b.step("test", "Run tests");