1
const std = @import("std");
2
const linkPcre = @import("vendor/libpcre/build.zig").linkPcre;
3
4
pub fn build(b: *std.Build) !void {
5
const target = b.standardTargetOptions(.{});
6
const optimize = b.standardOptimizeOption(.{});
7
8
var deps = std.StringHashMap(*std.Build.Module).init(b.allocator);
9
const libpcre = b.addModule("libpcre", .{
10
.root_source_file = .{ .path = "vendor/libpcre/src/main.zig" },
11
.target = target,
12
});
13
try linkPcre(b, libpcre);
14
try deps.put("libpcre", libpcre);
15
try deps.put("htmlentities", b.addModule("htmlentities", .{ .root_source_file = .{ .path = "vendor/htmlentities/src/main.zig" } }));
16
try deps.put("clap", b.addModule("clap", .{ .root_source_file = .{ .path = "vendor/zig-clap/clap.zig" } }));
17
try deps.put("zunicode", b.addModule("zunicode", .{ .root_source_file = .{ .path = "vendor/zunicode/src/zunicode.zig" } }));
18
19
const exe = b.addExecutable(.{
20
.name = "koino",
21
.root_source_file = .{ .path = "src/main.zig" },
22
.target = target,
23
.optimize = optimize,
24
});
25
try addCommonRequirements(exe, &deps);
26
b.installArtifact(exe);
27
28
const run_cmd = b.addRunArtifact(exe);
29
run_cmd.step.dependOn(b.getInstallStep());
30
const run_step = b.step("run", "Run the app");
31
run_step.dependOn(&run_cmd.step);
32
33
if (b.args) |args| {
34
run_cmd.addArgs(args);
35
}
36
37
const test_exe = b.addTest(.{
38
.name = "test",
39
.root_source_file = .{ .path = "src/main.zig" },
40
.target = target,
41
.optimize = optimize,
42
});
43
try addCommonRequirements(test_exe, &deps);
44
const test_step = b.step("test", "Run all the tests");
45
test_step.dependOn(&test_exe.step);
46
}
47
48
fn addCommonRequirements(cs: *std.Build.Step.Compile, deps: *const std.StringHashMap(*std.Build.Module)) !void {
49
var it = deps.iterator();
50
while (it.next()) |entry| {
51
cs.root_module.addImport(entry.key_ptr.*, entry.value_ptr.*);
52
}
53
cs.linkLibC();
54
}
55