summaryrefslogtreecommitdiff
path: root/bench/build.zig
blob: b7fb6afb88f21ab39199b1e37e9e4922d2d2aed5 (plain) (blame)
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
const std = @import("std");

const Import = struct {
    name: []const u8,
    module: *std.Build.Module,
};

const Bench = struct {
    name: []const u8,
    src: []const u8,
    imports: []const Import,
};

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

    const ziglyph = b.dependency("ziglyph", .{});
    const zg = b.dependency("zg", .{});

    const benches = [_]Bench{
        .{
            .name = "ziglyph_normalizer",
            .src = "src/ziglyph_normalizer.zig",
            .imports = &.{
                .{ .name = "ziglyph", .module = ziglyph.module("ziglyph") },
            },
        },
        .{
            .name = "ziglyph_caseless",
            .src = "src/ziglyph_caseless.zig",
            .imports = &.{
                .{ .name = "ziglyph", .module = ziglyph.module("ziglyph") },
            },
        },
        .{
            .name = "ziglyph_codepoint",
            .src = "src/ziglyph_codepoint.zig",
            .imports = &.{
                .{ .name = "ziglyph", .module = ziglyph.module("ziglyph") },
            },
        },
        .{
            .name = "ziglyph_grapheme",
            .src = "src/ziglyph_grapheme.zig",
            .imports = &.{
                .{ .name = "ziglyph", .module = ziglyph.module("ziglyph") },
            },
        },
        .{
            .name = "ziglyph_width",
            .src = "src/ziglyph_width.zig",
            .imports = &.{
                .{ .name = "ziglyph", .module = ziglyph.module("ziglyph") },
            },
        },
        .{
            .name = "ziglyph_case",
            .src = "src/ziglyph_case.zig",
            .imports = &.{
                .{ .name = "ziglyph", .module = ziglyph.module("ziglyph") },
            },
        },

        .{
            .name = "zg_normalize",
            .src = "src/zg_normalize.zig",
            .imports = &.{
                .{ .name = "Normalize", .module = zg.module("Normalize") },
            },
        },
        .{
            .name = "zg_caseless",
            .src = "src/zg_caseless.zig",
            .imports = &.{
                .{ .name = "CaseFolding", .module = zg.module("CaseFolding") },
                .{ .name = "Normalize", .module = zg.module("Normalize") },
            },
        },
        .{
            .name = "zg_codepoint",
            .src = "src/zg_codepoint.zig",
            .imports = &.{
                .{ .name = "code_point", .module = zg.module("code_point") },
            },
        },
        .{
            .name = "zg_grapheme",
            .src = "src/zg_grapheme.zig",
            .imports = &.{
                .{ .name = "Graphemes", .module = zg.module("Graphemes") },
            },
        },
        .{
            .name = "zg_width",
            .src = "src/zg_width.zig",
            .imports = &.{
                .{ .name = "DisplayWidth", .module = zg.module("DisplayWidth") },
            },
        },
        .{
            .name = "zg_case",
            .src = "src/zg_case.zig",
            .imports = &.{
                .{ .name = "LetterCasing", .module = zg.module("LetterCasing") },
            },
        },
    };

    for (&benches) |bench| {
        const exe = b.addExecutable(.{
            .name = bench.name,
            .root_source_file = b.path(bench.src),
            .target = target,
            .optimize = optimize,
            .strip = true,
        });

        for (bench.imports) |import| {
            exe.root_module.addImport(import.name, import.module);
        }

        b.installArtifact(exe);
    }

    // Tests
    const unit_tests = b.addTest(.{
        .root_source_file = b.path("src/tests.zig"),
        .target = target,
        .optimize = optimize,
    });
    unit_tests.root_module.addImport("GeneralCategories", zg.module("GeneralCategories"));
    unit_tests.root_module.addImport("Properties", zg.module("Properties"));
    unit_tests.root_module.addImport("LetterCasing", zg.module("LetterCasing"));
    unit_tests.root_module.addImport("Normalize", zg.module("Normalize"));
    unit_tests.root_module.addImport("CaseFolding", zg.module("CaseFolding"));
    unit_tests.root_module.addImport("DisplayWidth", zg.module("DisplayWidth"));
    unit_tests.root_module.addImport("code_point", zg.module("code_point"));
    unit_tests.root_module.addImport("Graphemes", zg.module("Graphemes"));
    unit_tests.root_module.addImport("Scripts", zg.module("Scripts"));

    const run_unit_tests = b.addRunArtifact(unit_tests);

    const unit_test_step = b.step("test", "Run tests");
    unit_test_step.dependOn(&run_unit_tests.step);
}