-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
189 lines (163 loc) · 7.74 KB
/
build.zig
File metadata and controls
189 lines (163 loc) · 7.74 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Create the logly module
const logly_module = b.createModule(.{
.root_source_file = b.path("src/logly.zig"),
});
// Expose the module for external projects that depend on this package.
// This allows users to do: `const logly = @import("logly");` in their code
// after adding logly as a dependency and calling `dep.module("logly")` in their build.zig
_ = b.addModule("logly", .{
.root_source_file = b.path("src/logly.zig"),
});
const examples = [_]struct { name: []const u8, path: []const u8, skip_run_all: bool = false }{
.{ .name = "basic", .path = "examples/basic.zig" },
.{ .name = "file_logging", .path = "examples/file_logging.zig" },
.{ .name = "rotation", .path = "examples/rotation.zig" },
.{ .name = "json_logging", .path = "examples/json_logging.zig" },
.{ .name = "callbacks", .path = "examples/callbacks.zig" },
.{ .name = "context", .path = "examples/context.zig" },
.{ .name = "custom_colors", .path = "examples/custom_colors.zig" },
.{ .name = "async_logging", .path = "examples/async_logging.zig" },
.{ .name = "advanced_config", .path = "examples/advanced_config.zig" },
.{ .name = "module_levels", .path = "examples/module_levels.zig" },
.{ .name = "sink_formats", .path = "examples/sink_formats.zig" },
.{ .name = "formatted_logging", .path = "examples/formatted_logging.zig" },
.{ .name = "json_extended", .path = "examples/json_extended.zig" },
.{ .name = "time", .path = "examples/time.zig" },
.{ .name = "filtering", .path = "examples/filtering.zig" },
.{ .name = "sampling", .path = "examples/sampling.zig" },
.{ .name = "redaction", .path = "examples/redaction.zig" },
.{ .name = "metrics", .path = "examples/metrics.zig" },
.{ .name = "tracing", .path = "examples/tracing.zig" },
.{ .name = "production_config", .path = "examples/production_config.zig" },
.{ .name = "diagnostics", .path = "examples/diagnostics.zig" },
.{ .name = "color_options", .path = "examples/color_options.zig" },
.{ .name = "custom_levels_full", .path = "examples/custom_levels_full.zig" },
.{ .name = "compression", .path = "examples/compression.zig" },
.{ .name = "thread_pool", .path = "examples/thread_pool.zig" },
.{ .name = "scheduler", .path = "examples/scheduler.zig" },
.{ .name = "async_advanced", .path = "examples/async_advanced.zig" },
.{ .name = "compression_demo", .path = "examples/compression_demo.zig" },
.{ .name = "scheduler_demo", .path = "examples/scheduler_demo.zig" },
.{ .name = "thread_pool_arena", .path = "examples/thread_pool_arena.zig" },
.{ .name = "dynamic_path", .path = "examples/dynamic_path.zig" },
.{ .name = "customizations", .path = "examples/customizations.zig" },
.{ .name = "sink_write_modes", .path = "examples/sink_write_modes.zig" },
.{ .name = "network_logging", .path = "examples/network_logging.zig", .skip_run_all = true },
.{ .name = "version_checker", .path = "examples/update_check.zig", .skip_run_all = true },
.{ .name = "advanced_features", .path = "examples/advanced_features.zig" },
.{ .name = "custom_theme", .path = "examples/custom_theme.zig" },
.{ .name = "config_presets", .path = "examples/config_presets.zig" },
};
inline for (examples) |example| {
const exe = b.addExecutable(.{
.name = example.name,
.root_module = b.createModule(.{
.root_source_file = b.path(example.path),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.addImport("logly", logly_module);
exe.linkLibC();
// Link ws2_32 on Windows for networking examples
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("ws2_32");
}
const install_exe = b.addInstallArtifact(exe, .{});
const example_step = b.step("example-" ++ example.name, "Build " ++ example.name ++ " example");
example_step.dependOn(&install_exe.step);
// Add run step for each example
const run_exe = b.addRunArtifact(exe);
run_exe.step.dependOn(&install_exe.step);
const run_step = b.step("run-" ++ example.name, "Run " ++ example.name ++ " example");
run_step.dependOn(&run_exe.step);
}
// Create run-all-examples step that runs all examples sequentially
const run_all_examples = b.step("run-all-examples", "Run all examples sequentially");
var previous_run_step: ?*std.Build.Step = null;
inline for (examples) |example| {
if (example.skip_run_all) continue;
const exe = b.addExecutable(.{
.name = "run-all-" ++ example.name,
.root_module = b.createModule(.{
.root_source_file = b.path(example.path),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.addImport("logly", logly_module);
exe.linkLibC();
// Link ws2_32 on Windows for networking examples
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("ws2_32");
}
const install_exe = b.addInstallArtifact(exe, .{});
const run_exe = b.addRunArtifact(exe);
run_exe.step.dependOn(&install_exe.step);
// Make each run step depend on the previous run step to ensure sequential execution
if (previous_run_step) |prev| {
run_exe.step.dependOn(prev);
}
previous_run_step = &run_exe.step;
}
if (previous_run_step) |last| {
run_all_examples.dependOn(last);
}
// Unit tests
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/logly.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.linkLibC();
if (target.result.os.tag == .windows) {
tests.linkSystemLibrary("ws2_32");
}
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
// Benchmark
const bench_exe = b.addExecutable(.{
.name = "benchmark",
.root_module = b.createModule(.{
.root_source_file = b.path("bench/benchmark.zig"),
.target = target,
.optimize = .ReleaseFast,
}),
});
bench_exe.root_module.addImport("logly", logly_module);
bench_exe.linkLibC();
if (target.result.os.tag == .windows) {
bench_exe.linkSystemLibrary("ws2_32");
}
const install_bench = b.addInstallArtifact(bench_exe, .{});
const run_bench = b.addRunArtifact(bench_exe);
run_bench.step.dependOn(&install_bench.step);
const bench_step = b.step("bench", "Run benchmarks");
bench_step.dependOn(&run_bench.step);
// Create comprehensive test-all step that runs everything sequentially
const test_all_step = b.step("test-all", "Run all tests, benchmarks, and examples sequentially");
// First run unit tests
test_all_step.dependOn(test_step);
// Then run benchmarks
test_all_step.dependOn(bench_step);
// Finally run all examples
test_all_step.dependOn(run_all_examples);
// Install step for library
const lib = b.addLibrary(.{
.name = "logly",
.linkage = .static,
.root_module = b.createModule(.{
.root_source_file = b.path("src/logly.zig"),
.target = target,
.optimize = optimize,
}),
});
b.installArtifact(lib);
}