1const std = @import("std");
2
3pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{});
5 const mode = b.option(std.builtin.OptimizeMode, "mode", "") orelse .Debug;
6 const disable_llvm = b.option(bool, "disable_llvm", "use the non-llvm zig codegen") orelse false;
7
8 const exe = b.addExecutable(.{
9 .name = "zig-ansi",
10 .root_module = b.createModule(.{
11 .root_source_file = b.path("src/main.zig"),
12 .target = target,
13 .optimize = mode,
14 }),
15 });
16 exe.use_llvm = !disable_llvm;
17 exe.use_lld = !disable_llvm;
18 b.installArtifact(exe);
19
20 const run_cmd = b.addRunArtifact(exe);
21 run_cmd.step.dependOn(b.getInstallStep());
22 if (b.args) |args| {
23 run_cmd.addArgs(args);
24 }
25
26 const run_step = b.step("run", "Run the app");
27 run_step.dependOn(&run_cmd.step);
28
29 const tests = b.addTest(.{
30 .root_module = b.createModule(.{
31 .root_source_file = b.path("src/test.zig"),
32 .target = target,
33 .optimize = mode,
34 }),
35 });
36 tests.use_llvm = !disable_llvm;
37 tests.use_lld = !disable_llvm;
38 b.getInstallStep().dependOn(&tests.step);
39
40 const run_test = b.addRunArtifact(tests);
41 run_test.setCwd(b.path("."));
42 run_test.has_side_effects = true;
43
44 const test_step = b.step("test", "Run all library tests");
45 test_step.dependOn(&run_test.step);
46}