r/o

port comrak quadratic fixes fc2df9bf parent 115c6669

Closes #45.

authored by ~talya committed by ~lotte

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 uucode_pkg = b.dependency("uucode", .{
12
.optimize = optimize,
13
.target = target,
14
.fields = @as([]const []const u8, &.{
15
"general_category",
16
"simple_lowercase_mapping",
17
}),
18
});
19
const clap_pkg = b.dependency("clap", .{ .optimize = optimize, .target = target });
20
21
try deps.put("clap", clap_pkg.module("clap"));
22
try deps.put("libpcre", pcre_pkg.module("libpcre"));
23
try deps.put("uucode", uucode_pkg.module("uucode"));
24
try deps.put("htmlentities", htmlentities_pkg.module("htmlentities"));
25
26
const mod = b.addModule("koino", .{
27
.root_source_file = b.path("src/koino.zig"),
28
.target = target,
29
.optimize = optimize,
30
});
31
try addCommonRequirements(mod, &deps);
32
33
// Workaround: uucode's generated tables trigger a crash in Zig's
34
// self-hosted x86_64 backend. Force LLVM until this is resolved upstream.
35
const exe = b.addExecutable(.{
36
.name = "koino",
37
.use_llvm = true,
38
.root_module = b.createModule(.{
39
.root_source_file = b.path("src/main.zig"),
40
41
.target = target,
42
.optimize = optimize,
43
44
.imports = &.{
45
.{ .name = "test_koino", .module = mod },
46
},
47
}),
48
});
49
try addCommonRequirements(exe.root_module, &deps);
50
b.installArtifact(exe);
51
52
const run_cmd = b.addRunArtifact(exe);
53
run_cmd.step.dependOn(b.getInstallStep());
54
const run_step = b.step("run", "Run the app");
55
run_step.dependOn(&run_cmd.step);
56
57
if (b.args) |args| {
58
run_cmd.addArgs(args);
59
}
60
61
const example = b.addExecutable(.{
62
.name = "koino_example",
63
.use_llvm = true,
64
.root_module = b.createModule(.{
65
.root_source_file = b.path("examples/to-html.zig"),
66
67
.target = target,
68
.optimize = optimize,
69
70
.imports = &.{
71
.{ .name = "test_koino", .module = mod },
72
},
73
}),
74
});
75
76
try addCommonRequirements(example.root_module, &deps);
77
b.installArtifact(example);
78
79
const example_run_cmd = b.addRunArtifact(example);
80
example_run_cmd.step.dependOn(b.getInstallStep());
81
const example_run_step = b.step("example", "Run example");
82
example_run_step.dependOn(&example_run_cmd.step);
83
84
const test_exe = b.addTest(.{
85
.use_llvm = true,
86
.root_module = b.createModule(.{
87
.root_source_file = b.path("src/main.zig"),
88
89
.target = target,
90
.optimize = optimize,
91
92
.imports = &.{
93
.{ .name = "test_koino", .module = mod },
94
},
95
}),
96
});
97
try addCommonRequirements(test_exe.root_module, &deps);
98
99
const test_step = b.step("test", "Run all the tests");
100
const test_run = b.addRunArtifact(test_exe);
101
test_step.dependOn(&test_run.step);
102
}
103
104
fn addCommonRequirements(mod: *std.Build.Module, deps: *const std.StringHashMap(*std.Build.Module)) !void {
105
var it = deps.iterator();
106
while (it.next()) |entry| {
107
mod.addImport(entry.key_ptr.*, entry.value_ptr.*);
108
}
109
mod.linkSystemLibrary("c", .{});
110
}
111