-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
185 lines (160 loc) · 7.49 KB
/
build.zig
File metadata and controls
185 lines (160 loc) · 7.49 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const version = b.option([]const u8, "version", "Build version exposed in metrics") orelse "dev";
const commit = b.option([]const u8, "commit", "Build commit exposed in metrics") orelse "unknown";
const build_options = b.addOptions();
build_options.addOption([]const u8, "version", version);
build_options.addOption([]const u8, "commit", commit);
// ==========================================================================
// Dependencies
// ==========================================================================
const httpz = b.dependency("httpz", .{
.target = target,
.optimize = optimize,
});
const zimdjson = b.dependency("zimdjson", .{
.target = target,
.optimize = optimize,
});
const policy_dep = b.dependency("policy_zig", .{
.target = target,
.optimize = optimize,
});
const metrics_dep = b.dependency("metrics", .{
.target = target,
.optimize = optimize,
});
// Shared modules from policy-zig ensure type identity across boundaries.
const proto_mod = policy_dep.module("proto");
const o11y_mod = policy_dep.module("observability");
// ==========================================================================
// Edge Library Module
// ==========================================================================
const mod = b.addModule("edge", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.imports = &.{
.{ .name = "proto", .module = proto_mod },
.{ .name = "zimdjson", .module = zimdjson.module("zimdjson") },
.{ .name = "policy_zig", .module = policy_dep.module("policy_zig") },
.{ .name = "o11y", .module = o11y_mod },
.{ .name = "metrics_zig", .module = metrics_dep.module("metrics") },
},
});
mod.addOptions("build_options", build_options);
// ==========================================================================
// Main Executable
// ==========================================================================
const exe = b.addExecutable(.{
.name = "edge",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "edge", .module = mod },
},
}),
});
exe.root_module.addImport("httpz", httpz.module("httpz"));
exe.root_module.addImport("proto", proto_mod);
exe.root_module.addImport("zimdjson", zimdjson.module("zimdjson"));
exe.root_module.addImport("policy_zig", policy_dep.module("policy_zig"));
exe.root_module.addImport("o11y", o11y_mod);
exe.root_module.addImport("metrics_zig", metrics_dep.module("metrics"));
exe.root_module.addOptions("build_options", build_options);
exe.root_module.link_libc = true;
exe.root_module.linkSystemLibrary("z", .{});
exe.root_module.linkSystemLibrary("zstd", .{});
b.installArtifact(exe);
// ==========================================================================
// Distribution Builds
// ==========================================================================
const distributions = .{
.{ "datadog", "src/datadog_main.zig", "Datadog ingestion" },
.{ "otlp", "src/otlp_main.zig", "OpenTelemetry (OTLP) ingestion" },
.{ "prometheus", "src/prometheus_main.zig", "Prometheus metrics scraping" },
.{ "tail", "src/edge_tail_main.zig", "Log tailing" },
.{ "edge", "src/main.zig", "Full distribution (OTLP, Datadog & Prometheus)" },
.{ "lambda", "src/lambda_main.zig", "AWS Lambda extension (Datadog)" },
};
inline for (distributions) |dist| {
const name = dist[0];
const source = dist[1];
const desc = dist[2];
const dist_exe = b.addExecutable(.{
.name = "edge-" ++ name,
.root_module = b.createModule(.{
.root_source_file = b.path(source),
.target = target,
.optimize = optimize,
}),
});
dist_exe.root_module.addImport("httpz", httpz.module("httpz"));
dist_exe.root_module.addImport("proto", proto_mod);
dist_exe.root_module.addImport("zimdjson", zimdjson.module("zimdjson"));
dist_exe.root_module.addImport("policy_zig", policy_dep.module("policy_zig"));
dist_exe.root_module.addImport("o11y", o11y_mod);
dist_exe.root_module.addImport("metrics_zig", metrics_dep.module("metrics"));
dist_exe.root_module.addOptions("build_options", build_options);
dist_exe.root_module.link_libc = true;
dist_exe.root_module.linkSystemLibrary("z", .{});
dist_exe.root_module.linkSystemLibrary("zstd", .{});
const dist_step = b.step(name, "Build the " ++ name ++ " distribution (" ++ desc ++ ")");
dist_step.dependOn(&b.addInstallArtifact(dist_exe, .{}).step);
const run_dist_step = b.step("run-" ++ name, "Run the " ++ name ++ " distribution");
const run_dist_cmd = b.addRunArtifact(dist_exe);
run_dist_step.dependOn(&run_dist_cmd.step);
run_dist_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_dist_cmd.addArgs(args);
}
}
// ==========================================================================
// Run Step
// ==========================================================================
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
// ==========================================================================
// Tests
// ==========================================================================
const mod_tests = b.addTest(.{
.root_module = mod,
});
mod_tests.root_module.link_libc = true;
mod_tests.root_module.linkSystemLibrary("z", .{});
mod_tests.root_module.linkSystemLibrary("zstd", .{});
mod_tests.root_module.addImport("metrics_zig", metrics_dep.module("metrics"));
mod_tests.root_module.addOptions("build_options", build_options);
const run_mod_tests = b.addRunArtifact(mod_tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
// ==========================================================================
// Benchmark Tools
// ==========================================================================
const echo_server = b.addExecutable(.{
.name = "echo-server",
.root_module = b.createModule(.{
.root_source_file = b.path("src/bench/echo_server.zig"),
.target = target,
.optimize = optimize,
}),
});
echo_server.root_module.addImport("httpz", httpz.module("httpz"));
const echo_step = b.step("echo-server", "Build the echo server for benchmarking");
echo_step.dependOn(&b.addInstallArtifact(echo_server, .{}).step);
const run_echo_step = b.step("run-echo-server", "Run the echo server");
const run_echo_cmd = b.addRunArtifact(echo_server);
run_echo_step.dependOn(&run_echo_cmd.step);
run_echo_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_echo_cmd.addArgs(args);
}
}