aboutsummaryrefslogtreecommitdiff
path: root/build.zig
blob: 989f6c43a64f7e8ad95e19deb55320a75e1e38c5 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const std = @import("std");

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

    const sqlite_c = b.addTranslateC(.{
        .root_source_file = b.path("src/db/sqlite.h"),
        .target = target,
        .optimize = optimize,
    });
    sqlite_c.linkSystemLibrary("sqlite3", .{});

    const db_mod = b.addModule("db", .{
        .root_source_file = b.path("src/db/root.zig"),
        .target = target,
    });
    db_mod.addImport("sqlite", sqlite_c.createModule());

    const api_mod = b.addModule("api", .{
        .root_source_file = b.path("src/api/root.zig"),
        .target = target,
    });

    const html_mod = b.addModule("html", .{
        .root_source_file = b.path("src/html/root.zig"),
        .target = target,
    });

    const z_mod = b.addModule("z", .{
        .root_source_file = b.path("src/z/root.zig"),
        .target = target,
    });
    z_mod.addImport("html", html_mod);

    const http_mod = b.addModule("http", .{
        .root_source_file = b.path("src/http/root.zig"),
        .target = target,
    });

    api_mod.addImport("http", http_mod);

    const exe = b.addExecutable(.{
        .name = "memora",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{
                .{ .name = "db", .module = db_mod },
                .{ .name = "api", .module = api_mod },
                .{ .name = "z", .module = z_mod },
                .{ .name = "html", .module = html_mod },
                .{ .name = "http", .module = http_mod },
            }
        }),
    });

    b.installArtifact(exe);

    const run_step = b.step("run", "Run the app");


    const run_cmd = b.addRunArtifact(exe);
    run_step.dependOn(&run_cmd.step);
    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const db_tests = b.addTest(.{
        .root_module = db_mod,
    });
    const run_db_tests = b.addRunArtifact(db_tests);
    const db_test_step = b.step("test-db", "Run database tests");
    db_test_step.dependOn(&run_db_tests.step);


    const api_tests = b.addTest(.{
        .root_module = api_mod,
    });
    const run_api_tests = b.addRunArtifact(api_tests);
    const api_test_step = b.step("test-api", "Run api tests");
    api_test_step.dependOn(&run_api_tests.step);


    const z_tests = b.addTest(.{
        .root_module = z_mod,
    });
    const run_z_tests = b.addRunArtifact(z_tests);
    const z_test_step = b.step("test-z", "Run z tests");
    z_test_step.dependOn(&run_z_tests.step);

    const html_tests = b.addTest(.{
        .root_module = html_mod,
    });
    const run_html_tests = b.addRunArtifact(html_tests);
    const html_test_step = b.step("test-html", "Run html tests");
    html_test_step.dependOn(&run_html_tests.step);


    const http_tests = b.addTest(.{
        .root_module = http_mod,
    });
    const run_http_tests = b.addRunArtifact(http_tests);
    const http_test_step = b.step("test-http", "Run http tests");
    http_test_step.dependOn(&run_http_tests.step);


    const exe_tests = b.addTest(.{
        .root_module = exe.root_module,
    });
    const run_exe_tests = b.addRunArtifact(exe_tests);


    const test_step = b.step("test", "Run all tests");
    test_step.dependOn(&run_db_tests.step);
    test_step.dependOn(&run_api_tests.step);
    test_step.dependOn(&run_z_tests.step);
    test_step.dependOn(&run_html_tests.step);
    test_step.dependOn(&run_http_tests.step);
    test_step.dependOn(&run_exe_tests.step);


    const fmt_step = b.step("fmt", "Format");
    const do_fmt = b.addFmt(.{
        .paths = &.{ "src" },
    });
    fmt_step.dependOn(&do_fmt.step);


    const check_fmt_step = b.step("check", "Check format and syntax");
    const do_check_fmt = b.addFmt(.{
        .paths = &.{ "src" },
        .check = true,
    });
    check_fmt_step.dependOn(&do_check_fmt.step);


    const docs_step = b.step("docs", "Emit documentation");
    const docs_install = b.addInstallDirectory(.{
        .install_dir = .prefix,
        .install_subdir = "docs",
        .source_dir = exe.getEmittedDocs(),
    });
    docs_step.dependOn(&docs_install.step);


    const hot_cmd = b.addSystemCommand(&.{
        "sh",
        "-c",
        "clear; echo 'building in hot mode'; find src -type f | entr -r zig build run",
    });

    const hot_step = b.step("hot", "Run server in hot reload mode");
    hot_step.dependOn(&hot_cmd.step);
    run_cmd.step.dependOn(b.getInstallStep());
}