Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
115 lines (101 loc) · 3.44 KB
/
Copy pathbuild.zig
File metadata and controls
115 lines (101 loc) · 3.44 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
111
112
113
114
115
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const chroma = b.dependency("chroma", .{
.target = target,
.optimize = optimize,
}).module("chroma");
const logger = b.addModule("chroma-logger", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "chroma", .module = chroma },
},
});
const example_module = b.createModule(.{
.root_source_file = b.path("examples/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "chroma-logger", .module = logger },
},
});
const example = b.addExecutable(.{
.name = "chroma-logger-demo",
.root_module = example_module,
});
b.installArtifact(example);
const run_command = b.addRunArtifact(example);
run_command.step.dependOn(b.getInstallStep());
if (b.args) |args| run_command.addArgs(args);
const run_step = b.step("run", "Run the live logger demo");
run_step.dependOn(&run_command.step);
const library_tests = b.addTest(.{ .root_module = logger });
const run_library_tests = b.addRunArtifact(library_tests);
const example_tests = b.addTest(.{ .root_module = example_module });
const run_example_tests = b.addRunArtifact(example_tests);
const test_step = b.step("test", "Run unit and example tests");
test_step.dependOn(&run_library_tests.step);
test_step.dependOn(&run_example_tests.step);
addCompileErrorTest(
b,
test_step,
logger,
target,
optimize,
"tests/compile_errors/invalid_offset.zig",
"error: chroma-logger config: utc_offset_minutes must be between -1439 and 1439",
);
addCompileErrorTest(
b,
test_step,
logger,
target,
optimize,
"tests/compile_errors/newline_label.zig",
"error: chroma-logger config: info label cannot contain a newline",
);
addCompileErrorTest(
b,
test_step,
logger,
target,
optimize,
"tests/compile_errors/unknown_message_style.zig",
"error: chroma: unknown directive 'missing' at byte 2",
);
const benchmark_module = b.createModule(.{
.root_source_file = b.path("benchmarks/compile.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "chroma-logger", .module = logger },
},
});
const benchmark_compile = b.addTest(.{ .root_module = benchmark_module });
const benchmark_step = b.step("benchmark", "Compile the logger stress fixture");
benchmark_step.dependOn(&benchmark_compile.step);
}
fn addCompileErrorTest(
b: *std.Build,
test_step: *std.Build.Step,
logger: *std.Build.Module,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
path: []const u8,
expected: []const u8,
) void {
const fixture_module = b.createModule(.{
.root_source_file = b.path(path),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "chroma-logger", .module = logger },
},
});
const fixture = b.addTest(.{ .root_module = fixture_module });
fixture.expect_errors = .{ .contains = expected };
test_step.dependOn(&fixture.step);
}