aboutsummaryrefslogtreecommitdiffstats
path: root/build.zig
blob: 947511bbbdfb87960319fefff1907e7ffa6f4b7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const std = @import("std");

pub fn build(b: *std.build.Builder) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const lib_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    const run_lib_tests = b.addRunArtifact(lib_tests);

    const test_step = b.step("test", "Run library tests");
    test_step.dependOn(&run_lib_tests.step);

    const znk_version = "0.2.1";

    const znk_options = b.addOptions();
    znk_options.addOption([]const u8, "version", znk_version);

    const nkeys_module = b.addModule("nkeys", .{
        .source_file = .{ .path = "src/main.zig" },
    });

    const znk_tests = b.addTest(.{
        .root_source_file = .{ .path = "tool/znk.zig" },
        .target = target,
        .optimize = optimize,
    });
    znk_tests.addModule("nkeys", nkeys_module);
    znk_tests.addOptions("build_options", znk_options);
    const run_znk_tests = b.addRunArtifact(znk_tests);

    const znk_test_step = b.step("test-znk", "Run znk tests");
    znk_test_step.dependOn(&run_znk_tests.step);

    const znk = b.addExecutable(.{
        .name = "znk",
        .root_source_file = .{ .path = "tool/znk.zig" },
        .target = target,
        .optimize = optimize,
    });
    znk.addModule("nkeys", nkeys_module);
    znk.addOptions("build_options", znk_options);

    b.installArtifact(znk);

    const znk_step = b.step("znk", "Build znk");
    znk_step.dependOn(b.getInstallStep());

    const znk_run_cmd = b.addRunArtifact(znk);
    znk_run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        znk_run_cmd.addArgs(args);
    }

    const znk_run_step = b.step("run-znk", "Run znk");
    znk_run_step.dependOn(&znk_run_cmd.step);
}