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