-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild.zig
More file actions
110 lines (90 loc) · 3.52 KB
/
build.zig
File metadata and controls
110 lines (90 loc) · 3.52 KB
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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var deps = std.StringHashMap(*std.Build.Module).init(b.allocator);
const pcre_pkg = b.dependency("libpcre_zig", .{ .optimize = optimize, .target = target });
const htmlentities_pkg = b.dependency("htmlentities_zig", .{ .optimize = optimize, .target = target });
const uucode_pkg = b.dependency("uucode", .{
.optimize = optimize,
.target = target,
.fields = @as([]const []const u8, &.{
"general_category",
"simple_lowercase_mapping",
}),
});
const clap_pkg = b.dependency("clap", .{ .optimize = optimize, .target = target });
try deps.put("clap", clap_pkg.module("clap"));
try deps.put("libpcre", pcre_pkg.module("libpcre"));
try deps.put("uucode", uucode_pkg.module("uucode"));
try deps.put("htmlentities", htmlentities_pkg.module("htmlentities"));
const mod = b.addModule("koino", .{
.root_source_file = b.path("src/koino.zig"),
.target = target,
.optimize = optimize,
});
try addCommonRequirements(mod, &deps);
// Workaround: uucode's generated tables trigger a crash in Zig's
// self-hosted x86_64 backend. Force LLVM until this is resolved upstream.
const exe = b.addExecutable(.{
.name = "koino",
.use_llvm = true,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "test_koino", .module = mod },
},
}),
});
try addCommonRequirements(exe.root_module, &deps);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
if (b.args) |args| {
run_cmd.addArgs(args);
}
const example = b.addExecutable(.{
.name = "koino_example",
.use_llvm = true,
.root_module = b.createModule(.{
.root_source_file = b.path("examples/to-html.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "test_koino", .module = mod },
},
}),
});
try addCommonRequirements(example.root_module, &deps);
b.installArtifact(example);
const example_run_cmd = b.addRunArtifact(example);
example_run_cmd.step.dependOn(b.getInstallStep());
const example_run_step = b.step("example", "Run example");
example_run_step.dependOn(&example_run_cmd.step);
const test_exe = b.addTest(.{
.use_llvm = true,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "test_koino", .module = mod },
},
}),
});
try addCommonRequirements(test_exe.root_module, &deps);
const test_step = b.step("test", "Run all the tests");
const test_run = b.addRunArtifact(test_exe);
test_step.dependOn(&test_run.step);
}
fn addCommonRequirements(mod: *std.Build.Module, deps: *const std.StringHashMap(*std.Build.Module)) !void {
var it = deps.iterator();
while (it.next()) |entry| {
mod.addImport(entry.key_ptr.*, entry.value_ptr.*);
}
mod.linkSystemLibrary("c", .{});
}